Add sampling weights to a matchit object
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)
m |
a |
s.weights |
an numeric vector of sampling weights to be added to the |
data |
a data frame containing the sampling weights if given as a string or formula. If unspecified, |
a matchit
object with an s.weights
component containing the supplied sampling weights. The nn
component containing the sample sizes before and after matching will be adjusted to incorporate the sampling weights. If s.weights = NULL
, the original matchit
object is returned.
Noah Greifer
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 # Add s.weights to the matchit object m.out <- add_s.weights(m.out, sw) m.out #note additional output # Check balance; note that sample sizes incorporate # s.weights summary(m.out, improvement = FALSE)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.