trim_weights: Trim weights

Description Usage Arguments Value Examples

Description

Trim survey weights. Wrapper for the trimWeights() function in the survey package that eliminates the need to create a svydesign object.

Usage

1
2
3
4
5
6
7
8
trim_weights(
  weight,
  lower_quantile = 0.01,
  upper_quantile = 0.99,
  minval = NULL,
  maxval = NULL,
  strict = FALSE
)

Arguments

weight

A numeric vector of weights

lower_quantile

The quantile at which the weights should be trimmed on the lower end

upper_quantile

The quantile at which the weights should be trimmed on the upper end

minval

NULL by default. If the lower quantile is less than the minimum value, minval will be used for the trim.

maxval

NULL by default. If the upper quantile is greater than the maximum value, maxval will be used for the trim.

strict

When the trimmed weights are reapportioned, some values may exceed the specificed threshold value. If strict = FALSE this is permitted. Otherwise, weights are trimmed recursively until none exceed the limit.

Value

A numeric vector of trimmed weights

Examples

1
2
3
4
5
calculate_deff(dec13_excerpt$weight)
trimmed <- trim_weights(dec13_excerpt$weight, lower_quantile = 0.1, upper_quantile = 0.9)
# Trimming reduces the standard deviation of the weights, reducing reducing the design effect
# and increasing the effective sample size.
calculate_deff(trimmed)

pewresearch/pewmethods documentation built on March 27, 2020, 7:22 p.m.