Skip to contents

Tabulate categorical (factor), logical, or numeric variables.

Usage

tab(
  ...,
  test = FALSE,
  alpha = 0.05,
  p_adjust = FALSE,
  drop_na = getOption("surveytable.drop_na"),
  max_levels = getOption("surveytable.max_levels"),
  csv = getOption("surveytable.csv")
)

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 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

Value

A list of tables or a single table.

Details

For categorical and logical variables, presents the estimated counts, their standard errors (SEs) and confidence intervals (CIs), percentages, and their SEs and CIs. Checks the presentation guidelines for counts and percentages and flags estimates if, according to the guidelines, they should be suppressed, footnoted, or reviewed by an analyst.

For numeric variables, presents the percentage of observations with known values, the mean of known values, the standard error of the mean (SEM), and the standard deviation (SD).

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.

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.                           │
#> │           │              │ survey::svydesign(ids = ~CPSUM, strata =       │
#> │           │              │ ~CSTRATM, weights = ~PATWT,                    │
#> │           │              │ data = namcs2019sv_df)                         │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#> 
tab("AGER")
#>                                 Patient age recode {NAMCS 2019 PUF}                                 
#> ┌─────────────┬───────┬─────────────┬──────────┬──────────┬──────────┬─────────┬─────┬──────┬──────┐
#> │ Level       │     n │      Number │ SE (000) │ LL (000) │ UL (000) │ Percent │  SE │   LL │   UL │
#> │             │       │       (000) │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ Under 15    │   887 │     117,917 │   14,097 │   93,229 │  149,142 │    11.4 │ 1.3 │  8.9 │ 14.2 │
#> │ years       │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 15-24 years │   542 │      64,856 │    7,018 │   52,387 │   80,292 │     6.3 │ 0.6 │  5.1 │  7.5 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 25-44 years │ 1,435 │     170,271 │   13,966 │  144,925 │  200,049 │    16.4 │ 1.1 │ 14.3 │ 18.8 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 45-64 years │ 2,283 │     309,506 │   23,290 │  266,994 │  358,787 │    29.9 │ 1.4 │ 27.2 │ 32.6 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 65-74 years │ 1,661 │     206,866 │   14,366 │  180,481 │  237,109 │    20   │ 1.2 │ 17.6 │ 22.5 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 75 years    │ 1,442 │     167,069 │   15,179 │  139,746 │  199,735 │    16.1 │ 1.3 │ 13.7 │ 18.8 │
#> │ and over    │       │             │          │          │          │         │     │      │      │
#> └─────────────┴───────┴─────────────┴──────────┴──────────┴──────────┴─────────┴─────┴──────┴──────┘
#>   N = 8250. Checked NCHS presentation standards. Nothing to report.                                 
#> 
tab("MDDO", "SPECCAT", "MSA")
#>                              Type of doctor (MD or DO) {NAMCS 2019 PUF}                              
#> ┌─────────────┬───────┬─────────────┬──────────┬──────────┬───────────┬─────────┬─────┬──────┬──────┐
#> │ Level       │     n │      Number │ SE (000) │ LL (000) │  UL (000) │ Percent │  SE │   LL │   UL │
#> │             │       │       (000) │          │          │           │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼───────────┼─────────┼─────┼──────┼──────┤
#> │ M.D. -      │ 7,498 │     980,280 │   48,388 │  889,842 │ 1,079,910 │    94.6 │ 0.7 │ 93.1 │ 95.8 │
#> │ Doctor of   │       │             │          │          │           │         │     │      │      │
#> │ Medicine    │       │             │          │          │           │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼───────────┼─────────┼─────┼──────┼──────┤
#> │ D.O. -      │   752 │      56,204 │    6,602 │   44,597 │    70,832 │     5.4 │ 0.7 │  4.2 │  6.9 │
#> │ Doctor of   │       │             │          │          │           │         │     │      │      │
#> │ Osteopathy  │       │             │          │          │           │         │     │      │      │
#> └─────────────┴───────┴─────────────┴──────────┴──────────┴───────────┴─────────┴─────┴──────┴──────┘
#>   N = 8250. Checked NCHS presentation standards. Nothing to report.                                  
#> 
#>                   Type of specialty (Primary, Medical, Surgical) {NAMCS 2019 PUF}                   
#> ┌─────────────┬───────┬─────────────┬──────────┬──────────┬──────────┬─────────┬─────┬──────┬──────┐
#> │ Level       │     n │      Number │ SE (000) │ LL (000) │ UL (000) │ Percent │  SE │   LL │   UL │
#> │             │       │       (000) │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ Primary     │ 2,993 │     521,466 │   31,136 │  463,840 │  586,252 │    50.3 │ 2.6 │ 45.1 │ 55.5 │
#> │ care        │       │             │          │          │          │         │     │      │      │
#> │ specialty   │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ Surgical    │ 3,050 │     214,832 │   31,110 │  161,661 │  285,490 │    20.7 │ 3   │ 15.1 │ 27.3 │
#> │ care        │       │             │          │          │          │         │     │      │      │
#> │ specialty   │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ Medical     │ 2,207 │     300,186 │   43,497 │  225,806 │  399,067 │    29   │ 3.6 │ 22.1 │ 36.6 │
#> │ care        │       │             │          │          │          │         │     │      │      │
#> │ specialty   │       │             │          │          │          │         │     │      │      │
#> └─────────────┴───────┴─────────────┴──────────┴──────────┴──────────┴─────────┴─────┴──────┴──────┘
#>   N = 8250. Checked NCHS presentation standards. Nothing to report.                                 
#> 
#>              Metropolitan Statistical Area Status of physician location {NAMCS 2019 PUF}             
#> ┌─────────────┬───────┬─────────────┬──────────┬──────────┬───────────┬─────────┬─────┬──────┬──────┐
#> │ Level       │     n │      Number │ SE (000) │ LL (000) │  UL (000) │ Percent │  SE │   LL │   UL │
#> │             │       │       (000) │          │          │           │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼───────────┼─────────┼─────┼──────┼──────┤
#> │ MSA         │ 7,496 │     973,676 │   50,515 │  879,490 │ 1,077,947 │    93.9 │ 1.7 │ 89.7 │ 96.8 │
#> │ (Metropolit │       │             │          │          │           │         │     │      │      │
#> │ an          │       │             │          │          │           │         │     │      │      │
#> │ Statistical │       │             │          │          │           │         │     │      │      │
#> │ Area)       │       │             │          │          │           │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼───────────┼─────────┼─────┼──────┼──────┤
#> │ Non-MSA     │   754 │      62,809 │   17,549 │   36,249 │   108,830 │     6.1 │ 1.7 │  3.2 │ 10.3 │
#> └─────────────┴───────┴─────────────┴──────────┴──────────┴───────────┴─────────┴─────┴──────┴──────┘
#>   N = 8250. Checked NCHS presentation standards. Nothing to report.                                  
#> 

# Numeric variables
tab("NUMMED")
#> Number of medications coded {NAMCS 2019 PUF}
#> ┌─────────┬──────┬───────┬──────┐
#> │ % known │ Mean │   SEM │   SD │
#> ├─────────┼──────┼───────┼──────┤
#> │     100 │ 3.46 │ 0.268 │ 4.43 │
#> └─────────┴──────┴───────┴──────┘
#> 

# Hypothesis testing with categorical variables
tab("AGER", test = TRUE)
#>                                 Patient age recode {NAMCS 2019 PUF}                                 
#> ┌─────────────┬───────┬─────────────┬──────────┬──────────┬──────────┬─────────┬─────┬──────┬──────┐
#> │ Level       │     n │      Number │ SE (000) │ LL (000) │ UL (000) │ Percent │  SE │   LL │   UL │
#> │             │       │       (000) │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ Under 15    │   887 │     117,917 │   14,097 │   93,229 │  149,142 │    11.4 │ 1.3 │  8.9 │ 14.2 │
#> │ years       │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 15-24 years │   542 │      64,856 │    7,018 │   52,387 │   80,292 │     6.3 │ 0.6 │  5.1 │  7.5 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 25-44 years │ 1,435 │     170,271 │   13,966 │  144,925 │  200,049 │    16.4 │ 1.1 │ 14.3 │ 18.8 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 45-64 years │ 2,283 │     309,506 │   23,290 │  266,994 │  358,787 │    29.9 │ 1.4 │ 27.2 │ 32.6 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 65-74 years │ 1,661 │     206,866 │   14,366 │  180,481 │  237,109 │    20   │ 1.2 │ 17.6 │ 22.5 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 75 years    │ 1,442 │     167,069 │   15,179 │  139,746 │  199,735 │    16.1 │ 1.3 │ 13.7 │ 18.8 │
#> │ and over    │       │             │          │          │          │         │     │      │      │
#> └─────────────┴───────┴─────────────┴──────────┴──────────┴──────────┴─────────┴─────┴──────┴──────┘
#>   N = 8250. Checked NCHS presentation standards. Nothing to report.                                 
#> 
#> Comparison of all possible pairs of Patient age recode {NAMCS 2019 PUF}
#> ┌────────────────┬───────────────────┬─────────┬──────┐
#> │ Level 1        │ Level 2           │ p-value │ Flag │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ Under 15 years │ 15-24 years       │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ Under 15 years │ 25-44 years       │   0.012 │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ Under 15 years │ 45-64 years       │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ Under 15 years │ 65-74 years       │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ Under 15 years │ 75 years and over │   0.022 │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 15-24 years    │ 25-44 years       │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 15-24 years    │ 45-64 years       │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 15-24 years    │ 65-74 years       │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 15-24 years    │ 75 years and over │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 25-44 years    │ 45-64 years       │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 25-44 years    │ 65-74 years       │   0.065 │      │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 25-44 years    │ 75 years and over │   0.878 │      │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 45-64 years    │ 65-74 years       │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 45-64 years    │ 75 years and over │   0     │ *    │
#> ├────────────────┼───────────────────┼─────────┼──────┤
#> │ 65-74 years    │ 75 years and over │   0.019 │ *    │
#> └────────────────┴───────────────────┴─────────┴──────┘
#>   Design-based t-test. *: p <= 0.05                    
#>