
Collect replicate weights into a data frame ready for srvyr
Source:R/variance.R
collect_replicate_weights.RdReturns the data with the point weight and the bootstrap replicate weights
as columns, so it can be fed directly to srvyr::as_survey_rep() (or
survey::svrepdesign()). Replicate columns are full weights, so use
combined.weights = TRUE, scale = 1 / R, rscales = 1, mse = TRUE.
Value
A data frame: the original columns, weight_name, and one column per
replicate. The number of replicates is stored in attribute "R".
Examples
spec <- weighting_spec(sample_survey, base_weights = pw) |>
step_calibrate(method = "raking",
margins = list(region = c(table(population$region))))
boot <- bootstrap_weights(spec, replicates = 30, strata = "region",
psu = "psu", seed = 1, progress = FALSE)
df <- collect_replicate_weights(boot)
if (FALSE) { # \dontrun{
srvyr::as_survey_rep(df, weights = .weight,
repweights = dplyr::starts_with("rep_"),
type = "bootstrap", combined.weights = TRUE,
scale = 1 / attr(df, "R"), rscales = 1, mse = TRUE)
} # }