Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions R/as_gt.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,17 @@ as_gt.gs_design_summary <- function(
# get different default columns to display
gsd_columns <- function(columns, method, x) {
# set different default columns to display
if (is.null(columns)) columns <- c(
"Analysis", "Bound", "Z", "Nominal p",
sprintf("%s at bound", switch(method, ahr = "~HR", wlr = "~wHR", rd = "~Risk difference")),
"Alternate hypothesis", "Null hypothesis"
)
if (is.null(columns)){
columns <- c(
"Analysis", "Bound", "Z", "Nominal p",
sprintf("%s at bound", switch(method, ahr = "~HR", wlr = "~wHR", rd = "~Risk difference")),
"Alternate hypothesis", "Null hypothesis")

if ("Spending time" %in% names(x)) {
columns <- c(columns[1:3], "Spending time", columns[4:length(columns)])
}
}

# filter the columns to display as the output: if `Probability` is selected to
# output, transform it to `c("Alternate hypothesis", "Null hypothesis")`
if (any(i <- columns == "Probability"))
Expand Down
37 changes: 37 additions & 0 deletions R/gs_design_ahr.R
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ gs_design_ahr <- function(
allout$event <- allout$event * inflac_fct
allout$n <- allout$n * inflac_fct


# Get bounds to output ----
bound <- allout |>
select(all_of(c(
Expand All @@ -345,6 +346,42 @@ gs_design_ahr <- function(
))) |>
arrange(analysis, desc(bound))

# Output spending time to the bounds table
info0 <- (allout |> filter(bound == "upper"))$info0
info <- (allout |> filter(bound == "upper"))$info
info0_final <- (allout |> filter(analysis == n_analysis, bound == "upper"))$info0
info_final <- (allout |> filter(analysis == n_analysis, bound == "upper"))$info

bound$spending_time <- NA

if (identical(upper, gs_spending_bound)) {

if (!is.null(upar$timing)) {
spending_time_upper <- upar$timing
} else {
spending_time_upper <- info0 / info0_final
}


bound$spending_time[which(bound$bound == "upper")] <- spending_time_upper
}

if (identical(lower, gs_spending_bound)) {
if (!is.null(lpar$timing)) {
spending_time_lower <- lpar$timing
} else if (h1_spending) {
spending_time_lower <- info / info_final
} else if (!h1_spending) {
spending_time_lower <- info0 / info0_final
}

bound$spending_time[which(bound$bound == "lower")] <- spending_time_lower
}

if (all(is.na(bound$spending_time))){
bound$spending_time <- NULL
}

# Get analysis summary to output ----
analysis <- allout |>
select(analysis, time, n, event, ahr, theta, info, info0, info_frac) |>
Expand Down
14 changes: 12 additions & 2 deletions R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ summary.fixed_design <- function(object, ...) {
#' vector is named, you only have to specify the number of digits for the
#' columns you want to be displayed differently than the defaults.
#' @param bound_names Names for bounds; default is `c("Efficacy", "Futility")`.
#' @param display_spending_time A logical value (TRUE/FALSE) indicating if the spending time
#' is summarized in the table.
#'
#' @export
#'
Expand Down Expand Up @@ -256,6 +258,7 @@ summary.gs_design <- function(object,
col_vars = NULL,
col_decimals = NULL,
bound_names = c("Efficacy", "Futility"),
display_spending_time = FALSE,
...) {
x <- object
x_bound <- x$bound
Expand Down Expand Up @@ -318,13 +321,19 @@ summary.gs_design <- function(object,
)

# Prepare the columns decimals ----
default_decimals <- c(NA, NA, 2, if (method != "combo") 4, 4, 4, 4)
default_decimals <- c(NA, NA, 2, if (method != "combo") 4, 4, 4, 4, 4)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this extra 4 needs to be removed. IIUC it is optionally added below if display_spending_time is TRUE

default_vars <- c(
"analysis", "bound", "z",
sprintf("~%s at bound", switch(method, ahr = "hr", wlr = "whr", rd = "risk difference")),
"nominal p", "Alternate hypothesis", "Null hypothesis"
)

if (display_spending_time) {
default_decimals <- c(default_decimals[1:3], 4, default_decimals[4:length(default_decimals)])
default_vars <- c(default_vars[1:3], "spending_time", default_vars[4:length(default_vars)])
}


# Filter columns and update decimal places
col_decimals <- get_decimals(col_vars, col_decimals, default_vars, default_decimals)

Expand Down Expand Up @@ -388,7 +397,8 @@ cap_names <- function(x) {
map, ahr = "AHR", event = "Events", rd = "Risk difference",
probability = "Alternate hypothesis", probability0 = "Null hypothesis",
info_frac0 = "Information fraction", info_frac = "Information fraction",
event_frac = "Event fraction"
event_frac = "Event fraction",
spending_time = "Spending time"
)
replace_names(x, map)
}
4 changes: 4 additions & 0 deletions man/summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 49 additions & 34 deletions tests/testthat/_snaps/independent_as_gt.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}Power computed with average hazard ratio method.\\
\vspace{.05em}
\textsuperscript{\textit{1}} Power computed with average hazard ratio method.\\
\end{minipage}
\end{table}

Expand All @@ -32,7 +33,8 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}Custom footnote.\\
\vspace{.05em}
\textsuperscript{\textit{1}} Custom footnote.\\
\end{minipage}
\end{table}

Expand All @@ -51,7 +53,8 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}Power for Fleming-Harrington test FH(0, 0) (logrank) using method of Yung and Liu.\\
\vspace{.05em}
\textsuperscript{\textit{1}} Power for Fleming-Harrington test FH(0, 0) (logrank) using method of Yung and Liu.\\
\end{minipage}
\end{table}

Expand All @@ -75,8 +78,9 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}}Approximate hazard ratio to cross bound.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}} Approximate hazard ratio to cross bound.\\
\end{minipage}
\end{table}

Expand Down Expand Up @@ -111,8 +115,9 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}}Approximate hazard ratio to cross bound.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}} Approximate hazard ratio to cross bound.\\
\end{minipage}
\end{table}

Expand All @@ -136,9 +141,10 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}}Approximate hazard ratio to cross bound.\\
\textsuperscript{\textit{3}}wAHR is the weighted AHR.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}} Approximate hazard ratio to cross bound.\\
\textsuperscript{\textit{3}} wAHR is the weighted AHR.\\
\end{minipage}
\end{table}

Expand Down Expand Up @@ -173,10 +179,11 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}this table is generated by gs\_power\_wlr.\\
\textsuperscript{\textit{2}}the crossing probability.\\
\textsuperscript{\textit{3}}approximate weighted hazard ratio to cross bound.\\
\textsuperscript{\textit{4}}wAHR is the weighted AHR.\\
\vspace{.05em}
\textsuperscript{\textit{1}} this table is generated by gs\_power\_wlr.\\
\textsuperscript{\textit{2}} the crossing probability.\\
\textsuperscript{\textit{3}} approximate weighted hazard ratio to cross bound.\\
\textsuperscript{\textit{4}} wAHR is the weighted AHR.\\
\end{minipage}
\end{table}

Expand Down Expand Up @@ -211,8 +218,9 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}}EF is event fraction. AHR is under regular weighted log rank test.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}} EF is event fraction. AHR is under regular weighted log rank test.\\
\end{minipage}
\end{table}

Expand All @@ -236,7 +244,8 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\end{minipage}
\end{table}

Expand Down Expand Up @@ -269,8 +278,9 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}}Cumulative alpha for final analysis (0.0238) is less than the full alpha (0.025) when the futility bound is non-binding. The smaller value subtracts the probability of crossing a futility bound before crossing an efficacy bound at a later analysis (0.025 - 0.0012 = 0.0238) under the null hypothesis.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}} Cumulative alpha for final analysis (0.0238) is less than the full alpha (0.025) when the futility bound is non-binding. The smaller value subtracts the probability of crossing a futility bound before crossing an efficacy bound at a later analysis (0.025 - 0.0012 = 0.0238) under the null hypothesis.\\
\end{minipage}
\end{table}

Expand Down Expand Up @@ -305,9 +315,10 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}}Approximate hazard ratio to cross bound.\\
\textsuperscript{\textit{3}}wAHR is the weighted AHR.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}} Approximate hazard ratio to cross bound.\\
\textsuperscript{\textit{3}} wAHR is the weighted AHR.\\
\end{minipage}
\end{table}

Expand Down Expand Up @@ -342,9 +353,10 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}}Approximate hazard ratio to cross bound.\\
\textsuperscript{\textit{3}}wAHR is the weighted AHR.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}} Approximate hazard ratio to cross bound.\\
\textsuperscript{\textit{3}} wAHR is the weighted AHR.\\
\end{minipage}
\end{table}

Expand Down Expand Up @@ -379,10 +391,11 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}this table is generated by gs\_power\_wlr.\\
\textsuperscript{\textit{2}}the crossing probability.\\
\textsuperscript{\textit{3}}approximate weighted hazard ratio to cross bound.\\
\textsuperscript{\textit{4}}wAHR is the weighted AHR.\\
\vspace{.05em}
\textsuperscript{\textit{1}} this table is generated by gs\_power\_wlr.\\
\textsuperscript{\textit{2}} the crossing probability.\\
\textsuperscript{\textit{3}} approximate weighted hazard ratio to cross bound.\\
\textsuperscript{\textit{4}} wAHR is the weighted AHR.\\
\end{minipage}
\end{table}

Expand Down Expand Up @@ -414,9 +427,10 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}}Approximate hazard ratio to cross bound.\\
\textsuperscript{\textit{3}}wAHR is the weighted AHR.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}} Approximate hazard ratio to cross bound.\\
\textsuperscript{\textit{3}} wAHR is the weighted AHR.\\
\end{minipage}
\end{table}

Expand Down Expand Up @@ -451,8 +465,9 @@
\bottomrule
\end{tabular*}
\begin{minipage}{\linewidth}
\textsuperscript{\textit{1}}One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}}wAHR is the weighted AHR.\\
\vspace{.05em}
\textsuperscript{\textit{1}} One-sided p-value for experimental vs control treatment. Value < 0.5 favors experimental, > 0.5 favors control.\\
\textsuperscript{\textit{2}} wAHR is the weighted AHR.\\
\end{minipage}
\end{table}