calc_iptw_weights | R Documentation |
Calculates propensity scores and inverse probability of treatment weights for use in standardized risk difference estimation. Implements multiple approaches for weight calculation and includes diagnostic tools.
calc_iptw_weights(
data,
treatment,
covariates,
method = "logistic",
weight_type = "ATE",
stabilize = TRUE,
trim_weights = TRUE,
trim_quantiles = c(0.01, 0.99),
verbose = FALSE
)
data |
A data frame containing treatment and covariate data |
treatment |
Character string naming the binary treatment variable |
covariates |
Character vector of covariate names for propensity score model |
method |
Method for propensity score estimation: "logistic" (default), "probit", or "cloglog" |
weight_type |
Type of weights to calculate: "ATE" (average treatment effect, default), "ATT" (average treatment effect on treated), "ATC" (average treatment effect on controls) |
stabilize |
Logical indicating whether to use stabilized weights (default: TRUE) |
trim_weights |
Logical indicating whether to trim extreme weights (default: TRUE) |
trim_quantiles |
Vector of length 2 specifying quantiles for weight trimming (default: c(0.01, 0.99)) |
verbose |
Logical indicating whether to print diagnostic information (default: FALSE) |
The function fits a model predicting treatment assignment from covariates:
Logistic regression: Standard approach, assumes logit link
Probit regression: Uses probit link, may be more robust with extreme probabilities
Complementary log-log: Useful when treatment is rare
ATE weights: 1/pi(X) for treated, 1/(1-pi(X)) for controls
ATT weights: 1 for treated, pi(X)/(1-pi(X)) for controls
ATC weights: (1-pi(X))/pi(X) for treated, 1 for controls
Where pi(X) is the propensity score (probability of treatment given X).
When stabilize=TRUE, weights are multiplied by marginal treatment probabilities to reduce variance while maintaining unbiasedness (Robins et al., 2000).
Extreme weights can cause instability. Trimming replaces weights outside specified quantiles with the quantile values (Crump et al., 2009).
A list containing:
Original data with added propensity scores and weights
Fitted propensity score model
Vector of calculated weights
Vector of propensity scores
List of diagnostic information including balance statistics
Method used for propensity score estimation
Type of weights calculated
Austin PC (2011). "An Introduction to Propensity Score Methods for Reducing the Effects of Confounding in Observational Studies." Multivariate Behavioral Research, 46(3), 399-424. doi:10.1080/00273171.2011.568786
Crump RK, Hotz VJ, Imbens GW, Mitnik OA (2009). "Dealing with Limited Overlap in Estimation of Average Treatment Effects." Biometrika, 96(1), 187-199.
Hernan MA, Robins JM (2020). Causal Inference: What If. Boca Raton: Chapman & Hall/CRC.
Robins JM, Hernan MA, Brumback B (2000). "Marginal Structural Models and Causal Inference in Epidemiology." Epidemiology, 11(5), 550-560.
data(cachar_sample)
# Calculate ATE weights for areca nut use
iptw_result <- calc_iptw_weights(
data = cachar_sample,
treatment = "areca_nut",
covariates = c("age", "sex", "residence", "smoking"),
weight_type = "ATE"
)
# Check balance
print(iptw_result$diagnostics$balance_table)
# Calculate ATT weights (effect on the treated)
iptw_att <- calc_iptw_weights(
data = cachar_sample,
treatment = "tobacco_chewing",
covariates = c("age", "sex", "residence", "areca_nut"),
weight_type = "ATT"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.