Learn R Programming

junco (version 0.1.2)

kaplan_meier: Survival time analysis

Description

[Stable]

The analyze function kaplan_meier() creates a layout element to analyze survival time by calculating survival time median, 2 quantiles, each with their confidence intervals, and range (for all, censored, or event patients). The primary analysis variable vars is the time variable and the secondary analysis variable is_event indicates whether or not an event has occurred.

Usage

a_kaplan_meier(
  df,
  .var,
  ...,
  .stats = NULL,
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)

s_kaplan_meier(df, .var, is_event, control = control_surv_time())

Value

  • a_kaplan_meier() returns the corresponding list with formatted rtables::CellValue().

  • s_kaplan_meier() returns the following statistics:

    • quantiles_lower: Lower quantile estimate and confidence interval for it.

    • median_ci_3d: Median survival time and confidence interval for it.

    • quantiles_upper: Upper quantile estimate and confidence interval for it.

    • range_with_cens_info: Survival time range with censoring information.

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.

...

additional arguments for the lower level functions.

.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 integer)
indent modifiers for the labels. Defaults to 0, which corresponds to the unmodified default behavior. Can be negative.

is_event

(character)
variable name storing Logical values: TRUE if event, FALSE if time to event is censored.

control

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

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

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

  • quantiles (numeric)
    vector of length two to specify the quantiles of survival time.

Functions

  • a_kaplan_meier(): Formatted analysis function which is used as afun

  • s_kaplan_meier(): Statistics function which analyzes survival times using Kaplan-Meier.

Examples

Run this code
library(dplyr)
library(tern)
adtte_f <- tern::tern_ex_adtte |>
  filter(PARAMCD == "OS") |>
  mutate(
    AVAL = tern::day2month(AVAL),
    is_event = CNSR == 0
  )
df <- adtte_f |> filter(ARMCD == "ARM A")
a_kaplan_meier(
  df,
  .var = "AVAL",
  is_event = "is_event"
)

basic_table() |>
  split_cols_by(var = "ARMCD") |>
  add_colcounts() |>
  analyze(
    vars = "AVAL",
    afun = a_kaplan_meier,
    var_labels = "Kaplan-Meier estimate of time to event (months)",
    show_labels = "visible",
    extra_args = list(
      is_event = "is_event",
      control = control_surv_time(conf_level = 0.9, conf_type = "log-log")
    )
  ) |>
  build_table(df = adtte_f)

Run the code above in your browser using DataLab