Extracts weights from the outputs of preprocessing functions.

get.w(x, ...)

# S3 method for matchit
get.w(x, ...)

# S3 method for ps
get.w(x, stop.method = NULL, estimand, s.weights = FALSE, ...)

# S3 method for mnps
get.w(x, stop.method = NULL, s.weights = FALSE, ...)

# S3 method for iptw
get.w(x, stop.method = NULL, s.weights = FALSE, ...)

# S3 method for ps.cont
get.w(x, s.weights = FALSE, ...)

# S3 method for Match
get.w(x, ...)

# S3 method for CBPS
get.w(x, estimand, ...)

# S3 method for ebalance
get.w(x, treat, ...)

# S3 method for optmatch
get.w(x, estimand, ...)

# S3 method for cem.match
get.w(x, estimand, ...)

# S3 method for weightit
get.w(x, s.weights = FALSE, ...)

# S3 method for mimids
get.w(x, ...)

# S3 method for wimids
get.w(x, ...)

# S3 method for designmatch
get.w(x, treat, estimand, ...)

# S3 method for sbwcau
get.w(x, ...)

Arguments

x

output from the corresponding preprocessing packages.

stop.method

the name of the stop method used in the original call to ps() or mnps() in twang, e.g., "es.mean". If empty, will return weights from all stop method available into a data.frame. Abbreviations allowed.

estimand

if weights are computed using the propensity score (i.e., for the ps and CBPS methods), which estimand to use to compute the weights. If "ATE", weights will be computed as 1/ps for the treated group and 1/(1-ps) for the control group. If "ATT", weights will be computed as 1 for the treated group and ps/(1-ps) for the control group. If not specified, get.w() will try to figure out which estimand is desired based on the object.

If weights are computed using subclasses/matching strata (i.e., for the cem and designmatch methods), which estimand to use to compute the weights. First, a subclass propensity score is computed as the proportion of treated units in each subclass, and the one of the formulas above will be used based on the estimand requested. If not specified, "ATT" is assumed.

treat

a vector of treatment status for each unit. This is required for methods that include treat as an argument. The treatment variable that was used in the original preprocessing function call should be used.

s.weights

whether the sampling weights included in the original call to the fitting function should be included in the weights. If TRUE, the returned weights will be the product of the balancing weights estimated by the fitting function and the sampling weights. If FALSE, only the balancing weights will be returned.

...

further arguments passed to or from other methods.

Details

The output of get.w() can be used in calls to the formula and data frame methods of bal.tab() (see example below). In this way, the output of multiple preprocessing packages can be viewed simultaneously and compared. The weights can also be used in weights statements in regression methods to compute weighted effects.

twang has a function called get.weights() that performs the same function on ps objects but offers slightly finer control. Note that the weights generated by get.w() for ps objects do not include sampling weights by default.

When sampling weights are used with CBPS() in CBPS, the returned weights will already have the sampling weights incorporated. To retrieve the balancing weights on their own, divide the returned weights by the original sampling weights. For other packages, the balancing weights are returned separately unless s.weights = TRUE, which means they must be multiplied by the sampling weights for effect estimation.

When Match() in Matching is used with CommonSupport = TRUE, the returned weights will be incorrect. This option is not recommended by the package authors.

Value

A vector or data frame of weights for each unit. These may be matching weights or balancing weights.

Author

Noah Greifer

See also

Examples

data("lalonde", package = "cobalt")
library("MatchIt"); library("WeightIt")

m.out <- matchit(treat ~ age + educ + race, data = lalonde) 

w.out <- weightit(treat ~ age + educ + race, data = lalonde,
                  estimand = "ATT")

bal.tab(treat ~ age + educ + race, data = lalonde,
        weights = data.frame(matched = get.w(m.out),
                             weighted = get.w(w.out)),
        method = c("matching", "weighting"), 
        estimand = "ATT")
#> Balance Measures
#>                Type Diff.matched Diff.weighted
#> age         Contin.      -0.0280        0.1078
#> educ        Contin.       0.0161       -0.0633
#> race_black   Binary       0.3730       -0.0020
#> race_hispan  Binary      -0.2703        0.0009
#> race_white   Binary      -0.1027        0.0011
#> 
#> Effective sample sizes
#>          Control Treated
#> All       429.       185
#> matched   185.       185
#> weighted  116.94     185