| weigh | R Documentation |
Applies weights to participants in a contact_survey object. Weights are
always multiplied into an existing weight column (or one is created with
value 1), making multiple calls composable.
The behaviour depends on the combination of arguments:
target = NULLNumeric column: multiply weight by column values
directly.
target + groupsMap column values to groups, assign
target[g] / n_in_group per participant.
targetNames match column values, assign
target[val] / n_with_val per participant.
targetPost-stratify against population data (expanded
to single-year ages via pop_age()).
weigh(survey, by, target = NULL, groups = NULL, ...)
survey |
a |
by |
column name in the participant data to weigh by |
target |
target weights: |
groups |
a list of value sets mapping column values to groups (used
with unnamed |
... |
further arguments passed to |
the survey object with updated participant weights
data(polymod)
# Direct numeric weighting
if ("survey_weight" %in% names(polymod$participants)) {
polymod |> weigh("survey_weight")
}
# Dayofweek weighting with groups (POLYMOD uses 0 = Sunday, 6 = Saturday)
polymod |>
weigh("dayofweek", target = c(5, 2), groups = list(1:5, c(0, 6)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.