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().
Arguments
- design
a survey object, created with
survey::svydesign()orsurvey::svrepdesign(). For an unweighted survey, adata.frameor 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.framewith columns namedLevelandPopulation.Levelmust exactly match the levels ofaa_vr.Populationis the population count or proportion/weight for that level ofaa_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.
See also
Other options:
set_opts(),
show_options(),
surveytable-options
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 │
#> │ │ │ │ ) │
#> └───────────┴──────────────┴────────────────────────────────────┴────────────────────────────────────┘
#>