Exploring Chi-Square Residuals and Cramér’s V

Companion to Chapter 21. This worksheet goes beyond significance testing into where an association comes from (standardized residuals) and how strong it is (Cramér’s V).

A Note on AI Tools

You may use AI assistants to help debug your R code. You may not use AI to generate your interpretations. Every write-up sentence must reflect your own reading of the output. If you use AI for any part of this assignment, note where at the end.

Getting Standardized Residuals

library(vcd)
data(HairEyeColor)
HairEyeColor_df <- as.data.frame(HairEyeColor)
contingency_table <- xtabs(Freq ~ Hair + Eye, data = HairEyeColor_df)
test <- chisq.test(contingency_table)
test
round(test$stdres, 2)

How to Interpret Standardized Residuals

Verified: independently recomputed in Python against the real HairEyeColor dataset (χ²(9, N = 592) = 138.29, p < .001, Cramér’s V = .28) — all four values below match exactly.

From the example output:

These high residuals help explain which cells are driving the overall chi-square result.

Understanding Cramér’s V

Cramér’s V measures the strength of association between two categorical variables, ranging from 0 to 1: .1 = small, .3 = moderate, .5 = large. (These conventions apply for small tables; cutoffs are smaller for larger tables with more df.)

Always report Cramér’s V for a test of independence, alongside χ² and p — regardless of significance. V tells you the size of the relationship; the p-value only tells you whether it’s detectable.

install.packages("vcd")  # once
library(vcd)
assocstats(contingency_table)

This outputs the chi-square test result, Cramér’s V, and a warning if expected counts are too low.

Simulated P-Values for Small Expected Counts

When expected counts are small, chisq.test()’s usual approximation becomes unreliable. You can simulate the p-value instead:

data <- matrix(c(1, 9, 11, 3), nrow = 2)
chisq.test(data, simulate.p.value = TRUE)

This uses random resampling (2,000 iterations by default) for a more accurate p-value when the standard chi-square approximation is shaky. Also worth knowing about for this situation: Fisher’s Exact Test, an alternative built specifically for small-count tables.

Practice

Using the Titanic or UCBAdmissions contingency table from chi-square-practice.md:

  1. Compute the standardized residuals. Which cell(s) deviate most from expected?
  2. Compute Cramér’s V. How strong is the association?
  3. Write one sentence connecting the residuals to the effect size: does the strength of the association (V) match what the residuals suggest about where the effect is concentrated?