Description Usage Arguments Details Value Examples
Applies the raking algorithm to a survey using specified raking targets in order to obtain weights.
Wrapper around the calibrate
function from the survey
package with argument
calfun = "raking"
.
1 2 3 4 5 6 7 8 9 | rake_survey(
.data,
pop_margins,
base_weight = 1,
scale_to_n = TRUE,
epsilon = 5e-06,
maxit = 100,
...
)
|
.data |
A |
pop_margins |
A list of tibbles giving the population margins for raking variables.
|
base_weight |
The survey's base weight variable, if applicable. Can be ignored if the survey data doesn't come with a base weight. |
scale_to_n |
If |
epsilon |
A |
maxit |
Maximum number of iterations before stopping if raking has not converged. |
... |
Other arguments passed to |
The variables in .data
must exactly match the variables in pop_margins
both
in name in the factor values. Additionally, they should contain no missing data.
A vector of survey weights.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | library(dplyr)
# Prepare variables from the survey data for raking
dec13_excerpt_raking <- dec13_excerpt %>%
mutate(rk_sex = sex,
rk_recage = dk_to_na(recage, pattern = "DK/Ref"),
rk_receduc = dk_to_na(receduc, pattern = "DK/Ref")) %>%
impute_vars(.) %>%
mutate(rk_sex_receduc = interaction(rk_sex, rk_receduc, sep = ":"))
# Prepare population marginal distributions for raking
# Here we will use the acs_2017_excerpt dataset included wih the package
targets <- create_raking_targets(acs_2017_excerpt,
vars = c("sex", "recage", "receduc", "sex:receduc"),
wt = "weight")
# Now that we have raking variables and population targets, we can create a raking weight
fake_weight <- rake_survey(dec13_excerpt_raking, targets)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.