Learn R Programming

surveytable (version 0.9.9)

tab: Tabulate variables

Description

Tabulate categorical (factor or character), 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")
)

Value

A list of tables or a single table.

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.

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 and UL); and

  • the estimated percentage (Percent), with its standard error (SE) and confidence interval (LL and UL).

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 and UL); and

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

Run this code
set_survey(namcs2019sv)
tab("AGER")
tab("MDDO", "SPECCAT", "MSA")

# Numeric variables
tab("NUMMED")

# Hypothesis testing with categorical variables
tab("AGER", test = TRUE)

Run the code above in your browser using DataLab