design: A survey design object, created with either the survey or srvyr packages.
full_wgt_name: The column name to use for the full-sample weights
rep_wgt_prefix: For replicate design objects, a prefix to use for the column names of the replicate weights. The column names will be created by appending the replicate number after the prefix.
vars_to_keep: By default, all variables in the data will be kept. To select only a subset of the non-weight variables, you can supply a character vector of variable names to keep.
Returns
A data frame, with new columns containing the weights from the survey design object
Examples
data("lou_vax_survey", package ='svrep')library(survey)# Create a survey design objectsurvey_design <- svydesign(data = lou_vax_survey, weights =~ SAMPLING_WEIGHT, ids =~1)rep_survey_design <- as.svrepdesign(survey_design, type ="boot", replicates =10)# Adjust the weights for nonresponsenr_adjusted_design <- redistribute_weights( design = rep_survey_design, reduce_if = RESPONSE_STATUS =="Nonrespondent", increase_if = RESPONSE_STATUS =="Respondent", by = c("RACE_ETHNICITY","EDUC_ATTAINMENT"))# Save the survey design object as a data framenr_adjusted_data <- as_data_frame_with_weights( nr_adjusted_design, full_wgt_name ="NR_ADJUSTED_WGT", rep_wgt_prefix ="NR_ADJUSTED_REP_WGT_")head(nr_adjusted_data)# Check the column names of the resultcolnames(nr_adjusted_data)