Learn R Programming

ipw (version 1.0-1)

ipwplot: Plot Inverse Probability Weights

Description

For time varying weights: display boxplots within strata of follow-up time. For point treatment weights: display density plot.

Usage

ipwplot(weights, timevar = NULL, binwidth = NULL, logscale = TRUE,
        xlab = NULL, ylab = NULL, main = "", ref = TRUE, ...)

Arguments

weights
numerical vector of inverse probability weights to plot.
timevar
numerical vector representing follow-up time. When specified, boxplots within strata of follow-up time are displayed. When left unspecified, a density plot is displayed.
binwidth
numerical value indicating the width of the intervals of follow-up time; for each interval a boxplot is made. Ignored when timevar is not specified.
logscale
logical value. If TRUE, weights are plotted on a logarithmic scale.
xlab
label for the horizontal axis. When left unspecified, the name of the quantity on the horizontal axis is used.
ylab
label for the vertical axis. When left unspecified, the name of the quantity on the vertical axis is used.
main
main title for the plot.
ref
logical value. If TRUE, a reference line is plotted at y=1.
...
additional arguments passed to boxplot (when timevar is specified) or plot (when timevar is not specified).

Value

  • A plot is displayed.

See Also

basdat, haartdat, healthdat, ipwplot, ipwpoint, ipwtm, timedat, tstartfun.

Examples

Run this code
#Load longitudinal data from HIV positive individuals.
data(haartdat)

#CD4 is confounder for the effect of initiation of HAART therapy on mortality.
#Estimate inverse probability weights to correct for confounding.
#Exposure allocation model is Cox proportional hazards model.
temp <- ipwtm(
   exposure = haartind,
   family = "survival",
   numerator = ~ sex + age,
   denominator = ~ sex + age + cd4.sqrt,
   id = patient,
   tstart = tstart,
   timevar = fuptime,
   type = "first",
   data = haartdat)

#plot inverse probability weights
graphics.off()
ipwplot(weights = temp$ipw.weights, timevar = haartdat$fuptime,
   binwidth = 100, ylim = c(-1.5, 1.5), main = "Stabilized weights")

#MSM for the causal effect of initiation of HAART on mortality
#corrected for confounding by CD4 count using inverse probability weighting
#with robust standard error obtained using cluster().
summary(coxph(Surv(tstart, fuptime, event) ~ haartind + cluster(patient),
   data = haartdat, weights = temp$ipw.weights))   

#Uncorrected model
summary(coxph(Surv(tstart, fuptime, event) ~ haartind, data = haartdat))

Run the code above in your browser using DataLab