Calculate the rates for categorical (factor) or logical variables.
Arguments
- vr
variable to tabulate
- pop
either a single number or a
data.frame
with columns namedLevel
andPopulation
.Level
must exactly match the levels ofvr
.Population
is the population for that level ofvr
.- 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
See also
Other tables:
tab()
,
tab_cross()
,
tab_subset_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) │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#>
# pop is a data frame
tab_rate("MSA", uspop2019$MSA)
#> Metropolitan Statistical Area Status of physician location (rate per 100 population) {NAMCS 2019 PUF}
#> ┌───────────────────────┬───────┬───────┬──────┬───────┬───────┐
#> │ Level │ n │ Rate │ SE │ LL │ UL │
#> ├───────────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ MSA (Metropolitan │ 7,496 │ 351.2 │ 18.2 │ 317.2 │ 388.8 │
#> │ Statistical Area) │ │ │ │ │ │
#> ├───────────────────────┼───────┼───────┼──────┼───────┼───────┤
#> │ Non-MSA │ 754 │ 136.7 │ 38.2 │ 78.9 │ 236.8 │
#> └───────────────────────┴───────┴───────┴──────┴───────┴───────┘
#> N = 8250.
#>
# pop is a single number
tab_rate("MDDO", uspop2019$total)
#> * Rate based on the entire population.
#> Type of doctor (MD or DO) (rate per 100 population) {NAMCS 2019 PUF}
#> ┌───────────────────────┬───────┬───────┬────┬───────┬───────┐
#> │ Level │ n │ Rate │ SE │ LL │ UL │
#> ├───────────────────────┼───────┼───────┼────┼───────┼───────┤
#> │ M.D. - Doctor of │ 7,498 │ 303.3 │ 15 │ 275.3 │ 334.1 │
#> │ Medicine │ │ │ │ │ │
#> ├───────────────────────┼───────┼───────┼────┼───────┼───────┤
#> │ D.O. - Doctor of │ 752 │ 17.4 │ 2 │ 13.8 │ 21.9 │
#> │ Osteopathy │ │ │ │ │ │
#> └───────────────────────┴───────┴───────┴────┴───────┴───────┘
#> N = 8250.
#>