library(survival)
# Fit a stratified model
coxph(Surv(time, status) ~ x + strata(sex), test1) # <= strata argument
#> Error in terms.formula(formula, specials = ss, data = data): object 'test1' not found
# Create a simple data set for a time-dependent model
test2 <- list(start=c(1,2,5,2,1,7,3,4,8,8),
stop=c(2,3,6,7,8,9,9,9,14,17),
event=c(1,1,1,1,1,1,1,0,0,0),
x=c(1,0,0,1,0,1,1,1,0,0))
fit <- summary(coxph(Surv(start, stop, event) ~ x, test2))
fit$coefficients
#> coef exp(coef) se(coef) z Pr(>|z|)
#> x -0.02110521 0.9791159 0.7951769 -0.02654153 0.9788254
Created on 2020-03-24 by the reprex package (v0.3.0)