library(survival)
data(pbc)
pbc <- pbc[order(pbc$time),]
# using the marginal Kaplan-Meier for the censoring times
WKM=ipcw(Surv(time,status)~edema,data=pbc,model="marginal",times=sort(unique(pbc$time)),otimes=pbc$time)
plot(WKM$fit)
WKM$fit
# using the Cox model for the censoring times given edema
WCox=ipcw(Surv(time,status)~edema,data=pbc,model="cox",times=sort(unique(pbc$time)),otimes=pbc$time)
WCox$fit
plot(WKM$fit)
lines(sort(unique(pbc$time)),1-WCox$wt[1,],type="l",col=2,lty=3,lwd=3)
lines(sort(unique(pbc$time)),1-WCox$wt[2,],type="l",col=3,lty=3,lwd=3)
# using the stratified Kaplan-Meier for the censoring times given edema
WKM2=ipcw(Surv(time,status)~edema,data=pbc,model="nonpar",times=sort(unique(pbc$time)),otimes=pbc$time)
plot(WKM2$fit,add=TRUE)
Run the code above in your browser using DataLab