set_survey: Specify the survey to analyze

View source: R/set_survey.R

set_surveyR Documentation

Specify the survey to analyze

Description

You must specify a survey before the other functions, such as tab(), will work. To convert a data.frame or similar to a survey object, see survey::svydesign() or survey::svrepdesign().

Usage

set_survey(design, aa_vr = NULL, aa_pop = NULL, ...)

Arguments

design

a survey object, created with survey::svydesign() or survey::svrepdesign(). For an unweighted survey, a data.frame or similar.

aa_vr

used to produce age-adjusted estimates only. The name of a categorical age variable located in design.

aa_pop

used to produce age-adjusted estimates only. A data.frame with columns named Level and Population. Level must exactly match the levels of aa_vr. Population is the population count or proportion/weight for that level of aa_vr.

...

arguments to set_opts().

Details

Optionally, the survey can have an attribute called label, which is the long name of the survey. Optionally, each variable in the survey can have an attribute called label, which is the variable's long name.

For age-adjustment, aa_pop$Population can contain either population counts or proportions/weights for each level. Values are normalized internally, so counts and proportions produce the same age-adjusted estimates when they describe the same standard population distribution.

Value

info about the survey

See Also

Other options: set_opts(), show_options(), surveytable-options

Examples

set_survey(namcs2019sv)
set_survey(namcs2019sv, mode = "NCHS")

## Age-adjusted estimation
set_survey(nhis2024a, aa_vr = "age_group_std", aa_pop = uspop_example$age_group_std)

surveytable documentation built on Aug. 20, 2026, 1:08 a.m.