How to run a chi-square test
- Copy two categorical columns, or category columns and a frequency (count) column, together with the header.
- Choose the data input and select the columns. For a 2×2 table you can turn on the Yates continuity correction.
- Press Analyze and check the p-value, Cramér's V and the cell contributions in the test summary.
Worked example with sample data
The sample data count raw material lots from 3 suppliers (Supplier A, B, C) by quality grade (Grade 1 to 3) (Supplier, Grade, Lots). Set the data input to 'row and column category columns + frequency column' and use the Lots column as the frequency column.
The test summary shows χ²=15.59 (4 degrees of freedom) and a p-value of 0.003628, so supplier and quality grade are related. With Cramér's V=0.1802, however, the association is 'weak'.
The largest cell contributions are (Supplier A, Grade 3) 4.36 and (Supplier A, Grade 1) 4.265. Supplier A has 48 lots of Grade 1, more than expected (35.67), and 5 lots of Grade 3, fewer than expected (12.33), so its material is generally of better grade.
In the standardized residual heatmap, only these two cells exceed 2 in absolute value (2.07 and -2.09). Supplier B has a relatively high share of Grade 3 (18 lots, contribution 2.604), so it is worth checking whether Grade 3 material concentrates there.
How it is calculated
The expected count is row total × column total / grand total, and χ² = Σ(observed - expected)² / expected is tested against the chi-square distribution with (rows - 1)(columns - 1) degrees of freedom (the same as SciPy's chi2_contingency).
The Yates correction is applied only to 2×2 tables, which have 1 degree of freedom.
Cramér's V
Cramér's V = √(χ² / (N × (min(rows, columns) - 1))) and lies between 0 and 1. Using 0.1, 0.3, 0.5 and 0.7 as boundaries, it is read as almost none, weak, moderate, strong and very strong.
What the result shows
Observed counts, expected counts, χ² contributions by cell and test summary tables, plus a mosaic plot, a standardized residual heatmap and a 100% stacked bar.
How to read the chi-square test result
- If the p-value is below the significance level, the two variables are related (not independent).
- Cells with a large χ² contribution are the combinations behind the association. Check the sign of the standardized residual to see whether there are more or fewer than expected.
- If many cells have an expected count below 5, the approximation may be inaccurate; for a 2×2 table, use Fisher's exact test.
Frequently asked questions
Is it the same as Excel CHISQ.TEST?
Yes. It gives the same p-value as CHISQ.TEST(observed, expected) with the observed and expected count tables (with the Yates correction off).
Can I use a pre-counted frequency table?
Yes. Choose 'row and column category columns + frequency column' to use the count of each cell as it is.
Should I turn on the Yates correction?
Turn it on for a more conservative result on a 2×2 table. It is not applied to tables larger than 2×2.