Title: | Propensity Score Weighting Methods for Dichotomous Treatments |
---|---|
Description: | Provides propensity score weighting methods to control for confounding in causal inference with dichotomous treatments and continuous/binary outcomes. It includes the following functional modules: (1) visualization of the propensity score distribution in both treatment groups with mirror histogram, (2) covariate balance diagnosis, (3) propensity score model specification test, (4) weighted estimation of treatment effect, and (5) augmented estimation of treatment effect with outcome regression. The weighting methods include the inverse probability weight (IPW) for estimating the average treatment effect (ATE), the IPW for average treatment effect of the treated (ATT), the IPW for the average treatment effect of the controls (ATC), the matching weight (MW), the overlap weight (OVERLAP), and the trapezoidal weight (TRAPEZOIDAL). Sandwich variance estimation is provided to adjust for the sampling variability of the estimated propensity score. These methods are discussed by Hirano et al (2003) <DOI:10.1111/1468-0262.00442>, Lunceford and Davidian (2004) <DOI:10.1002/sim.1903>, Li and Greene (2013) <DOI:10.1515/ijb-2012-0030>, and Li et al (2016) <DOI:10.1080/01621459.2016.1260466>. |
Authors: | Huzhang Mao <[email protected]>, Liang Li <[email protected]> |
Maintainer: | Huzhang Mao <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1-3 |
Built: | 2025-03-13 04:16:46 UTC |
Source: | https://github.com/cran/PSW |
psw
is the main function to perfrom propensity score weighting analysis for (1) visualization of the propensity score distribution in both treatment groups,
(2) covariate balance diagnosis, (3) propensity score model specification test, (4) treatment effect estimation and inference, and (5) augmented estimation with outcome regression
when applicable.
psw(data, form.ps, weight, std.diff = FALSE, V.name = NULL, mirror.hist = FALSE, add.weight = FALSE, nclass = 50, wt = FALSE, out.var = NULL, family = "gaussian", aug = FALSE, form.outcome = NULL, spec.test = F, trans.type = NULL, K = 4)
psw(data, form.ps, weight, std.diff = FALSE, V.name = NULL, mirror.hist = FALSE, add.weight = FALSE, nclass = 50, wt = FALSE, out.var = NULL, family = "gaussian", aug = FALSE, form.outcome = NULL, spec.test = F, trans.type = NULL, K = 4)
data |
data frame to be used. |
form.ps |
propensity score model. |
weight |
weighting method to be used. Available methods are |
std.diff |
calculate standardized mean difference as a percentage, |
V.name |
a vector of covariates on which standardized mean difference is computed or the specification test is performed. If |
mirror.hist |
mirror histogram showing the propensity score distributions in both treatment groups, |
add.weight |
add propensity score weights to the mirror histogram, |
nclass |
number of breaks in the mirror histogram. |
wt |
estimate the weighted estimator, |
out.var |
outcome variable, needed when |
family |
outcome family, either |
aug |
estimate the augmented estimator, |
form.outcome |
outcome model, needed when |
spec.test |
propensity score model specification test, |
trans.type |
a vector of the same length as |
K |
value of |
In package PSW
, treatment indicator (left handside of form.ps
) should be dummy coded
such that a value of 1 indicates the treated and a value of 0 indicates the control. All categorical covariates need to be dummy coded too.
If the outcome belongs to the "gaussian"
family, causal estimation is based on the mean differnce between treatment groups. If the
outcome belongs to the "binomial"
family, causal estimation is based on risk difference, risk ratio, odds ratio or log odds ratio.
The Delta method is used for variance estimation when applicable.
Let be the treatment indicator of subject
,
be the corresponding propensity score. Then
propensity score weight,
, is defined as
where is a function depending
on
. For
"ATE"
, , which leads to estimating the average treatment effect. For
"ATT"
, ,
which leads to estimating average treatment effect for the treated. For
"ATC"
, , which leads to estimating average treatment effect
for the controls. For
"MW"
, . For
"OVERLAP"
, . For
"TRAPEZOIDAL"
,
. This type of weights are studied by Hirano, Imbens and Ridder (2003) and Li et al (2016).
The
function is specified by the
weight
argument.
The matching weight ("MW"
) was proposed by Li and Greene (2013). The overlap weight ("OVERLAP"
) was propsed by Li et al (2016).
These methods down weight subjects with propensity score close to 0 or 1. and hence improve the stability of computation.
A mirror histogram is produced to visualize the propensity score distributions in both treatment groups. In the mirror histogram, above the horizontal line
is the histogram of the propensiy scores of the control group, below is that of the treated group. The vertical axis of the histogram is the frequency. When
add.weight=TRUE
, the height of the green bar added to mirror histogram is the summation of the weights of subjects within the corresponding propensity
score stratum. For weighting methods of "ATE"
, "ATT"
, "ATC"
, add.weight
is not recommended for visualization because weights may
be larger than 1.
Standardized mean difference for a covariate is defiend as
where and
are weighted mean and standard deviation for the treated group, and
and
are defined similarly for the control group. A plot showing the standardized mean difference before and after weighting adjustement will be generated to
facilitate covariate balance diagnosis. It is sometimes recommended that the absolute values of standardized mean differences of all covariates should be less
than
10%
in order to claim covariate balance.
For the proensity score model specification test (Li and Greene, 2013), the quantity of interest is
where is a vector of covariates whose balance are examined, and
is a vector of monotone smooth transformations for the input.
Transformation type is specified by argument
trans.type
, and available transformation types are "identity"
, "log"
, "logit"
, "sqrt"
, "Fisher"
.
These transformations are recommended to improve the finite sample performance of the specification test. Log transformation ("log"
) and square root transformation ("sqrt"
)
are recommended for skewed data, logit transformation ("logit"
) for binary data, and Fisher z-transformation ("Fisher"
) for bounded data between .
The current version of model specification test is not available for
weight="OVERLAP"
because it results in zero standardized difference.
For estimation of mean difference ("gaussian"
family) or risk difference ("binomial"
family), the weighted estimator is
and the augmented estimator is
where is the conditional expectation of outcome when treated given covariates
,
and
is the conditional expectation of outcome when control given covariates
.
When the outcome belongs to the
"binomial"
family, the marginal probability is used to estimate risk ratio, odds ratio and log odds ratio.
Sandwich variance estimation is used to adjust for the sampling variability in the estimated propensity scores (Li and Greene, 2013).
The augmented estimator incorporates regression models for the outcome variable and has simliar properties as the doubly robust IPW estimator
(Lunceford and Davidian, 2004), but with one difference. The estimand of IPW estimator does not depend on the propensity score because
,
while the estimands of other weighting methods depend on propensity score specification. Nonetheless, the proposed augmented estimator converges to the estimand
defined by the corresponding propensity score model.
psw
returns a list of elements depending on the supplied arguments.
weight |
weighting method. |
ps.model |
object returned by fitting the propensity score model using |
ps.hat |
estimated propensity score. |
W |
estimated propensity score weight. |
std.diff.before |
A data frame of weighed mean, variance, and standardized mean difference for covariates in |
std.diff.after |
A data frame of weighed mean, variance, and standardized mean difference for covariates in |
est.wt |
weighted estimator for mean difference when |
std.wt |
standard error for |
est.aug |
augmented estimator for mean difference when |
std.aug |
standard error for |
est.risk.wt |
weighted estimator for risk difference when |
std.risk.wt |
standard error for |
est.risk.aug |
augmented estimator for risk difference when |
std.risk.aug |
standard error for |
est.rr.wt |
weighted estimator for relative risk when |
std.rr.wt |
standard error for |
est.or.wt |
weighted estimator for odds ratio when |
std.or.wt |
standard error for |
est.lor.wt |
weighted estimator for log odds ratio when |
std.lor.wt |
standard error for |
V.name |
covariates for balance diagnosis and specification test. |
test.stat |
test statistic for the specification test, which follows the |
df |
degree of freedom for the specification test, |
pvalue |
pvalue of the specification test when |
Hirano K, Imbens GW and Ridder G. "Efficient estimation of average treatment effects using the estimated propensity score." Econometrica 2003; 71(4): 1161-1189.
Li F, Morgan KL and Zaslavsky AM. "Balancing covariates via propensity score weighting." J Am Stat Assoc 2016; DOI:10.1080/01621459.2016.1260466.
Li L and Greene T. "A weighting analogue to pair matching in propensity score analysis." Int J Biostat 2013; 9(2):215-234.
Lunceford JK and Davidian M. Stratification and weighting via the propensity score in estimation of causal treatment effects: a comparative study. Stat Med. 2004; 23(19):2937-2960.
psw.balance, psw.spec.test, psw.wt, psw.aug, psw.mirror.hist.
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; # A vector of covariates V.name <- c( "X1", "X2", "X3", "X4" ); #1. Standardized differnce with "ATE" tmp1 <- psw( data = test_data, form.ps = form.ps, weight = "ATE", std.diff = TRUE, V.name = V.name ); #2. Mirror histogram and add estimated matching weight to it tmp2 <- psw( data = test_data, form.ps = form.ps, weight = "MW", mirror.hist = TRUE, add.weight = TRUE ); #3. Estimate average treatment effect with "ATE" tmp3 <- psw( data = test_data, form.ps = form.ps, weight = "ATE", wt = TRUE, out.var = "Y", family = "gaussian" ); #4. Augmented estimator with "OVERLAP" # outcome model form.out <- "Y ~ X1 + X2 + X3 + X4"; tmp4 <- psw( data = test_data, form.ps = form.ps, weight = "OVERLAP", aug = TRUE, form.outcome = form.out, family = "gaussian" ); #5. Propensity score model specification test with "MW". # A vector of transformation types for covariates in V.name. trans.type <- c( "identity", "identity", "logit", "logit" ); tmp5 <- psw( data = test_data, form.ps = form.ps, weight = "MW", spec.test = TRUE, V.name = V.name, trans.type = trans.type );
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; # A vector of covariates V.name <- c( "X1", "X2", "X3", "X4" ); #1. Standardized differnce with "ATE" tmp1 <- psw( data = test_data, form.ps = form.ps, weight = "ATE", std.diff = TRUE, V.name = V.name ); #2. Mirror histogram and add estimated matching weight to it tmp2 <- psw( data = test_data, form.ps = form.ps, weight = "MW", mirror.hist = TRUE, add.weight = TRUE ); #3. Estimate average treatment effect with "ATE" tmp3 <- psw( data = test_data, form.ps = form.ps, weight = "ATE", wt = TRUE, out.var = "Y", family = "gaussian" ); #4. Augmented estimator with "OVERLAP" # outcome model form.out <- "Y ~ X1 + X2 + X3 + X4"; tmp4 <- psw( data = test_data, form.ps = form.ps, weight = "OVERLAP", aug = TRUE, form.outcome = form.out, family = "gaussian" ); #5. Propensity score model specification test with "MW". # A vector of transformation types for covariates in V.name. trans.type <- c( "identity", "identity", "logit", "logit" ); tmp5 <- psw( data = test_data, form.ps = form.ps, weight = "MW", spec.test = TRUE, V.name = V.name, trans.type = trans.type );
psw.aug
is the function to estimate the augmented estimator for mean difference
(mean outcome difference for "gaussian"
family and risk difference for "binomial"
family).
The augmented estimator is consistent for the estimand defined by the corresponding propensity score model.
psw.aug(data, form.ps, weight, form.outcome, family = "gaussian", K = 4)
psw.aug(data, form.ps, weight, form.outcome, family = "gaussian", K = 4)
data |
data frame to be used. |
form.ps |
propensity score model. |
weight |
weighting method to be used. Available methods are |
form.outcome |
outcome model. |
family |
outcome family, either |
K |
value of |
psw.aug
is used to estimate the augmented estimator, ,
and make inference using the sandwich variance that adjusts for the sampling variability in the estimated propensity score.
A list of weighting method, fitted propensity score model, estimated propenstity scores, estimated propensity score weights, augmented estimator and associated standard error.
weight |
weighting method. |
ps.model |
object returned by fitting the propensity score model using |
ps.hat |
estimated propensity score. |
W |
estimated propensity score weight. |
est.aug |
augmented estimator for mean difference when |
std.aug |
standard error for |
est.risk.aug |
augmented estimator for risk difference when |
std.risk.aug |
standard error for |
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; # Outcome model form.out <- "Y ~ X1 + X2 + X3 + X4"; tmp <- psw.aug( data = test_data, form.ps = form.ps, weight = "ATE", form.outcome = form.out, family="gaussian" );
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; # Outcome model form.out <- "Y ~ X1 + X2 + X3 + X4"; tmp <- psw.aug( data = test_data, form.ps = form.ps, weight = "ATE", form.outcome = form.out, family="gaussian" );
psw.balance
is used to compute the standardized mean difference (in percentage) for balance diagnosis.
psw.balance(data, form.ps, weight, V.name = NULL, K = 4)
psw.balance(data, form.ps, weight, V.name = NULL, K = 4)
data |
data frame to be used. |
form.ps |
propensity score model. |
weight |
weighting method to be used. Available methods are |
V.name |
a vector of covariates on which standardized mean difference is computed. If |
K |
value of |
A list of weighting method, fitted propensity score model, estimated propenstity scores, estimated propensity score weights, standardized mean difference before and after weighting adjustment.
weight |
weighting method. |
ps.model |
object returned by fitting the propensity score model using |
ps.hat |
estimated propensity score. |
W |
estimated propensity score weight. |
std.diff.before |
A data frame of weighed mean, variance, and standardized mean difference for covariates in |
std.diff.after |
A data frame of weighed mean, variance, and standardized mean difference for covariates in |
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; # A vector of covariates V.name <- c( "X1", "X2", "X3", "X4" ); tmp <- psw.balance( data = test_data, weight = "MW", form.ps = form.ps, V.name = V.name );
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; # A vector of covariates V.name <- c( "X1", "X2", "X3", "X4" ); tmp <- psw.balance( data = test_data, weight = "MW", form.ps = form.ps, V.name = V.name );
psw.mirror.hist
is used to plot the mirror histogram that visualizes the propensity score distributions in both treatment groups.
psw.mirror.hist(data, form.ps, weight, add.weight = FALSE, nclass = 50, K = 4)
psw.mirror.hist(data, form.ps, weight, add.weight = FALSE, nclass = 50, K = 4)
data |
data frame to be used. |
form.ps |
propensity score model. |
weight |
weighting method to be used. Available methods are |
add.weight |
add propensity score weights to the mirror histogram, |
nclass |
number of breaks in the mirror histogram. |
K |
value of |
See psw
.
NULL
.
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; tmp <- psw.mirror.hist( data = test_data, weight = "MW", form.ps = form.ps, add.weight = TRUE );
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; tmp <- psw.mirror.hist( data = test_data, weight = "MW", form.ps = form.ps, add.weight = TRUE );
psw.spec.test
is used to test the sufficiency of propensity score model in balancing covariates between groups.
psw.spec.test(data, form.ps, weight, V.name, trans.type, K = 4)
psw.spec.test(data, form.ps, weight, V.name, trans.type, K = 4)
data |
data frame to be used. |
form.ps |
propensity score model. |
weight |
weighting method to be used. Available methods are |
V.name |
a vector of covariates on which the specification test is performed. |
trans.type |
a vector of the same length as |
K |
value of |
In the data set, treatment indicator should be numerically specified such that a value of 1
indicates the treated
and a value of 0
indicates the control. The null hypothesis is that the propensity score model is correctly specified; the
alternative is that the propensity score model is misspecified. Therefore, this test is a goodness-of-fit test of propensity score model,
with the test statistic being a metric of covariate balance.
#'
Rejection of the specification test implies current propensity score model is inadquate
for balancing covariates between groups.
A list of model specification test results.
weight |
weighting method. |
ps.model |
object returned by fitting the propensity score model using |
ps.hat |
estimated propensity score. |
W |
estimated propensity score weight. |
V.name |
covariates in the specification test. |
g.B1.hat |
a vector of transformed weighted average for covariates in the treated group when |
g.B0.hat |
a vector of transformed weighted average for covariates in the control group when |
B.hat |
difference between |
var.B.hat |
covariance matrix for |
test.stat |
test statistic for the specification test, which follows the |
df |
degree of freedom for the specification test, |
pvalue |
pvalue of the specification test when |
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; # A vector of covariates V.name <- c( "X1", "X2", "X3", "X4" ); # A vector of transformation types for covariates in V.name. trans.type <- c( "identity", "identity", "logit", "logit" ); tmp <- psw.spec.test( data = test_data, form.ps = form.ps, weight = "MW", V.name = V.name, trans.type = trans.type );
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; # A vector of covariates V.name <- c( "X1", "X2", "X3", "X4" ); # A vector of transformation types for covariates in V.name. trans.type <- c( "identity", "identity", "logit", "logit" ); tmp <- psw.spec.test( data = test_data, form.ps = form.ps, weight = "MW", V.name = V.name, trans.type = trans.type );
psw.wt
is used to estimate the weighted treatment effect estimator (without double robustness).
psw.wt(data, form.ps, weight, out.var, family = "gaussian", K = 4)
psw.wt(data, form.ps, weight, out.var, family = "gaussian", K = 4)
data |
data frame to be used. |
form.ps |
propensity score model. |
weight |
weighting method to be used. Available methods are |
out.var |
outcome variable. |
family |
outcome family, either |
K |
value of |
psw.wt
is used to estimate the weighted estimator, , and make inference using the sandwich variance estimator
that takes into account the sampling variability in the estimated propensity score.
A list of weighting method, fitted propensity score model, estimated propenstity scores, estimated propensity score weights, weighted estimator and standard error estimator
weight |
weighting method. |
ps.model |
object returned by fitting the propensity score model using |
ps.hat |
estimated propensity score. |
W |
estimated propensity score weight. |
est.wt |
weighted estimator for mean difference when |
std.wt |
standard error for |
est.risk.wt |
weighted estimator for risk difference when |
std.risk.wt |
standard error for |
est.rr.wt |
weighted estimator for relative risk when |
std.rr.wt |
standard error for |
est.or.wt |
weighted estimator for odds ratio when |
std.or.wt |
standard error for |
est.lor.wt |
weighted estimator for log odds ratio when |
std.lor.wt |
standard error for |
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; tmp <- psw.wt( data = test_data, weight = "ATE", form.ps = form.ps, out.var = "Y", family = "gaussian" );
# Load the test data set data(test_data); # Propensity score model form.ps <- "Z ~ X1 + X2 + X3 + X4"; tmp <- psw.wt( data = test_data, weight = "ATE", form.ps = form.ps, out.var = "Y", family = "gaussian" );
A simulated data frame for illustration. In the test data, and
are continuous variables,
and
are binary variables,
is the continuous outcome, and
is the dichotomous treatment indicator.
test_data
test_data