vignettes/session_lecture.Rmd
session_lecture.Rmd
\[ log(HR(x_i)) = log \frac{h(t|x_i)}{h_0(t)} = \beta_0 + \beta_1 x_{1i} + \beta_2 x_{2i} + ... + \beta_p x_{pi} \]
\(HR(x_i)\) is the hazard of patient \(i\) relative to baseline
\(h(t|x_i)\) is the time-dependent hazard function \(h(t)\) for patient \(i\)
\(h_0(t)\) is the baseline hazard function, and is the negative of the slope of the \(S_0(t)\), the baseline survival function.
Multiplicative model
suppressPackageStartupMessages(library(pensim))
set.seed(1)
mydat <- create.data(
nvars = c(1, 1),
nsamples = 500,
cors = c(0, 0),
associations = c(0.5, 0.5),
firstonly = c(TRUE, TRUE),
censoring = c(0, 8.5)
)$data
Rename variables of simulated data, and make one variable categorical:
summary(mydat)
## Var1 Var2 time cens
## low :323 Min. :-2.99695 Min. : 5 Min. :0.000
## high:177 1st Qu.:-0.79008 1st Qu.: 691 1st Qu.:0.000
## Median :-0.02126 Median :1970 Median :1.000
## Mean :-0.04594 Mean :2529 Mean :0.526
## 3rd Qu.: 0.68933 3rd Qu.:3874 3rd Qu.:1.000
## Max. : 3.05574 Max. :8481 Max. :1.000
## chisq df p
## Var1 0.00887 1 0.925
## Var2 4.92734 1 0.026
## GLOBAL 5.07415 2 0.079
pbc.os <-
mutate(pbc.os, stageordered = factor(stage, ordered = TRUE))
fit <- coxph(Surv(time, os) ~ stageordered, data = pbc.os)
summary(fit)
## Call:
## coxph(formula = Surv(time, os) ~ stageordered, data = pbc.os)
##
## n= 312, number of events= 125
##
## coef exp(coef) se(coef) z Pr(>|z|)
## stageordered.L 2.1759 8.8099 0.6801 3.199 0.00138 **
## stageordered.Q -0.3469 0.7069 0.5248 -0.661 0.50867
## stageordered.C 0.3209 1.3784 0.2990 1.073 0.28316
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## stageordered.L 8.8099 0.1135 2.3231 33.410
## stageordered.Q 0.7069 1.4146 0.2527 1.977
## stageordered.C 1.3784 0.7255 0.7671 2.477
##
## Concordance= 0.702 (se = 0.022 )
## Likelihood ratio test= 52.74 on 3 df, p=2e-11
## Wald test = 43.92 on 3 df, p=2e-09
## Score (logrank) test = 53.85 on 3 df, p=1e-11
Highly significant tests of overall fit by LRT, Wald, and logrank test.
## Call:
## coxph(formula = Surv(time, os) ~ age + sex + edema + stage +
## arm, data = pbc.os)
##
## n= 312, number of events= 125
##
## coef exp(coef) se(coef) z Pr(>|z|)
## age 0.027618 1.028003 0.009362 2.950 0.00318 **
## sexf -0.317540 0.727938 0.248839 -1.276 0.20193
## edema0.5 0.538715 1.713804 0.275287 1.957 0.05036 .
## edema1 2.080422 8.007845 0.276959 7.512 5.84e-14 ***
## stage2 1.535263 4.642546 1.034854 1.484 0.13793
## stage3 1.998217 7.375893 1.016097 1.967 0.04923 *
## stage4 2.666263 14.386101 1.016234 2.624 0.00870 **
## armtreatment 0.057946 1.059658 0.189200 0.306 0.75940
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## age 1.0280 0.97276 1.0093 1.047
## sexf 0.7279 1.37374 0.4470 1.186
## edema0.5 1.7138 0.58350 0.9992 2.940
## edema1 8.0078 0.12488 4.6534 13.780
## stage2 4.6425 0.21540 0.6108 35.288
## stage3 7.3759 0.13558 1.0067 54.040
## stage4 14.3861 0.06951 1.9630 105.430
## armtreatment 1.0597 0.94370 0.7313 1.535
##
## Concordance= 0.77 (se = 0.022 )
## Likelihood ratio test= 107.6 on 8 df, p=<2e-16
## Wald test = 120.8 on 8 df, p=<2e-16
## Score (logrank) test = 177.1 on 8 df, p=<2e-16
## stage2 stage3 stage4
## 1.607014 2.149500 3.062775
relevant to all kinds of regression, not just survival analysis
when analysis is separated into groups or strata
Strata have different baseline hazards
Coefficients / Hazard Ratios are calculated within stratum then combined.
Vittinghoff 6.3.2
Example - in R, strata() can be added to any model formula
## Call:
## coxph(formula = Surv(time, os) ~ trt + strata(stage), data = pbc.os)
##
## n= 312, number of events= 125
##
## coef exp(coef) se(coef) z Pr(>|z|)
## trt -0.1063 0.8992 0.1814 -0.586 0.558
##
## exp(coef) exp(-coef) lower .95 upper .95
## trt 0.8992 1.112 0.6302 1.283
##
## Concordance= 0.494 (se = 0.025 )
## Likelihood ratio test= 0.34 on 1 df, p=0.6
## Wald test = 0.34 on 1 df, p=0.6
## Score (logrank) test = 0.34 on 1 df, p=0.6
Orwoll, E. et al. (2005). Design and baseline characteristics of the osteoporotic fractures in men (MrOS) study–a large observational study of the determinants of fracture in older men. Contemporary Clinical Trials, 26(5), 569–585.
outcome ~ exposure + counfounder1 + confounder2
exposure ~ counfounder1 + confounder2
Step 2: use propensity predictions to match or stratify participants with similar propensity (for example, stratifying on quintiles of propensity)
Step 3: check adequacy of matching or stratification, ie by comparing attributes of matched participants
Step 4: test hypothesis among matched participants:
outcome ~ exposure