data(dataDIVAT2)
# adjusted Kaplan-Meier estimator by IPW
Pr0 <- glm(ecd ~ 1, family = binomial(link="logit"), data=dataDIVAT2)$fitted.values[1]
Pr1 <- glm(ecd ~ age + hla + retransplant, data=dataDIVAT2,
family=binomial(link = "logit"))$fitted.values
W <- (dataDIVAT2$ecd==1) * (1/Pr1) + (dataDIVAT2$ecd==0) * (1)/(1-Pr1)
res.akm <-ipw.survival(times=dataDIVAT2$times, failures=dataDIVAT2$failures,
variable=dataDIVAT2$ecd, weights=W)
plot(res.akm, ylab="Confounder-adjusted survival",
xlab="Time post-transplantation (years)", col=c(1,2), grid.lty=1)
Run the code above in your browser using DataLab