Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

trim

Trim Weights


Description

Trims (i.e., truncates) large weights by setting all weights higher than that at a given quantile to the weight at the quantile. This can be useful in controlling extreme weights, which can reduce effective sample size by enlarging the variability of the weights.

Usage

## S3 method for class 'wimids'
trim(w, at = 0, lower = FALSE, ...)

Arguments

w

A wimids object; the output of a call to weightthem().

at

numeric; either the quantile of the weights above which weights are to be trimmed (given as a single number between .5 and 1) or the number of weights to be trimmed (e.g., at = 3 for the top 3 weights to be set to the 4th largest weight).

lower

logical; whether also to trim at the lower quantile (e.g., for at = .9, trimming at both the .1 and .9 quantiles, or for at = 3, trimming the top and bottom 3 weights).

...

Ignored.

Details

trim.wimids() works by calling WeightIt::trim() on each weightit object stored in the models component of the wimid object. Because trim() itself is not exported from MatchThem, it must be called using WeightIt::trim() or by attaching WeightIt (i.e., running library(WeightIt)) before use. See Example.

Value

An object of class wimids, identical to the original object except with trim() applied to each of the weightit objects in the models component.

Author(s)

Noah Greifer

See Also

Examples

#Loading libraries
library(MatchThem)

#Loading the dataset
data(osteoarthritis)

#Multiply imputing the missing values
imputed.datasets <- mice::mice(osteoarthritis, m = 5)

#Estimating weights of observations in the multiply imputed datasets
weighted.datasets <- weightthem(OSP ~ AGE + SEX + BMI + RAC + SMK,
                                imputed.datasets,
                                approach = 'within',
                                method = 'ps',
                                estimand = "ATE")

#Trimming the top 10% of weights in each dataset
#to the 90th percentile
trimmed.datasets <- trim(weighted.datasets, at = .9)

MatchThem

Matching and Weighting Multiply Imputed Datasets

v1.0.0
GPL (>= 2)
Authors
Farhad Pishgar [aut, cre], Noah Greifer [aut], Clémence Leyrat [ctb], Elizabeth Stuart [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.