calc_iptw_weights: Calculate Propensity Scores and IPTW Weights

View source: R/iptw_weights.R

calc_iptw_weightsR Documentation

Calculate Propensity Scores and IPTW Weights

Description

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.

Usage

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
)

Arguments

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)

Details

Propensity Score Estimation

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

Weight Types

  • 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).

Stabilized Weights

When stabilize=TRUE, weights are multiplied by marginal treatment probabilities to reduce variance while maintaining unbiasedness (Robins et al., 2000).

Weight Trimming

Extreme weights can cause instability. Trimming replaces weights outside specified quantiles with the quantile values (Crump et al., 2009).

Value

A list containing:

data

Original data with added propensity scores and weights

ps_model

Fitted propensity score model

weights

Vector of calculated weights

ps

Vector of propensity scores

diagnostics

List of diagnostic information including balance statistics

method

Method used for propensity score estimation

weight_type

Type of weights calculated

References

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.

Examples

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"
)


riskdiff documentation built on June 30, 2025, 9:07 a.m.