ipwpoint: Estimate Inverse Probability Weights (Point Treatment)

View source: R/ipwpoint.R

ipwpointR Documentation

Estimate Inverse Probability Weights (Point Treatment)

Description

Estimate inverse probability weights to fit marginal structural models in a point treatment situation. The exposure for which we want to estimate the causal effect can be binomial, multinomial, ordinal or continuous. Both stabilized and unstabilized weights can be estimated.

Usage

ipwpoint(exposure, family, link, numerator = NULL, denominator,
         data, trunc = NULL, ...)

Arguments

exposure

a vector, representing the exposure variable of interest. Both numerical and categorical variables can be used. A binomial exposure variable should be coded using values 0/1.

family

is used to specify a family of link functions, used to model the relationship between the variables in numerator or denominator and exposure, respectively. Alternatives are "binomial","multinomial", "ordinal" and "gaussian". A specific link function is then chosen using the argument link, as explained below. Regression models are fitted using glm, multinom, polr or glm, respectively.

link

specifies the link function between the variables in numerator or denominator and exposure, respectively. For family = "binomial" (fitted using glm) alternatives are "logit", "probit", "cauchit", "log" and "cloglog". For family = "multinomial" this argument is ignored, and multinomial logistic regression models are always used (fitted using multinom). For family = "ordinal" (fitted using polr) alternatives are "logit", "probit", "cauchit", and "cloglog". For family = "gaussian" this argument is ignored, and a linear regression model with identity link is always used (fitted using glm).

numerator

is a formula, specifying the right-hand side of the model used to estimate the elements in the numerator of the inverse probability weights. When left unspecified, unstabilized weights with a numerator of 1 are estimated.

denominator

is a formula, specifying the right-hand side of the model used to estimate the elements in the denominator of the inverse probability weights. This typically includes the variables specified in the numerator model, as well as confounders for which to correct.

data

is a dataframe containing exposure and the variables used in numerator and denominator.

trunc

optional truncation percentile (0-0.5). E.g. when trunc = 0.01, the left tail is truncated to the 1st percentile, and the right tail is truncated to the 99th percentile.When specified, both un-truncated and truncated weights are returned.

...

are further arguments passed to the function that is used to estimate the numerator and denominator models (the function is chosen using family).

Details

For each unit under observation, this function computes an inverse probability weight, which is the ratio of two probabilities:

  • the numerator contains the probability of the observed exposure level given observed values of stabilization factors (usually a set of baseline covariates). These probabilities are estimated using the model regressing exposure on the terms in numerator, using the link function indicated by family and link.

  • the denominator contains the probability of the observed exposure level given the observed values of a set of confounders, as well as the stabilization factors in the numerator. These probabilities are estimated using the model regressing exposure on the terms in denominator, using the link function indicated by family and link.

When the models from which the elements in the numerator and denominator are predicted are correctly specified, and there is no unmeasured confounding, weighting the observations by the inverse probability weights adjusts for confounding of the effect of the exposure of interest. On the weighted dataset a marginal structural model can then be fitted, quantifying the causal effect of the exposure on the outcome of interest.

With numerator specified, stabilized weights are computed, otherwise unstabilized weighs with a numerator of 1 are computed. With a continuous exposure, using family = "gaussian", weights are computed using the ratio of predicted densities. Therefore, for family = "gaussian" only stabilized weights can be used, since unstabilized weights would have infinity variance.

Value

A list containing the following elements:

ipw.weights

is a vector containing inverse probability weights for each unit under observation. This vector is returned in the same order as the measurements contained in data, to facilitate merging.

weights.trunc

is a vector containing truncated inverse probability weights for each unit under observation. This vector is only returned when trunc is specified.

call

is the original function call to ipwpoint.

num.mod

is the numerator model, only returned when numerator is specified.

den.mod

is the denominator model.

Missing values

Currently, the exposure variable and the variables used in numerator and denominator should not contain missing values.

Author(s)

Willem M. van der Wal willem@vanderwalresearch.com, Ronald B. Geskus rgeskus@oucru.org

References

Cole, S.R. & Hern<e1>n, M.A. (2008). Constructing inverse probability weights for marginal structural models. American Journal of Epidemiology, 168(6), 656-664.

Robins, J.M., Hern<e1>n, M.A. & Brumback, B.A. (2000). Marginal structural models and causal inference in epidemiology. Epidemiology, 11, 550-560.

Van der Wal W.M. & Geskus R.B. (2011). ipw: An R Package for Inverse Probability Weighting. Journal of Statistical Software, 43(13), 1-23. doi: 10.18637/jss.v043.i13.

See Also

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

Examples

#Simulate data with continuous confounder and outcome, binomial exposure.
#Marginal causal effect of exposure on outcome: 10.
n <- 1000
simdat <- data.frame(l = rnorm(n, 10, 5))
a.lin <- simdat$l - 10
pa <- exp(a.lin)/(1 + exp(a.lin))
simdat$a <- rbinom(n, 1, prob = pa)
simdat$y <- 10*simdat$a + 0.5*simdat$l + rnorm(n, -10, 5)
simdat[1:5,]

#Estimate ipw weights.
temp <- ipwpoint(
   exposure = a,
   family = "binomial",
   link = "logit",
   numerator = ~ 1,
   denominator = ~ l,
   data = simdat)
summary(temp$ipw.weights)

#Plot inverse probability weights
graphics.off()
ipwplot(weights = temp$ipw.weights, logscale = FALSE,
   main = "Stabilized weights", xlim = c(0, 8))

#Examine numerator and denominator models.
summary(temp$num.mod)
summary(temp$den.mod)

#Paste inverse probability weights
simdat$sw <- temp$ipw.weights

#Marginal structural model for the causal effect of a on y
#corrected for confounding by l using inverse probability weighting
#with robust standard error from the survey package.
require("survey")
msm <- (svyglm(y ~ a, design = svydesign(~ 1, weights = ~ sw,
   data = simdat)))
coef(msm)
confint(msm)


## Not run: 
#Compute basic bootstrap confidence interval .
#require(boot)
#boot.fun <- function(dat, index){
#   coef(glm(
#       formula = y ~ a,
#       data = dat[index,],
#       weights = ipwpoint(
#           exposure = a,
#           family = "gaussian",
#           numerator = ~ 1,
#           denominator = ~ l,
#           data = dat[index,])$ipw.weights))[2]
#   }
#bootres <- boot(simdat, boot.fun, 499);bootres
#boot.ci(bootres, type = "basic")

## End(Not run)


ipw documentation built on Jan. 7, 2023, 9:08 a.m.

Related to ipwpoint in ipw...