Skip to contents

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().

Value

info about the survey

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.

See also

Examples

set_survey(namcs2019sv)
#>                         Survey info {NAMCS 2019 PUF}                         
#> ┌───────────┬──────────────┬────────────────────────────────────────────────┐
#> │ Variables │ Observations │ Design                                         │
#> ├───────────┼──────────────┼────────────────────────────────────────────────┤
#> │        33 │        8,250 │ Stratified 1 - level Cluster Sampling design   │
#> │           │              │ (with replacement)                             │
#> │           │              │ With (398) clusters.                           │
#> │           │              │ namcs2019sv = survey::svydesign(ids = ~CPSUM,  │
#> │           │              │ strata = ~CSTRATM, weights = ~PATWT            │
#> │           │              │ , data = namcs2019sv_df)                       │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#> 
set_survey(namcs2019sv, mode = "NCHS")
#> * Mode: NCHS.
#>                         Survey info {NAMCS 2019 PUF}                         
#> ┌───────────┬──────────────┬────────────────────────────────────────────────┐
#> │ Variables │ Observations │ Design                                         │
#> ├───────────┼──────────────┼────────────────────────────────────────────────┤
#> │        33 │        8,250 │ Stratified 1 - level Cluster Sampling design   │
#> │           │              │ (with replacement)                             │
#> │           │              │ With (398) clusters.                           │
#> │           │              │ namcs2019sv = survey::svydesign(ids = ~CPSUM,  │
#> │           │              │ strata = ~CSTRATM, weights = ~PATWT            │
#> │           │              │ , data = namcs2019sv_df)                       │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#> 

## Age-adjusted estimation
set_survey(nhis2024a, aa_vr = "age_group_std", aa_pop = uspop_example$age_group_std)
#> * Producing age-adjusted estimates.
#>                                  Survey info {NHIS 2024 PUF (Adults)}                                 
#> ┌───────────┬──────────────┬────────────────────────────────────┬────────────────────────────────────┐
#> │ Variables │ Observations │ Age adjustment                     │ Design                             │
#> ├───────────┼──────────────┼────────────────────────────────────┼────────────────────────────────────┤
#> │        16 │       32,577 │ Age-adjusted by age_group_std:     │ Stratified 1 - level Cluster       │
#> │           │              │ 18-44, 45-54, 55-64, 65-74, 75+    │ Sampling design (with replacement) │
#> │           │              │                                    │ With (662) clusters.               │
#> │           │              │                                    │ nhis2024a = svydesign(             │
#> │           │              │                                    │ data = nhis2024_df,                │
#> │           │              │                                    │ ids = ~ppsu,                       │
#> │           │              │                                    │ strata = ~pstrat,                  │
#> │           │              │                                    │ weights = ~wtfa_a,                 │
#> │           │              │                                    │ nest = TRUE                        │
#> │           │              │                                    │ )                                  │
#> └───────────┴──────────────┴────────────────────────────────────┴────────────────────────────────────┘
#>