| collect_replicate_weights | R Documentation |
Returns 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.
collect_replicate_weights(
boot,
weight_name = ".weight",
prefix = "rep_",
drop_zero = TRUE
)
boot |
a |
weight_name |
name of the point-weight column to add. |
prefix |
prefix for the replicate-weight columns ( |
drop_zero |
keep only active units (point weight > 0). |
A data frame: the original columns, weight_name, and one column per
replicate. The number of replicates is stored in attribute "R".
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 (requireNamespace("srvyr", quietly = TRUE) &&
requireNamespace("dplyr", quietly = TRUE)) {
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.