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


