liveBook · Manning

Chi-square test

As explained in Statistics Slam Dunk

A chi-square test is a statistical test based on a chi-square-distributed statistic for assessing categorical-data relationships or distributional differences.

A chi-square test for independence asks whether two categorical variables have a meaningful relationship. It starts from a null hypothesis that the variables are independent: knowing one does not help predict the other. Compare the test’s p-value with a chosen significance threshold, commonly 0.05; a p-value at or below that threshold leads to rejecting the null hypothesis. section 9.6 section 20.2

Use it when the dependent variable is categorical rather than numeric. In an NBA rest analysis, the question is whether the competing teams’ prior days off are related to wins and losses. This frames rest categories and game outcomes as a testable relationship rather than a difference to inspect only visually. section 9.0 section 1.3

A practical workflow is:

  • State a null hypothesis of no meaningful relationship between the categorical variables. section 9.6
  • Create a contingency table containing the category counts to compare. section 9.6.2
  • Run base R’s chisq.test() on that table. section 9.6.2
  • Interpret the p-value against the predefined threshold, rejecting or failing to reject the null hypothesis. section 9.6.2 section 20.2

Does rest relate to winning?

Build a contingency table for permutations of home- and road-team days off and game outcomes. Running chisq.test(chisq_table) produces a chi-squared statistic, degrees of freedom, and p-value. A p-value far below 0.05 supports rejecting the independence null hypothesis and treating rest as statistically related to wins and losses. section 9.6.2 section 9.0

options(scipen = 999)

test <- chisq.test(chisq_table)
test
## 
##  Pearson's Chi-squared test
## 
## data:  chisq_table
## X-squared = 400.5, df = 2, p-value < 0.00000000000000022

Inspect the R call and its output to see the minimal input—a contingency table—and the returned chi-squared statistic, degrees of freedom, and p-value. section 9.6.2

How Statistics Slam Dunk covers it

How deep it goes
Defines independence hypotheses and p-value decisions, then demonstrates running chisq.test() on a contingency table.
Examples
Uses NBA days off versus wins and losses, survey sentiment versus marital status, political beliefs, and restaurant customer counts.
What it assumes
Introduces categorical dependent variables, null hypotheses, p-values, and a 0.05 significance threshold before testing.
What you can do after
Apply it via base R’s chisq.test() to assess categorical relationships from a contingency table.
How it connects
Connects chi-square testing with t-tests, contingency tables, p-values, null hypotheses, and Cramer’s V.

Also explained in

Compare how 3 books explain chi-square test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.