library(survival)
library(rms)
set.seed(10)
n <- 1e2
## Cox model
dtS <- sampleData(n,outcome="survival")
dtS$time <- round(dtS$time,1)
dtS$X1 <- factor(rbinom(n, prob = c(0.3,0.4) , size = 2), labels = paste0("T",0:2))
fit=cph(formula = Surv(time,event)~ X1+X2,data=dtS,y=TRUE,x=TRUE)
## the cph object carries its call:
fit$call
## and there is a predictRisk method
"predictRisk.cph" %in% methods("predictRisk")
ateFit=ate(fit, data = dtS, treatment = "X1", contrasts = NULL,
times = 5:7, B = 3, y = TRUE, mc.cores=1)
ateFit=ate(fit, data = dtS, treatment = "X1", contrasts = NULL,
times = 5:7, B = 0, y = TRUE, mc.cores=1)
## Cause specific cox model
set.seed(17)
n=200
dt <- sampleData(n,outcome="competing.risks")
dt$time <- round(dt$time,1)
dt$X1 <- factor(rbinom(n, prob = c(0.2,0.3,0.2) , size = 3), labels = paste0("T",0:3))
fitCR= CSC(Hist(time,event)~ X1+X8,data=dt,cause=1)
ate(fitCR, data = dt, treatment = "X1", contrasts = NULL,
times = 7, cause = 1, B = 2, mc.cores=1)
atefit=ate(fitCR, data = dt, treatment = "X1", contrasts = NULL,
times = 1:7, cause = 1, B = 0, mc.cores=1,conf.level=FALSE)
ate(fitCR, data = dt, treatment = "X1", contrasts = NULL,
times = 5:7, cause = 1, B = 0, mc.cores=1)
Run the code above in your browser using DataLab