create_raking_targets: Create raking targets

Description Usage Arguments Details Value Examples

View source: R/create_raking_targets.R

Description

Given a dataset, creates a list of tibbles, each summarizing the marginal distribution of categorical variables from that dataset. These can be used as raking targets by passing them to the pop_margins argument in rake_survey. Each element in the list will have two columns: the name of the raking target, which will by default have the prefix "rk_" appended to indicate being a raking target, and the percentage of each category in that variable.

Usage

1
create_raking_targets(bm_data, vars, prefix = "rk_", new_sep = "_", wt = NULL)

Arguments

bm_data

The name of the dataset to be used for calculating marginal distributions.

vars

A character vector containing the names of all the variables that will be used for raking targets. Interactions between variables can be specified using the convention "variable1:variable2".

prefix

A string containing the prefix to be prepended to the name of the first column of each raking target. "rk_" by default.

new_sep

The character separating interaction variables, if applicable. "_" by default, does not do anything if no interaction variables present.

wt

The weight to be used in calculating the targets. For unweighted targets, use wt = 1.

Details

Datasets used to create raking targets generally come from microdata describing your population, which is taken to be the ground truth. For example, one frequently used dataset for obtaining demographic raking targets for the population of U.S. adults is the American Community Survey. If the dataset used is itself a survey, it may come with ts own survey weights needed for the raking targets to accurately describe the target population, in which case those weights need to be passed to the wt argument. To prevent errors, a value must be supplied for wt. Use wt = 1 if targets are to be based on unweighted data.

It is good practice to separate out variables used for raking from the raw variables, because raking variables may be processed via recoding and imputation, among other things. The prefix argument enforces this practice by adding a prefix to the names of the raking variables. If the output of this function is subsequently passed to the pop_margins argument of rake_survey, the code will search the sample data file for variables with the same names. This is meant to ensure consistency.

This function allows you to pass interactions between variables into the vars argument by inserting a : between two variable names. When an interaction is specified, the variable names will be concatenated using new_sep.

Value

A list, with each element being a tibble returned by get_totals for each raking target.

Examples

1
2
3
4
5
6
7
# Here we will use the acs_2017_excerpt dataset included wih the package

# Notice that the names in the output are by default called rk_sex, rk_recage, rk_receduc,
# and rk_sex_receduc
create_raking_targets(acs_2017_excerpt,
                      vars = c("sex", "recage", "receduc", "sex:receduc"),
                      wt = "weight")

pewresearch/pewmethods documentation built on March 27, 2020, 7:22 p.m.