View source: R/weights_for_population.R
| weights_for_population | R Documentation |
Calculates survey weights given respondent information and target population demographics. Respondent demographic info must be properly encoded in respondentdata to work with targetdata. If respondent demographic info is missing, the respondent's weight will be coded 1. Weight values trimmed so that no weights are greater than 6 or less than .1.
weights_for_population(respondentdata, targetdata)
respondentdata |
Data frame with encoded respondent demographic information (use encode.cloud.respondent.variables to prepare). Must include: ParticipantId, black, ba_or_more, hhincome_over50k, age35plus, woman, hispanic, respondent_na. |
targetdata |
A one-row data.frame (or named vector) with the following statistics in [0, 1]: black, ba_or_more, hhincome_over50k, age35plus, woman, hispanic (use target.population.demographics to obtain). |
Returns respondentdata with raked sampling weights encoded.
library(sate)
example_n <- 100
example <- data.frame(Race = sample(x=c("Black or African American", "Other"),
size=example_n, replace=TRUE),
Education = sample(x=c("Bachelor's degree (for example: BA, AB, BS)",
"Other"), size=example_n, replace=TRUE),
Household.Income = sample(x=c("$70,000-$79,999", "Other"),
size=example_n, replace=TRUE),
Age = sample(x=18:80, size=example_n, replace=TRUE),
Gender = sample(x=c("Woman", "Man", "Prefer not to say"),
size=example_n, replace=TRUE),
Ethnicity = sample(x=c("No, not of Hispanic, Latino, or Spanish origin",
"Other"), size=example_n, replace=TRUE),
ParticipantId = 1:example_n)
respondents.encoded <- encode.cloud.respondent.variables(dataset=example)
pop.targets <- target.population.demographics(state="FL")
respondents.weighted <- weights_for_population(respondentdata = respondents.encoded,
targetdata = pop.targets)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.