# NOT RUN {
library(survival)
library(ggplot2)
## predictions ##
d <- sampleData(1e2, outcome = "survival")
m.cox <- coxph(Surv(time,event)~ X1 + X2 + X3,
data = d, x = TRUE, y = TRUE)
dt.basehaz <- predictCox(m.cox)
ggplot(as.data.table(dt.basehaz), aes(x = time, y = survival)) + geom_point() + geom_line()
pred.cox <- predictCox(m.cox, newdata = d[1:4,],
times = 1:5, type = "survival", keep.newdata = TRUE)
autoplot(pred.cox)
autoplot(pred.cox, groupBy = "covariates")
autoplot(pred.cox, groupBy = "covariates", reduce.data = TRUE)
m.cox.strata <- coxph(Surv(time,event)~ strata(X1) + strata(X2) + X3 + X6,
data = d, x = TRUE, y = TRUE)
pred.cox.strata <- predictCox(m.cox.strata, newdata = d[1,,drop=FALSE],
time = 1:5, keep.newdata = TRUE)
autoplot(pred.cox.strata, type = "survival")
autoplot(pred.cox.strata, type = "survival", groupBy = "strata")
res <- autoplot(pred.cox.strata, type = "survival",
groupBy = "covariates")
# customize display
res$plot + geom_point(data = res$data, size = 5)
## predictions with confidence interval
pred.cox <- predictCox(m.cox, newdata = d[1,,drop=FALSE],
times = 1:5, type = "survival", se = TRUE, keep.newdata = TRUE)
autoplot(pred.cox, ci = TRUE)
## predictions with confidence bands
pred.cox <- predictCox(m.cox, newdata = d[1,,drop=FALSE],
times = 1:5, type = "survival", nSim.band = 500, band = TRUE, keep.newdata = TRUE)
autoplot(pred.cox, band = TRUE)
# }
Run the code above in your browser using DataLab