diff --git a/R/as_gt.R b/R/as_gt.R index b925d6f2..c7a2b8bb 100644 --- a/R/as_gt.R +++ b/R/as_gt.R @@ -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")) diff --git a/R/gs_design_ahr.R b/R/gs_design_ahr.R index 13b1e786..786e81be 100644 --- a/R/gs_design_ahr.R +++ b/R/gs_design_ahr.R @@ -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( @@ -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) |> diff --git a/R/summary.R b/R/summary.R index f6ebe77e..68983028 100644 --- a/R/summary.R +++ b/R/summary.R @@ -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 #' @@ -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 @@ -325,6 +328,12 @@ summary.gs_design <- function(object, "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) @@ -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) } diff --git a/man/summary.Rd b/man/summary.Rd index 21b2ac5a..4cdb08d8 100644 --- a/man/summary.Rd +++ b/man/summary.Rd @@ -14,6 +14,7 @@ col_vars = NULL, col_decimals = NULL, bound_names = c("Efficacy", "Futility"), + display_spending_time = FALSE, ... ) } @@ -37,6 +38,9 @@ vector is named, you only have to specify the number of digits for the columns you want to be displayed differently than the defaults.} \item{bound_names}{Names for bounds; default is \code{c("Efficacy", "Futility")}.} + +\item{display_spending_time}{A logical value (TRUE/FALSE) indicating if the spending time +is summarized in the table.} } \value{ A summary table (data frame). diff --git a/tests/testthat/_snaps/independent_as_gt.md b/tests/testthat/_snaps/independent_as_gt.md index 1e83b9d5..830eda20 100644 --- a/tests/testthat/_snaps/independent_as_gt.md +++ b/tests/testthat/_snaps/independent_as_gt.md @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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} @@ -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}