Closed okassi closed 4 years ago
Hi, thanks for asking! The source of the error you’re getting is because the variable name in my_skewed_sample
doesn’t match the variable name in the targets. This is because create_raking_targets,
by default, appends an “rk_”
prefix to the variable name when it creates the list of targets, and rake_survey
was thus also expecting your variable name to be called rk_weighting_variable.
This can easily be remedied two ways: either by setting the prefix
argument in create_raking_targets
to “”,
or by changing the name of the variable in my_skewed_sample
to rk_weighting_variable.
The error message isn't very informative in that respect, so we'll push a quick update soon to explicitly tell the user when the variable names don't match.
After a second look at ?create_raking_targets
this feature seems to be well explained in the documentation. Cheers, and thanks for a quick reply!
rake_survey
throws the error mentioned in the title. Simple reproducible example below (this follows https://medium.com/pew-research-center-decoded/weighting-survey-data-with-the-pewmethods-r-package-d040afb0d2c2):I get the error:
Error: All elements of
fsmust be factors
I managed to trace the error to
unify_margins
function called byrake_factors()
. A simple workaround was to comment out the line whereunify_margins
is called. This works fine if factor levels in fullpopulation$weighting_variable and my_skewed_sample$weighting_variable match.For reference, here is my R version:
And here's my system info: