| step_trim_calibrated | R Documentation |
Trims already-calibrated weights into an absolute interval [lower, upper]
while preserving the calibration totals of formula. Unlike
step_trim_weights() (which caps and then redistributes the trimmed mass, so
the calibration constraints are broken), this is a bounded re-calibration: it
finds the weights closest to the incoming ones that both lie in
[lower, upper] and still reproduce the totals the incoming weights achieve
(the generalized exponential method of Folsom & Singh 2000). The
absolute-weight bound is imposed as a per-unit
factor bound w_new / w in [lower/w, upper/w] on top of the incoming weights,
using the range-restricted Euclidean distance (calfun = "linear", the
default) or the multiplicative one (calfun = "raking"). Weights
inside the range that are not needed to restore the totals stay put; the
out-of-range ones saturate at their bound and the rest move as little as
possible. If the range is too tight to preserve every total, the totals that
cannot be met are relaxed and a warning is raised.
step_trim_calibrated(
spec,
formula,
lower = NULL,
upper = NULL,
calfun = c("linear", "raking"),
cluster = NULL,
equal_within_cluster = FALSE,
maxit = 100L,
tol = 1e-07
)
spec |
a weighting_spec. |
formula |
the auxiliaries whose calibration totals must be preserved
(right-hand side only), e.g. |
lower, upper |
numeric. Absolute bounds on the trimmed weight. At least
one must be supplied; the other defaults to no bound. For positive variance,
use a positive |
calfun |
distance function: "linear" (default; the range-restricted Euclidean distance) or "raking" (the multiplicative distance, which keeps the adjustment factors positive). |
cluster |
character or NULL. Cluster (e.g. household) id column, for
integrative trimming (with |
equal_within_cluster |
logical. If TRUE, integrative trimming: one
trimming factor per |
maxit |
integer. Maximum iterations for the bounded solver. |
tol |
numeric. Convergence tolerance for the bounded solver. |
This step is meant to run after a step_calibrate(): it acts on the
positive incoming weights and leaves dropped units (weight 0) alone.
The input weighting_spec with this step appended to its recipe. The
step is recorded only; it is evaluated when prep() is called.
Folsom, R. E. and Singh, A. C. (2000). The generalized exponential model for sampling weight calibration for extreme values, nonresponse, and poststratification. ASA Proceedings of the Section on Survey Research Methods, 598-603.
# calibrate, then trim the calibrated weights into [50, 400] without breaking
# the region/sex totals
weighting_spec(sample_survey, base_weights = pw) |>
step_calibrate(method = "raking",
margins = list(region = c(table(population$region)),
sex = c(table(population$sex)))) |>
step_trim_calibrated(~ region + sex, lower = 50, upper = 400) |>
prep()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.