Skip to contents

Create subsets of the survey using one variable, and tabulate the rates of another variable within each of the subsets.

Usage

tab_subset_rate(
  vr,
  vrby,
  pop,
  lvls = c(),
  per = getOption("surveytable.rate_per"),
  drop_na = getOption("surveytable.drop_na"),
  max_levels = getOption("surveytable.max_levels"),
  csv = getOption("surveytable.csv")
)

Arguments

vr

variable to tabulate

vrby

use this variable to subset the survey

pop

a data.frame with columns named Level, Subset, and Population. Level must exactly match the levels of vr. Subset must exactly match the levels of vrby. Population is the population for that level of vr and vrby.

lvls

(optional) only show these levels of vrby

per

calculate rate per this many items in the population

drop_na

drop missing values (NA)?

max_levels

a categorical variable can have at most this many levels. Used to avoid printing huge tables.

csv

name of a CSV file

Value

A list of tables or a single table.

See also

Other tables: tab(), tab_cross(), tab_rate(), total(), total_rate()

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)                       │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#> 
tab_subset_rate("AGER", "SEX", uspop2019$`AGER x SEX`)
#> Patient age recode (Patient sex = Female) (rate per 100 population) {NAMCS 2019 PUF}
#> ┌───────────────────┬───────┬───────┬──────┬───────┬───────┐
#> │ Level             │     n │  Rate │   SE │    LL │    UL │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ Under 15 years    │   434 │ 202.5 │ 24.3 │ 159.8 │ 256.6 │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 15-24 years       │   346 │ 198.4 │ 21.9 │ 159.5 │ 246.8 │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 25-44 years       │   923 │ 263.3 │ 26.5 │ 215.9 │ 321   │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 45-64 years       │ 1,253 │ 414   │ 37.7 │ 346.2 │ 495.1 │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 65-74 years       │   891 │ 720.3 │ 66.4 │ 600.8 │ 863.6 │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 75 years and over │   762 │ 758.1 │ 89.2 │ 601.2 │ 956   │
#> └───────────────────┴───────┴───────┴──────┴───────┴───────┘
#>   N = 4609.                                                 
#> 
#> Patient age recode (Patient sex = Male) (rate per 100 population) {NAMCS 2019 PUF}
#> ┌───────────────────┬───────┬───────┬──────┬───────┬───────┐
#> │ Level             │     n │  Rate │   SE │    LL │    UL │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ Under 15 years    │   453 │ 187.4 │ 25   │ 144.1 │ 243.7 │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 15-24 years       │   196 │ 113.1 │ 20.7 │  78.4 │ 163   │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 25-44 years       │   512 │ 133.4 │ 17.2 │ 103.4 │ 172   │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 45-64 years       │ 1,030 │ 333.4 │ 32.3 │ 275.4 │ 403.5 │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 65-74 years       │   770 │ 594.8 │ 46.4 │ 510.1 │ 693.6 │
#> ├───────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ 75 years and over │   680 │ 801.2 │ 73.2 │ 669.1 │ 959.5 │
#> └───────────────────┴───────┴───────┴──────┴───────┴───────┘
#>   N = 3641.                                                 
#>