library(survival)
#### simulate data ####
set.seed(10)
n <- 250
tau <- 1:5
d <- sampleData(n, outcome = "competing.risks")
dFull <- d[event!=0] ## (artificially) remove censoring
dSurv <- d[event!=2] ## (artificially) remove competing risk
#### no censoring ####
e.wglm <- wglm(Surv(time,event) ~ X1,
times = tau, data = dFull, product.limit = TRUE)
e.wglm ## same as a logistic regression at each timepoint
coef(e.wglm)
confint(e.wglm)
model.tables(e.wglm)
summary(ate(e.wglm, data = dFull, times = tau, treatment = "X1", verbose = FALSE))
#### right-censoring ####
## no covariante in the censoring model (independent censoring)
eC.wglm <- wglm(Surv(time,event) ~ X1,
times = tau, data = dSurv, product.limit = TRUE)
summary(eC.wglm)
weights(eC.wglm)
## with covariates in the censoring model
eC2.wglm <- wglm(Surv(time,event) ~ X1 + X8, formula.censor = ~ X1*X8,
times = tau, data = dSurv)
eC2.wglm
#### Competing risks ####
## here Kaplan-Meier as censoring model
eCR.wglm <- wglm(Surv(time,event) ~ X1, formula.censor = ~X1,
times = tau, data = d)
eCR.wglm
summary(eCR.wglm)
eCR.wglm <- wglm(Surv(time,event) ~ X1, formula.censor = ~X1,
times = tau, data = d)
Run the code above in your browser using DataLab