R: Extract Weights from Preprocessing Objects

get.w {cobalt} | R Documentation

## Extract Weights from Preprocessing Objects

### Description

Extracts weights from the outputs of preprocessing functions.

### Usage

    get.w(x, ...)

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

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

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

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

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

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

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

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

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

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

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

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

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

    ## S3 method for class '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(s)

Noah Greifer

### See Also

`get.weights()` in twang.

### 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")

[Package cobalt version 4.3.2 Index]