Skip to main content

Section 6.13 Key Functions & Commands

The following functions and commands are introduced or reinforced in this chapter to support categorical data analysis, contingency tables, and Chi-Square testing.
  • table() (base R)
    • Creates basic contingency (frequency) tables for categorical variables.
  • xtabs() (base R)
    • Constructs contingency tables using a formula interface, useful for multi-way tables.
  • tabyl() (janitor)
    • Generates clean contingency tables that integrate easily with percentage calculations.
  • adorn_percentages() (janitor)
    • Converts contingency table counts into row- or column-based percentages.
  • adorn_ns() (janitor)
    • Displays counts and percentages together for clearer interpretation.
  • chisq.test() (stats)
    • Performs a Chi-Square test of independence to assess whether two categorical variables are related.
  • CrossTable() (gmodels)
    • Produces detailed cross-tabulations including expected counts, proportions, and chi-square contributions.
  • pheatmap() (pheatmap)
    • Visualizes Chi-Square contributions or residuals using a heatmap.
  • cramerV() (rcompanion)
    • Computes Cramer’s V to measure the strength of association between categorical variables.