Skip to contents

[Stable]

Summarize patients' survival rate and difference of survival rates between groups at a time point.

Usage

s_surv_timepoint(
  df,
  .var,
  time_point,
  is_event,
  control = control_surv_timepoint()
)

a_surv_timepoint(
  df,
  .var,
  time_point,
  is_event,
  control = control_surv_timepoint()
)

s_surv_timepoint_diff(
  df,
  .var,
  .ref_group,
  .in_ref_col,
  time_point,
  control = control_surv_timepoint(),
  ...
)

a_surv_timepoint_diff(
  df,
  .var,
  .ref_group,
  .in_ref_col,
  time_point,
  control = control_surv_timepoint(),
  ...
)

surv_timepoint(
  lyt,
  vars,
  na_str = NA_character_,
  nested = TRUE,
  ...,
  table_names_suffix = "",
  var_labels = "Time",
  show_labels = "visible",
  method = c("surv", "surv_diff", "both"),
  .stats = c("pt_at_risk", "event_free_rate", "rate_ci", "rate_diff", "rate_diff_ci",
    "ztest_pval"),
  .formats = NULL,
  .labels = NULL,
  .indent_mods = if (method == "both") {
     c(rate_diff = 1L, rate_diff_ci = 2L,
    ztest_pval = 2L)
 } else {
     c(rate_diff_ci = 1L, ztest_pval = 1L)
 }
)

Arguments

df

(data.frame)
data set containing all analysis variables.

.var

(string)
single variable name that is passed by rtables when requested by a statistics function.

time_point

(number)
survival time point of interest.

is_event

(logical)
TRUE if event, FALSE if time to event is censored.

control

(list)
parameters for comparison details, specified by using the helper function control_surv_timepoint(). Some possible parameter options are:

  • conf_level (proportion)
    confidence level of the interval for survival rate.

  • conf_type (string)
    confidence interval type. Options are "plain" (default), "log", "log-log", see more in survival::survfit(). Note option "none" is no longer supported.

  • time_point (number)
    survival time point of interest.

.ref_group

(data.frame or vector)
the data corresponding to the reference group.

.in_ref_col

(logical)
TRUE when working with the reference level, FALSE otherwise.

...

additional arguments for the lower level functions.

lyt

(layout)
input layout where analyses will be added to.

vars

(character)
variable names for the primary analysis variable to be iterated over.

na_str

(string)
string used to replace all NA or empty values in the output.

nested

(flag)
whether this layout instruction should be applied within the existing layout structure if possible (TRUE, the default) or as a new top-level element (FALSE). Ignored if it would nest a split. underneath analyses, which is not allowed.

table_names_suffix

(string)
optional suffix for the table_names used for the rtables to avoid warnings from duplicate table names.

var_labels

(character)
character for label.

show_labels

(string)
label visibility: one of "default", "visible" and "hidden".

method

(string)
either surv (survival estimations), surv_diff (difference in survival with the control) or both.

.stats

(character)
statistics to select for the table.

.formats

(named character or list)
formats for the statistics. See Details in analyze_vars for more information on the "auto" setting.

.labels

(named character)
labels for the statistics (without indent).

.indent_mods

(named vector of integer)
indent modifiers for the labels. Each element of the vector should be a name-value pair with name corresponding to a statistic specified in .stats and value the indentation for that statistic's row label.

Value

  • s_surv_timepoint() returns the statistics:

    • pt_at_risk: Patients remaining at risk.

    • event_free_rate: Event-free rate (%).

    • rate_se: Standard error of event free rate.

    • rate_ci: Confidence interval for event free rate.

  • s_surv_timepoint_diff() returns the statistics:

    • rate_diff: Event-free rate difference between two groups.

    • rate_diff_ci: Confidence interval for the difference.

    • ztest_pval: p-value to test the difference is 0.

  • surv_timepoint() returns a layout object suitable for passing to further layouting functions, or to rtables::build_table(). Adding this function to an rtable layout will add formatted rows containing the statistics from s_surv_timepoint() and/or s_surv_timepoint_diff() to the table layout depending on the value of method.

Functions

  • s_surv_timepoint(): Statistics function which analyzes survival rate.

  • a_surv_timepoint(): Formatted analysis function which is used as afun in surv_timepoint() when method = "surv".

  • s_surv_timepoint_diff(): Statistics function which analyzes difference between two survival rates.

  • a_surv_timepoint_diff(): Formatted analysis function which is used as afun in surv_timepoint() when method = "surv_diff".

  • surv_timepoint(): Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper for rtables::analyze().

Examples

library(dplyr)

adtte_f <- tern_ex_adtte %>%
  filter(PARAMCD == "OS") %>%
  mutate(
    AVAL = day2month(AVAL),
    is_event = CNSR == 0
  )
df <- adtte_f %>%
  filter(ARMCD == "ARM A")

df_ref_group <- adtte_f %>%
  filter(ARMCD == "ARM B")

# Survival at given time points.
basic_table() %>%
  split_cols_by(var = "ARMCD", ref_group = "ARM A") %>%
  add_colcounts() %>%
  surv_timepoint(
    vars = "AVAL",
    var_labels = "Months",
    is_event = "is_event",
    time_point = 7
  ) %>%
  build_table(df = adtte_f)
#>                                    ARM A            ARM B            ARM C     
#>                                    (N=69)           (N=73)           (N=58)    
#> ———————————————————————————————————————————————————————————————————————————————
#> 7 Months                                                                       
#>   Patients remaining at risk         54               57               42      
#>   Event Free Rate (%)              84.89            79.43            75.50     
#>   95% CI                       (76.24, 93.53)   (70.15, 88.71)   (64.33, 86.67)

# Difference in survival at given time points.
basic_table() %>%
  split_cols_by(var = "ARMCD", ref_group = "ARM A") %>%
  add_colcounts() %>%
  surv_timepoint(
    vars = "AVAL",
    var_labels = "Months",
    is_event = "is_event",
    time_point = 9,
    method = "surv_diff",
    .indent_mods = c("rate_diff" = 0L, "rate_diff_ci" = 2L, "ztest_pval" = 2L)
  ) %>%
  build_table(df = adtte_f)
#>                                   ARM A        ARM B            ARM C     
#>                                   (N=69)       (N=73)           (N=58)    
#> ——————————————————————————————————————————————————————————————————————————
#> 9 Months                                                                  
#>   Difference in Event Free Rate                -9.64            -13.03    
#>       95% CI                               (-22.80, 3.52)   (-27.59, 1.53)
#>       p-value (Z-test)                         0.1511           0.0794    

# Survival and difference in survival at given time points.
basic_table() %>%
  split_cols_by(var = "ARMCD", ref_group = "ARM A") %>%
  add_colcounts() %>%
  surv_timepoint(
    vars = "AVAL",
    var_labels = "Months",
    is_event = "is_event",
    time_point = 9,
    method = "both"
  ) %>%
  build_table(df = adtte_f)
#>                                       ARM A            ARM B            ARM C     
#>                                       (N=69)           (N=73)           (N=58)    
#> ——————————————————————————————————————————————————————————————————————————————————
#> 9 Months                                                                          
#>   Patients remaining at risk            53               53               39      
#>   Event Free Rate (%)                 84.89            75.25            71.86     
#>   95% CI                          (76.24, 93.53)   (65.32, 85.17)   (60.14, 83.57)
#>   Difference in Event Free Rate                        -9.64            -13.03    
#>     95% CI                                         (-22.80, 3.52)   (-27.59, 1.53)
#>     p-value (Z-test)                                   0.1511           0.0794