Adds sampling weights to a matchit
object so that they are
incorporated into balance assessment and creation of the weights. This would
typically only be used when an argument to s.weights
was not supplied
to matchit()
(i.e., because they were not to be included in the estimation
of the propensity score) but sampling weights are required for generalizing
an effect to the correct population. Without adding sampling weights to the
matchit
object, balance assessment tools (i.e., summary.matchit()
and plot.matchit()
) will not calculate balance statistics correctly, and
the weights produced by match.data()
and get_matches()
will not
incorporate the sampling weights.
add_s.weights(m, s.weights = NULL, data = NULL)
a matchit
object; the output of a call to matchit()
,
typically with the s.weights
argument unspecified.
an numeric vector of sampling weights to be added to the
matchit
object. Can also be specified as a string containing the name
of variable in data
to be used or a one-sided formula with the
variable on the right-hand side (e.g., ~ SW
).
a data frame containing the sampling weights if given as a
string or formula. If unspecified, add_s.weights()
will attempt to find
the dataset using the environment of the matchit
object.
a matchit
object with an s.weights
component
containing the supplied sampling weights. If s.weights = NULL
, the original
matchit
object is returned.
data("lalonde")
# Generate random sampling weights, just
# for this example
sw <- rchisq(nrow(lalonde), 2)
# NN PS match using logistic regression PS that doesn't
# include sampling weights
m.out <- matchit(treat ~ age + educ + race + nodegree +
married + re74 + re75, data = lalonde)
m.out
#> A matchit object
#> - method: 1:1 nearest neighbor matching without replacement
#> - distance: Propensity score
#> - estimated with logistic regression
#> - number of obs.: 614 (original), 370 (matched)
#> - target estimand: ATT
#> - covariates: age, educ, race, nodegree, married, re74, re75
# Add s.weights to the matchit object
m.out <- add_s.weights(m.out, sw)
m.out #note additional output
#> A matchit object
#> - method: 1:1 nearest neighbor matching without replacement
#> - distance: Propensity score
#> - estimated with logistic regression
#> - sampling weights not included in estimation
#> - number of obs.: 614 (original), 370 (matched)
#> - sampling weights: present
#> - target estimand: ATT
#> - covariates: age, educ, race, nodegree, married, re74, re75
# Check balance; note that sample sizes incorporate
# s.weights
summary(m.out, improvement = FALSE)
#>
#> Call:
#> matchit(formula = treat ~ age + educ + race + nodegree + married +
#> re74 + re75, data = lalonde)
#>
#> Summary of Balance for All Data:
#> Means Treated Means Control Std. Mean Diff. Var. Ratio eCDF Mean
#> distance 0.5707 0.1802 1.7659 0.9422 0.3726
#> age 25.5420 28.4092 -0.4286 0.3760 0.0990
#> educ 10.4701 10.1135 0.2094 0.3365 0.0511
#> raceblack 0.8357 0.1929 1.7344 . 0.6427
#> racehispan 0.0478 0.1498 -0.4778 . 0.1020
#> racewhite 0.1165 0.6573 -1.6855 . 0.5408
#> nodegree 0.7144 0.6293 0.1882 . 0.0850
#> married 0.1769 0.4940 -0.8311 . 0.3171
#> re74 2622.1279 5445.0090 -0.5373 0.5766 0.1722
#> re75 1861.1995 2155.9494 -0.0782 1.4130 0.0647
#> eCDF Max
#> distance 0.6512
#> age 0.1903
#> educ 0.1744
#> raceblack 0.6427
#> racehispan 0.1020
#> racewhite 0.5408
#> nodegree 0.0850
#> married 0.3171
#> re74 0.3562
#> re75 0.2311
#>
#> Summary of Balance for Matched Data:
#> Means Treated Means Control Std. Mean Diff. Var. Ratio eCDF Mean
#> distance 0.5707 0.3639 0.9349 0.7573 0.1262
#> age 25.5420 25.6969 -0.0232 0.3542 0.1031
#> educ 10.4701 10.6044 -0.0788 0.3352 0.0464
#> raceblack 0.8357 0.4592 1.0159 . 0.3765
#> racehispan 0.0478 0.2156 -0.7862 . 0.1678
#> racewhite 0.1165 0.3252 -0.6505 . 0.2087
#> nodegree 0.7144 0.6571 0.1269 . 0.0573
#> married 0.1769 0.1636 0.0348 . 0.0133
#> re74 2622.1279 2320.3799 0.0574 1.2317 0.0360
#> re75 1861.1995 1366.3361 0.1312 2.4538 0.0513
#> eCDF Max Std. Pair Dist.
#> distance 0.4001 0.9703
#> age 0.2843 1.4859
#> educ 0.1315 1.4408
#> raceblack 0.3765 1.0064
#> racehispan 0.1678 1.1650
#> racewhite 0.2087 0.7582
#> nodegree 0.0573 0.9932
#> married 0.0133 0.8217
#> re74 0.1689 0.7590
#> re75 0.1740 0.6446
#>
#> Sample Sizes:
#> Control Treated
#> All (ESS) 231.6 98.03
#> All 429. 185.
#> Matched (ESS) 104.29 98.03
#> Matched 185. 185.
#> Unmatched 244. 0.
#> Discarded 0. 0.
#>