Skip to contents

pairwise_logrank_test() runs logrank_test() on each pair of groups, using only the rows of the two groups, and adjusts the p-values for the number of comparisons. It answers which groups differ once a test across all groups has found that some do.

Usage

pairwise_logrank_test(
  formula,
  data,
  weights,
  subset,
  na.action = stats::na.omit,
  rho = 0,
  gamma = 0,
  correction = c("holm", "bh", "bonferroni", "none")
)

Arguments

formula

A formula with a Surv() response on the left and the grouping variables on the right, such as Surv(time, status) ~ sex. Several variables give one group per combination. A strata() term, such as Surv(time, status) ~ sex + strata(inst), stratifies the test.

data

A data frame holding the variables in formula.

weights

Optional case weights, a column of data or a numeric vector.

subset

An optional expression selecting the rows of data to use.

na.action

What to do with rows that have missing values. The default drops them.

rho, gamma

The Fleming-Harrington weight exponents, each at least 0. The default of 0 for both is the log-rank test.

correction

The adjustment for multiple comparisons: "holm" (the default), "bh", "bonferroni", or "none".

Value

A data frame with one row per pair of groups, in the order of the groups: group1, group2 (the groups' labels), statistic, p_value (unadjusted), and p_adjusted.

Details

Holm's method (the default) and Bonferroni's control the chance of any false positive among the comparisons, Holm's with more power. The Benjamini-Hochberg method ("bh") controls the expected proportion of false positives among the comparisons called significant instead, and is less conservative.

Examples

lung <- data.frame(
  time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654),
  status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2),
  ecog = c(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2)
)
pairwise_logrank_test(Surv(time, status) ~ ecog, data = lung)
#>   group1 group2 statistic    p_value p_adjusted
#> 1      0      1  3.149006 0.07597325   0.152911
#> 2      0      2  3.809248 0.05097034   0.152911
#> 3      1      2  1.808411 0.17869896   0.178699
pairwise_logrank_test(Surv(time, status) ~ ecog, data = lung, correction = "bh")
#>   group1 group2 statistic    p_value p_adjusted
#> 1      0      1  3.149006 0.07597325  0.1139599
#> 2      0      2  3.809248 0.05097034  0.1139599
#> 3      1      2  1.808411 0.17869896  0.1786990