This family of functions computes propensity score weights for various causal estimands:
ATE (Average Treatment Effect)
ATT (Average Treatment Effect on the Treated)
ATU (Average Treatment Effect on the Untreated, sometimes called the ATC, where the "C" stands for "control")
ATM (Average Treatment Effect for the Evenly Matchable)
ATO (Average Treatment Effect for the Overlap population)
The propensity score can be provided as a numeric vector of predicted probabilities or as a
data.frame
where each column represents the predicted probability for a level of the exposure. They can also be propensity score objects created byps_trim()
,ps_refit()
, orps_trunc()
The returned weights are encapsulated in a
psw
object, which is a numeric vector with additional attributes that record the estimand, and whether the weights have been stabilized, trimmed, or truncated.
Usage
wt_ate(
.propensity,
.exposure,
.sigma = NULL,
exposure_type = c("auto", "binary", "categorical", "continuous"),
.treated = NULL,
.untreated = NULL,
stabilize = FALSE,
stabilization_score = NULL,
...
)
wt_att(
.propensity,
.exposure,
exposure_type = c("auto", "binary", "categorical", "continuous"),
.treated = NULL,
.untreated = NULL,
...
)
wt_atu(
.propensity,
.exposure,
exposure_type = c("auto", "binary", "categorical", "continuous"),
.treated = NULL,
.untreated = NULL,
...
)
wt_atm(
.propensity,
.exposure,
exposure_type = c("auto", "binary", "categorical", "continuous"),
.treated = NULL,
.untreated = NULL,
...
)
wt_ato(
.propensity,
.exposure,
exposure_type = c("auto", "binary", "categorical", "continuous"),
.treated = NULL,
.untreated = NULL,
...
)
Arguments
- .propensity
Either a numeric vector of predicted probabilities or a
data.frame
where each column corresponds to a level of the exposure.- .exposure
The exposure variable. For binary exposures, a vector of 0s and 1s; for continuous exposures, a numeric vector.
- .sigma
For continuous exposures, a numeric vector of standard errors used with
dnorm()
. For example, this can be derived from the influence measures of a model (e.g.,influence(model)$sigma
).- exposure_type
Character string specifying the type of exposure. Options are
"auto"
,"binary"
,"categorical"
, and"continuous"
. Defaults to"auto"
, which detects the type automatically.- .treated
The value representing the treatment group. If not provided, it is automatically detected.
- .untreated
The value representing the control group. If not provided, it is automatically detected.
- stabilize
Logical indicating whether to stabilize the weights. For ATE weights, stabilization multiplies the weight by either the mean of
.exposure
or the suppliedstabilization_score
.- stabilization_score
Optional numeric value for stabilizing the weights (e.g., a predicted value from a regression model without predictors). Only used when
stabilize
isTRUE
.- ...
Reserved for future expansion. Not currently used.
Value
A psw
object (a numeric vector) with additional attributes:
estimand: A description of the estimand (e.g., "ate", "att").
stabilized: A logical flag indicating if stabilization was applied.
trimmed: A logical flag indicating if the weights are based on trimmed propensity scores.
truncated: A logical flag indicating if the weights are based on truncated propensity scores.
Details
Exposure Types
The functions support different types of exposures:
binary
: For dichotomous treatments (e.g. 0/1).continuous
: For numeric exposures. Here, weights are calculated via the normal density usingdnorm()
.categorical
: Currently not supported (an error will be raised).auto
: Automatically detects the exposure type based on.exposure
.
Stabilization
For ATE weights, stabilization can improve the performance of the estimator
by reducing variance. When stabilize
is TRUE
and no
stabilization_score
is provided, the weights are multiplied by the mean
of .exposure
. Alternatively, if a stabilization_score
is provided, it
is used as the multiplier.
Trimmed and Truncated Weights
In addition to the standard weight functions, versions exist for trimmed
and truncated propensity score weights created by ps_trim()
,
ps_trunc()
, and ps_refit()
. These variants calculate the weights using
modified propensity scores (trimmed or truncated) and update the estimand
attribute accordingly.
The main functions (wt_ate
, wt_att
, wt_atu
, wt_atm
, and wt_ato
)
dispatch on the class of .propensity
. For binary exposures, the weights
are computed using inverse probability formulas. For continuous exposures
(supported only for ATE), weights are computed as the inverse of the
density function evaluated at the observed exposure.
See also
psw()
for details on the structure of the returned weight objects.
Examples
## ATE Weights with a Binary Exposure
# Simulate a binary treatment and corresponding propensity scores
propensity_scores <- c(0.2, 0.7, 0.5, 0.8)
treatment <- c(0, 1, 0, 1)
# Compute ATE weights (unstabilized)
weights_ate <- wt_ate(propensity_scores, .exposure = treatment)
#> ℹ Treating `.exposure` as binary
weights_ate
#> <psw{estimand = ate}[4]>
#> [1] 1.250000 1.428571 2.000000 1.250000
# Compute ATE weights with stabilization using the mean of the exposure
weights_ate_stab <- wt_ate(propensity_scores, .exposure = treatment, stabilize = TRUE)
#> ℹ Treating `.exposure` as binary
weights_ate_stab
#> <psw{estimand = ate}[4]>
#> [1] 0.6250000 0.7142857 1.0000000 0.6250000
## ATT Weights for a Binary Exposure
propensity_scores <- c(0.3, 0.6, 0.4, 0.7)
treatment <- c(1, 1, 0, 0)
# Compute ATT weights
weights_att <- wt_att(propensity_scores, .exposure = treatment)
#> ℹ Treating `.exposure` as binary
weights_att
#> <psw{estimand = att}[4]>
#> [1] 1.0000000 1.0000000 0.6666667 2.3333333