coxph_pairs | R Documentation |
coxph
comparisonsEvaluate pairwise group differences in hazard ratios with
coxph
. Note this function is intended to be used
for uni-variable models with a factor-like predictor.
coxph_pairs(
object,
data = NULL,
level = 0.95,
...,
relevel = FALSE,
method = p.adjust.methods,
digits = getOption("digits")
)
object |
an object of class alternatively, a formula in which case |
data |
(optional) a data frame in which to interpret the variables
named in |
level |
the confidence level for intervals; see |
... |
additional arguments passed to |
relevel |
logical; if |
method |
p-value correction method (default is |
digits |
integer indicating the number of decimal places to be used |
A list with three elements:
n |
the number of subjects in each pair of groups |
n_model |
the number of subjects in each pair of models, i.e., excluding subjects with missing data |
hr |
the hazard ratio between pairs of groups |
lci |
the lower |
uci |
the upper |
p.value |
Wald p-value for each hazard ratio. The lower and
upper triangles of the matrix are uncorrected and adjusted, respectively,
for multiple comparisons using |
survdiff_pairs
library('survival')
sdif <- survdiff(Surv(time, status) ~ sex, data = lung)
sfit <- survfit(Surv(time, status) ~ sex, data = lung)
cxph <- coxph(Surv(time, status) ~ sex, data = lung)
stopifnot(
identical(coxph_pairs(sdif), coxph_pairs(sfit)),
identical(coxph_pairs(sdif), coxph_pairs(cxph))
)
## numeric and integer variables will be treated as factor-like
sfit <- survfit(Surv(time, status) ~ extent, data = colon)
kmplot(sfit, add = TRUE)
coxph_pairs(sfit)$n
leg <- function(ii, jj, ...) {
hr <- coxph_pairs(sfit, ...)
sapply(seq_along(ii), function(i) {
j <- ii[i]
i <- jj[i]
sprintf(
'%s vs %s: n=%s, HR: %.2f (%.2f - %.2f), %s',
i, j, hr$n[i, j], hr$hr[i, j], hr$lci[i, j], hr$uci[i, j],
pvalr(hr$p.value[i, j], show.p = TRUE)
)
})
}
legend(
'bottomleft', leg(c('1', '1', '1'), c('2', '3', '4')),
lty = 1, col = 2:4, bty = 'n'
)
## compare
f <- function(x) exp(coef(x))
f(coxph(Surv(time, status) ~ extent, data = colon[colon$extent %in% c(1, 2), ]))
f(coxph(Surv(time, status) ~ extent, data = colon[colon$extent %in% c(1, 3), ]))
f(coxph(Surv(time, status) ~ extent, data = colon[colon$extent %in% c(1, 4), ]))
## etc ...
## rawr >= 1.0.0 allows multiple variables
sfit <- survfit(Surv(time, status) ~ sex + extent, data = colon)
coxph_pairs(sfit, method = 'BH')
## also allows for a formula to be passed (data arg required)
coxph_pairs(Surv(time, status) ~ sex + extent, data = colon)
## strata will be ignored
sdif <- survdiff(Surv(time, status) ~ sex + strata(inst), data = lung)
coxph_pairs(sdif)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.