ipwpoint: Estimate Inverse Probability Weights (Point Treatment)

View source: R/ipwpoint.R

ipwpointR Documentation

Estimate Inverse Probability Weights (Point Treatment)

Description

Estimates inverse probability weights to fit marginal structural models in a point treatment situation. Exposure can be binomial, multinomial, ordinal, or continuous (gaussian). Both stabilized and unstabilized weights can be estimated.

Usage

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

Arguments

exposure

Name of the exposure column in data (unquoted or as a string). Binomial exposure variables should be coded as 0/1.

family

Model family for exposure: "binomial", "multinomial", "ordinal", or "gaussian".

link

Link function for binomial ("logit", "probit", "cauchit", "log", "cloglog") or ordinal ("logit", "probit", "cauchit", "cloglog"). Ignored for multinomial and gaussian.

numerator

Formula specifying the right-hand side of the numerator model. If NULL, unstabilized weights (numerator = 1) are calculated.

denominator

Formula specifying the right-hand side of the denominator model.

data

Data frame containing exposure and model covariates.

trunc

Optional truncation percentile between 0 and 0.5 (e.g., 0.01 for 1st/99th percentiles).

...

Additional arguments passed to model fitting functions (glm, multinom, polr).

Value

A list of class "ipwpoint" containing:

ipw.weights

Numeric vector of inverse probability weights.

weights.trunc

Numeric vector of truncated weights (if trunc is specified).

call

The original function call.

num.mod

Numerator model object (if numerator is specified).

den.mod

Denominator model object.

Author(s)

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

References

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

Robins, J.M., Herná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. \Sexpr[results=rd]{tools:::Rd_expr_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.
set.seed(16)
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
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
if (requireNamespace("survey", quietly = TRUE)) {
  library(survey)
  msm <- svyglm(y ~ a,
                design = svydesign(~1, weights = ~temp$ipw.weights,
                data = simdat))
  summary(msm)
}

ipw documentation built on Nov. 2, 2026, 1:10 a.m.