Tabulate categorical (factor or character), logical, or numeric variables.
Arguments
- ...
names of variables (in quotes)
- test
perform hypothesis tests?
- alpha
significance level for tests
- p_adjust
adjust p-values for multiple comparisons?
- drop_na
drop missing values (
NA
)? Categorical or logical variables only.- max_levels
a categorical variable can have at most this many levels. Used to avoid printing huge tables.
- csv
name of a CSV file
Details
For categorical and logical variables, for each category, this function presents the following:
the number of observations (
n
);the estimated count (
Number
), with its standard error (SE
) and confidence interval (LL
andUL
); andthe estimated percentage (
Percent
), with its standard error (SE
) and confidence interval (LL
andUL
).
Optionally, this function identifies low-precision estimates and flags
them if, according to the guidelines (such as the NCHS presentation standards), they should
be suppressed, footnoted, or reviewed by an analyst. To enable this functionality,
see set_opts()
with arguments lpe = TRUE
or mode = "NCHS"
.
For numeric variables, this function presents the following:
percentage of observations with known values (
% known
);the mean of known values (
Mean
), with its standard error (SEM
) and confidence interval (LL
andUL
); andthe standard deviation (
SD
).
Confidence intervals (CIs) are calculated at the 95% confidence level. CIs for
count estimates are the log Student's t CIs, with adaptations
for complex surveys. CIs for percentage estimates are
the Korn and Graubard CIs, with optional adjustments. See set_opts()
argument
adj
. CIs for estimates of means are the Wald CIs.
See also
Other tables:
tab_cross()
,
tab_rate()
,
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) │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#>
tab("AGER")
#> Patient age recode {NAMCS 2019 PUF}
#> ┌─────────────┬───────┬─────────────┬────────────┬─────────────┬─────────────┬─────────┬─────┬──────┬──────┐
#> │ Level │ n │ Number │ SE │ LL │ UL │ Percent │ SE │ LL │ UL │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ Under 15 │ 887 │ 117,916,772 │ 14,097,315 │ 93,228,928 │ 149,142,177 │ 11.4 │ 1.3 │ 8.9 │ 14.2 │
#> │ years │ │ │ │ │ │ │ │ │ │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 15-24 years │ 542 │ 64,855,698 │ 7,018,359 │ 52,386,950 │ 80,292,164 │ 6.3 │ 0.6 │ 5.1 │ 7.5 │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 25-44 years │ 1,435 │ 170,270,604 │ 13,965,978 │ 144,924,545 │ 200,049,472 │ 16.4 │ 1.1 │ 14.3 │ 18.8 │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 45-64 years │ 2,283 │ 309,505,956 │ 23,289,827 │ 266,994,092 │ 358,786,727 │ 29.9 │ 1.4 │ 27.2 │ 32.6 │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 65-74 years │ 1,661 │ 206,865,982 │ 14,365,993 │ 180,480,708 │ 237,108,637 │ 20 │ 1.2 │ 17.6 │ 22.5 │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 75 years │ 1,442 │ 167,069,344 │ 15,179,082 │ 139,746,193 │ 199,734,713 │ 16.1 │ 1.3 │ 13.7 │ 18.8 │
#> │ and over │ │ │ │ │ │ │ │ │ │
#> └─────────────┴───────┴─────────────┴────────────┴─────────────┴─────────────┴─────────┴─────┴──────┴──────┘
#> N = 8250.
#>
tab("MDDO", "SPECCAT", "MSA")
#> Type of doctor (MD or DO) {NAMCS 2019 PUF}
#> ┌─────────────┬───────┬─────────────┬────────────┬─────────────┬─────────────┬─────────┬─────┬──────┬──────┐
#> │ Level │ n │ Number │ SE │ LL │ UL │ Percent │ SE │ LL │ UL │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ M.D. - │ 7,498 │ 980,280,219 │ 48,387,921 │ 889,841,831 │ 1,079,910,2 │ 94.6 │ 0.7 │ 93.1 │ 95.8 │
#> │ Doctor of │ │ │ │ │ 43 │ │ │ │ │
#> │ Medicine │ │ │ │ │ │ │ │ │ │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ D.O. - │ 752 │ 56,204,137 │ 6,601,909 │ 44,596,891 │ 70,832,404 │ 5.4 │ 0.7 │ 4.2 │ 6.9 │
#> │ Doctor of │ │ │ │ │ │ │ │ │ │
#> │ Osteopathy │ │ │ │ │ │ │ │ │ │
#> └─────────────┴───────┴─────────────┴────────────┴─────────────┴─────────────┴─────────┴─────┴──────┴──────┘
#> N = 8250.
#>
#> Type of specialty (Primary, Medical, Surgical) {NAMCS 2019 PUF}
#> ┌─────────────┬───────┬─────────────┬────────────┬─────────────┬─────────────┬─────────┬─────┬──────┬──────┐
#> │ Level │ n │ Number │ SE │ LL │ UL │ Percent │ SE │ LL │ UL │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ Primary │ 2,993 │ 521,466,378 │ 31,136,212 │ 463,840,192 │ 586,251,877 │ 50.3 │ 2.6 │ 45.1 │ 55.5 │
#> │ care │ │ │ │ │ │ │ │ │ │
#> │ specialty │ │ │ │ │ │ │ │ │ │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ Surgical │ 3,050 │ 214,831,829 │ 31,110,335 │ 161,661,415 │ 285,489,984 │ 20.7 │ 3 │ 15.1 │ 27.3 │
#> │ care │ │ │ │ │ │ │ │ │ │
#> │ specialty │ │ │ │ │ │ │ │ │ │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ Medical │ 2,207 │ 300,186,150 │ 43,496,739 │ 225,806,019 │ 399,066,973 │ 29 │ 3.6 │ 22.1 │ 36.6 │
#> │ care │ │ │ │ │ │ │ │ │ │
#> │ specialty │ │ │ │ │ │ │ │ │ │
#> └─────────────┴───────┴─────────────┴────────────┴─────────────┴─────────────┴─────────┴─────┴──────┴──────┘
#> N = 8250.
#>
#> Metropolitan Statistical Area Status of physician location {NAMCS 2019 PUF}
#> ┌─────────────┬───────┬─────────────┬────────────┬─────────────┬─────────────┬─────────┬─────┬──────┬──────┐
#> │ Level │ n │ Number │ SE │ LL │ UL │ Percent │ SE │ LL │ UL │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ MSA │ 7,496 │ 973,675,566 │ 50,514,928 │ 879,490,192 │ 1,077,947,3 │ 93.9 │ 1.7 │ 89.6 │ 96.8 │
#> │ (Metropolit │ │ │ │ │ 34 │ │ │ │ │
#> │ an │ │ │ │ │ │ │ │ │ │
#> │ Statistical │ │ │ │ │ │ │ │ │ │
#> │ Area) │ │ │ │ │ │ │ │ │ │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ Non-MSA │ 754 │ 62,808,790 │ 17,549,184 │ 36,248,698 │ 108,829,955 │ 6.1 │ 1.7 │ 3.2 │ 10.4 │
#> └─────────────┴───────┴─────────────┴────────────┴─────────────┴─────────────┴─────────┴─────┴──────┴──────┘
#> N = 8250.
#>
# Numeric variables
tab("NUMMED")
#> Number of medications coded {NAMCS 2019 PUF}
#> ┌─────────┬──────┬───────┬──────┬──────┬──────┐
#> │ % known │ Mean │ SEM │ LL │ UL │ SD │
#> ├─────────┼──────┼───────┼──────┼──────┼──────┤
#> │ 100 │ 3.46 │ 0.268 │ 2.93 │ 3.98 │ 4.43 │
#> └─────────┴──────┴───────┴──────┴──────┴──────┘
#>
# Hypothesis testing with categorical variables
tab("AGER", test = TRUE)
#> Patient age recode {NAMCS 2019 PUF}
#> ┌─────────────┬───────┬─────────────┬────────────┬─────────────┬─────────────┬─────────┬─────┬──────┬──────┐
#> │ Level │ n │ Number │ SE │ LL │ UL │ Percent │ SE │ LL │ UL │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ Under 15 │ 887 │ 117,916,772 │ 14,097,315 │ 93,228,928 │ 149,142,177 │ 11.4 │ 1.3 │ 8.9 │ 14.2 │
#> │ years │ │ │ │ │ │ │ │ │ │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 15-24 years │ 542 │ 64,855,698 │ 7,018,359 │ 52,386,950 │ 80,292,164 │ 6.3 │ 0.6 │ 5.1 │ 7.5 │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 25-44 years │ 1,435 │ 170,270,604 │ 13,965,978 │ 144,924,545 │ 200,049,472 │ 16.4 │ 1.1 │ 14.3 │ 18.8 │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 45-64 years │ 2,283 │ 309,505,956 │ 23,289,827 │ 266,994,092 │ 358,786,727 │ 29.9 │ 1.4 │ 27.2 │ 32.6 │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 65-74 years │ 1,661 │ 206,865,982 │ 14,365,993 │ 180,480,708 │ 237,108,637 │ 20 │ 1.2 │ 17.6 │ 22.5 │
#> ├─────────────┼───────┼─────────────┼────────────┼─────────────┼─────────────┼─────────┼─────┼──────┼──────┤
#> │ 75 years │ 1,442 │ 167,069,344 │ 15,179,082 │ 139,746,193 │ 199,734,713 │ 16.1 │ 1.3 │ 13.7 │ 18.8 │
#> │ and over │ │ │ │ │ │ │ │ │ │
#> └─────────────┴───────┴─────────────┴────────────┴─────────────┴─────────────┴─────────┴─────┴──────┴──────┘
#> N = 8250.
#>
#> Comparison of all pairs of Patient age recode {NAMCS 2019 PUF}
#> ┌────────────────┬───────────────────┬────────────────┬────────────────────┬─────────┬──────┐
#> │ Level 1 │ Level 2 │ Test statistic │ Degrees of freedom │ p-value │ Flag │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ Under 15 years │ 15-24 years │ -4.89 │ 174 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ Under 15 years │ 25-44 years │ 2.52 │ 268 │ 0.012 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ Under 15 years │ 45-64 years │ 7.93 │ 316 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ Under 15 years │ 65-74 years │ 4.19 │ 295 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ Under 15 years │ 75 years and over │ 2.3 │ 270 │ 0.022 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 15-24 years │ 25-44 years │ 10.4 │ 269 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 15-24 years │ 45-64 years │ 22.5 │ 318 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 15-24 years │ 65-74 years │ 10.4 │ 311 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 15-24 years │ 75 years and over │ 7.41 │ 297 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 25-44 years │ 45-64 years │ 7.72 │ 298 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 25-44 years │ 65-74 years │ 1.85 │ 297 │ 0.065 │ │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 25-44 years │ 75 years and over │ -0.15 │ 291 │ 0.878 │ │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 45-64 years │ 65-74 years │ -4.64 │ 298 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 45-64 years │ 75 years and over │ -6.39 │ 292 │ 0 │ * │
#> ├────────────────┼───────────────────┼────────────────┼────────────────────┼─────────┼──────┤
#> │ 65-74 years │ 75 years and over │ -2.36 │ 281 │ 0.019 │ * │
#> └────────────────┴───────────────────┴────────────────┴────────────────────┴─────────┴──────┘
#> Design-based t-test. *: p <= 0.05
#>