| ipwpoint | R Documentation |
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.
ipwpoint(
exposure,
family,
link = NULL,
numerator = NULL,
denominator,
data,
trunc = NULL,
...
)
exposure |
Name of the exposure column in |
family |
Model family for exposure: |
link |
Link function for binomial ( |
numerator |
Formula specifying the right-hand side of the numerator model.
If |
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 ( |
A list of class "ipwpoint" containing:
ipw.weights |
Numeric vector of inverse probability weights. |
weights.trunc |
Numeric vector of truncated weights (if |
call |
The original function call. |
num.mod |
Numerator model object (if |
den.mod |
Denominator model object. |
Willem M. van der Wal willem@vanderwalresearch.com, Ronald B. Geskus rgeskus@oucru.org, Hung Thai Tran hungtt@oucru.org
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")}.
basdat, haartdat, ipwplot, ipwpoint, ipwtm, timedat, tstartfun.
# 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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.