Functions for calculating propensity score weights with optional trimming for binary and multiple treatment groups. Calculate Inverse Probability Weights (IPW)
Calculates inverse probability weights for binary or multiple treatment groups. For ATE (Average Treatment Effect), weights are 1/e_j(X) for each treatment j. For ATT (Average Treatment Effect on the Treated), weights target a specific treatment group.
calculate_ipw_weights(
ps_result,
data,
treatment_var,
estimand = "ATE",
att_group = NULL
)A numeric vector of IPW weights with length equal to nrow(data).
A list returned by estimate_ps(), containing:
ps_matrix: Matrix of propensity scores (n x J) for multiple treatments, or NULL for binary treatment
ps: Vector of propensity scores for observed treatment
n_levels: Number of treatment levels
treatment_levels: Vector of treatment level values
A data.frame containing the treatment variable.
A character string specifying the name of the treatment
variable in data.
Character string specifying the estimand. One of "ATE" (default) or "ATT" (Average Treatment Effect on the Treated).
For ATT estimation, specifies which treatment group to target. This is MANDATORY when estimand = "ATT".
For ATE with multiple treatments, weights are: $$w_j(X_i) = \frac{1}{e_j(X_i)} \text{ for individual i in treatment j}$$
For ATT targeting treatment k, weights are: $$w_j(X_i) = \begin{cases} 1 & \text{if } j = k \\ \frac{e_k(X_i)}{e_j(X_i)} & \text{if } j \neq k \end{cases}$$