Learn R Programming

mets (version 0.2.8)

ipw: Inverse Probability of Censoring Weights

Description

Calculates Inverse Probability of Censoring Weights (IPCW) and adds them to a data.frame

Usage

ipw(formula, data, cluster, samecens = FALSE, obsonly = TRUE,
  weightname = "w", cens.model = "aalen", pairs = FALSE, ...)

Arguments

formula
Formula specifying the censoring model
data
data frame
cluster
clustering variable
samecens
For clustered data, should same censoring be assumed (bivariate probability calculated as mininum of the marginal probabilities)
obsonly
Return data with uncensored observations only
weightname
Name of weight variable in the new data.frame
cens.model
Censoring model (default Aalens additive model)
pairs
For paired data (e.g. twins) only the complete pairs are returned (With pairs=TRUE)
...
Additional arguments to censoring model

Examples

Run this code
data(prt)
prtw <- ipw(Surv(time,status==0)~country, data=prt[sample(nrow(prt),5000),],
            cluster="id",weightname="w")
plot(0,type="n",xlim=range(prtw$time),ylim=c(0,1),xlab="Age",ylab="Probability")
count <- 0
for (l in unique(prtw$country)) {
    count <- count+1
    prtw <- prtw[order(prtw$time),]
    with(subset(prtw,country==l),
         lines(time,w,col=count,lwd=2))
}
legend("topright",legend=unique(prtw$country),col=1:4,pch=-1,lty=1)

Run the code above in your browser using DataLab