12. Chi-square tests and categorical association

Learning goals

You will learn to:

  • build a contingency table;
  • compare counts and row percentages;
  • use the chi-square test of independence;
  • inspect expected cell counts;
  • distinguish association from direction, magnitude, and causality.

Management question: Is managerial status associated with department, or is the observed distribution compatible with independence?

library(tidyverse)

employees <- read_csv(
  "data/employee_survey.csv",
  show_col_types = FALSE
)

manager_department <- table(
  employees$manager,
  employees$department
)

manager_department
     
      Finance HR Marketing Operations Technology
  No       70 41        70         97         67
  Yes      27 13        30         28         37
prop.table(manager_department, margin = 1)
     
        Finance        HR Marketing Operations Technology
  No  0.2028986 0.1188406 0.2028986  0.2811594  0.1942029
  Yes 0.2000000 0.0962963 0.2222222  0.2074074  0.2740741

Run the test:

chi_result <- chisq.test(manager_department)

chi_result

    Pearson's Chi-squared test

data:  manager_department
X-squared = 5.4999, df = 4, p-value = 0.2397
chi_result$expected
     
       Finance      HR Marketing Operations Technology
  No  69.71875 38.8125    71.875   89.84375      74.75
  Yes 27.28125 15.1875    28.125   35.15625      29.25

The chi-square test compares observed counts with the counts expected if the two categorical variables were independent.

A statistically detectable chi-square association does not tell you the mechanism, direction of causality, or managerial importance. Examine the pattern of percentages and, when appropriate, an effect size such as Cramér’s V.

Optional effect size:

effectsize::cramers_v(manager_department)
Cramer's V (adj.) |       95% CI
--------------------------------
0.06              | [0.00, 1.00]

- One-sided CIs: upper bound fixed at [1.00].

Practice

  1. Test manager by department.
  2. Report row percentages.
  3. Inspect expected counts.
  4. Calculate Cramér’s V.
  5. Write one sentence describing association without causal language.

Takeaway

For categorical variables, start with counts and proportions. The chi-square statistic is one part of the substantive interpretation.