Computes pairwise Cox proportional hazards tests and returns a gtsummary
object. The table splits the results by comparison arms, presenting the
p-value, Hazard Ratio, and 95% Confidence Interval in a stacked layout where
statistics form the rows of the table.
tbl_coxph(data, model_formula, arm, ref_group = NULL)(data.frame)
A data.frame containing the survival data,
including time, status, and the arm variable.
(formula)
A formula object specifying the survival model,
typically in the form Surv(time, status) ~ arm + covariates.
(character)
A single character string specifying the name of the column in data
that contains the grouping/treatment
arm variable. This column must be a factor
for correct stratification and comparison.
(character or NULL)
A single character string specifying the level of the arm variable
to be used as the reference group for
all pairwise comparisons. If NULL (the default),
the first unique level of the arm column is automatically
selected as the reference group.
A gtsummary object summarizing the pairwise Cox PH results.
# Setup sample survival data with 3 arms to test pairwise comparisons
library(survival)
surv_data <- survival::lung |>
dplyr::mutate(
arm = factor(sample(c("A", "B", "C"), dplyr::n(), replace = TRUE)),
status = status - 1
) |>
dplyr::filter(dplyr::if_all(dplyr::everything(), ~ !is.na(.)))
# Generate the gtsummary table
tbl_coxph(
data = surv_data,
model_formula = survival::Surv(time, status) ~ arm,
arm = "arm",
ref_group = "A"
)
B vs A
C vs A
# Setup sample survival data with 2 arms to test if table drops comparison
# column
surv_data_2arm <- survival::lung |>
dplyr::mutate(
arm = factor(sample(c("A", "B"), dplyr::n(), replace = TRUE)),
status = status - 1
) |>
dplyr::filter(dplyr::if_all(dplyr::everything(), ~ !is.na(.)))
# Generate the 2-arm gtsummary table
tbl_coxph(
data = surv_data_2arm,
model_formula = survival::Surv(time, status) ~ arm,
arm = "arm",
ref_group = "A"
)