# NOT RUN {
library(survival)
library(rms)
library(ggplot2)
#### simulate data ####
n <- 1e2
set.seed(10)
dtS <- sampleData(n,outcome="survival")
seqTimes <- c(0,sort(dtS$time[dtS$event==1]),max(dtS$time))
#### Cox model ####
fit <- cph(formula = Surv(time,event)~ X1+X2,data=dtS,y=TRUE,x=TRUE)
#### plot.type = 1: for few timepoints ####
ateFit <- ate(fit, data = dtS, treatment = "X1",
times = c(1,2,5,10), se = TRUE, band = TRUE)
ggplot2::autoplot(ateFit)
ggplot2::autoplot(ateFit, band = FALSE)
ggplot2::autoplot(ateFit, type = "diffRisk")
ggplot2::autoplot(ateFit, type = "ratioRisk")
#### plot.type = 2: when looking at all jump times ####
ateFit <- ate(fit, data = dtS, treatment = "X1",
times = seqTimes, se = TRUE, band = TRUE)
ggplot2::autoplot(ateFit, plot.type = "2")
## customize plot
outGG <- ggplot2::autoplot(ateFit, plot.type = "2", alpha = 0.25)
outGG$plot + facet_wrap(~X1, labeller = label_both)
## Looking at the difference after smoothing
# }
# NOT RUN {
outGGS <- ggplot2::autoplot(ateFit, plot.type = "2", alpha = NA, smooth = TRUE)
outGGS$plot + facet_wrap(~X1, labeller = label_both)
# }
# NOT RUN {
## first derivative
## (computation of the confidence intervals takes time)
## (based on simulation - n.sim parameter)
# }
# NOT RUN {
ggplot2::autoplot(ateFit, plot.type = "2", smooth = TRUE,
band = FALSE, type = "diffRisk")
ggplot2::autoplot(ateFit, plot.type = "2", smooth = TRUE, first.derivative = TRUE,
band = FALSE, type = "diffRisk")
# }
Run the code above in your browser using DataLab