Understand the idea
Cross-tabulate two categorical variables (say, penguin species against island) and you get a grid of counts, one cell per combination. This test asks: does that grid of counts look like what you'd expect if species and island had NOTHING to do with each other (each cell's count purely proportional to its row and column totals), or does it look meaningfully different from that independence pattern?
A large test statistic means the actual table departs substantially from the pattern independence would predict: some combinations show up far more (or less) often than chance alone would produce, which is the signature of a real association between the two variables. The test tells you THAT an association likely exists, not what DIRECTION or shape that association takes; for that, you'd look at the actual table of counts.
Cramer's V measures how STRONG that association is, on a 0-to-1 scale. Here's a subtlety worth knowing: the conventional 'small/medium/large' benchmarks for V (0.10/0.30/0.50) only apply directly to a table where the smaller of (rows, columns) minus 1 equals exactly 1, essentially a 2-by-anything table. For a bigger table (say 3 rows by 3 columns), the card lowers these heuristic cut-points using a degrees-of-freedom convention: the same numeric V can earn a stronger verbal label in a bigger table than it would in a 2-by-2 table.
The Pearson chi-square test of independence is the standard contingency table test. The Yates correction is a small adjustment for 2x2 tables that makes the test more cautious, often more cautious than it needs to be.
Practitioner explanation
KernelStats computes chi2 = sum((O_ij-E_ij)^2/E_ij) with E_ij = R_i*C_j/N, df = (r-1)(c-1), via scipy.stats.chi2_contingency. Cramer's V = sqrt(chi2/(N*(min(r,c)-1))) is reported as the RAW numeric value UNCHANGED regardless of table size, but the verbal label (small/medium/large) is chosen using df* = min(r,c)-1 -ADJUSTED thresholds (Cohen's w benchmarks divided by sqrt(df*): 0.10/0.30/0.50 at df*=1, about 0.07/0.21/0.35 at df*=2 (a 3x3 table), about 0.06/0.17/0.29 at df*=3), a deliberate, stated departure from blindly applying the familiar 2x2 benchmarks to every table size, so a V of 0.30 is labeled 'medium' on a 2x2 or 3x3 table but 'large' on a 4x4 table.
Yates' continuity correction is applied by DEFAULT for 2x2 tables ONLY (subtracting at most 0.5 from each |O-E|, clamped at zero before squaring, making the continuous chi-square distribution a better approximation to genuinely discrete counts, at the cost of being slightly conservative) and is automatically SKIPPED for any larger table, where it does not apply. The expected-counts assumption check uses Cochran's rule specifically (no more than 20% of cells below expected count 5, and none below 1) rather than the simpler 'all cells >= 5' rule sometimes quoted, a materially less strict, and more standard, threshold that the goodness-of-fit test's simpler all-cells check does not share.
Choose the test for the scientific question and sampling unit. Small expected counts in a 2x2 table can call for Fisher's exact test; sparse larger tables may need a suitable exact or Monte Carlo procedure or substantively justified category combination. With one independent subject contributing one joint (before, after) outcome to a single cell, Pearson's test can assess association between the two measurements. It does not test whether their marginal probabilities changed. For marginal change in paired binary outcomes, use McNemar's test. Stacking repeated responses as if they came from independent subjects violates the ordinary independence sampling model.
When to use it
Consider it when
You have two categorical variables (each with 2+ levels), independent observations (each subject contributes to exactly one cell), and want to detect any association between them.
Use caution when
You want to test marginal change in paired binary outcomes (use McNemar's test), repeated or clustered responses have been stacked as independent sampling units, expected counts are too low in a 2x2 table (consider Fisher's exact test), or a larger table is too sparse for the chi-square approximation (consider a suitable exact or Monte Carlo procedure). A joint before/after table with one independent subject per cell contribution can still be analyzed for association; that is a different question from change.
Formulas and symbols
Pearson chi-square statistic for independence
E_ij = R_i*C_j/N from the row total R_i, column total C_j, and grand total N; df = (r-1)(c-1).
Cramer's V (effect size)
Ranges 0 (no association) to 1 (perfect association). Cohen's benchmarks depend on df* = min(r,c)-1 and shrink for larger tables.
Yates' continuity correction (2x2 tables only)
For 2x2 tables with positive expected counts, move each observed count toward its expectation by at most 0.5, never past it. Applied by default only to 2x2 tables and skipped for larger tables; this is an approximation correction, not an exact test.
Assumptions and checks
- Adequate expected counts (chi-square). When too many cells have an expected count below 5, the chi-square distribution is a poor approximation to the test statistic's true sampling distribution, making the p-value unreliable.
In KernelStats: Checked directly: the card computes the minimum expected cell count and the share of cells below 5, flagging it as a warning and recommending an exact test (Fisher's) or combining sparse categories.
- Independence of observations. The subject-level sampling units must be independent for the ordinary Pearson reference distribution. Each unit contributes once to a joint cell. The two variables within that unit may be associated: their independence is the null hypothesis being tested, not an assumption required for running the test. Stacking repeated responses or correlated clusters as if they were independent units requires a different analysis.
In KernelStats: Not checked by KernelStats: assumed by design; stated directly as a standing reminder.
Alternatives
- McNemar's Test. You want to test whether the marginal probability of a binary outcome changed between two paired conditions on independent subjects. McNemar tests the balance of discordant pairs; it does not test before/after association.
- Chi-Square Goodness-of-Fit Test. You have only ONE categorical variable and want to test whether its categories are equally frequent (the goodness-of-fit card tests equal expected frequencies by default, or the expected shares you type in its Expected shares box), rather than testing association between two variables.
Worked example
Scenario
Testing whether penguin species is associated with the island it was observed on, across all 344 penguins in a 3x3 contingency table.
Result
chi2(4) = 299.6, p < .001, Cramer's V = 0.66, labeled 'large' using the df*=2-adjusted thresholds.
Interpretation
Species and island are very strongly associated: certain species are found overwhelmingly on specific islands rather than being evenly distributed, and the large, table-size-adjusted Cramer's V confirms this is a substantial, not merely statistically detectable, association.
Dataset: penguins.csv
Common misconceptions
Misconception
A Cramer's V of 0.30 always represents the same strength of association ('medium'), regardless of the size of the contingency table.
Correction
Cohen's small/medium/large benchmarks for Cramer's V depend on the table's smaller degrees of freedom, df* = min(rows, columns) - 1. The familiar 0.10/0.30/0.50 cut-points apply only when df*=1 (essentially a 2xk table); for a larger table the thresholds SHRINK (to 0.10, 0.30 and 0.50 divided by the square root of df*), so the same numeric V corresponds to a larger Cohen's w and earns a stronger label: a V of 0.30 that is 'medium' on a 2x2 table (large threshold 0.50) sits much closer to 'large' on a 3x3 table (large threshold about 0.35) and is 'large' on a 4x4 table (about 0.29).
Misconception
A chi-square association test on a before/after joint table tells me whether the marginal proportion changed.
Correction
A joint table can contain one independent person's paired outcomes in one cell, so its observations can satisfy the sampling-independence requirement. Pearson's test asks whether the before and after variables are associated; it does not ask whether their marginal probabilities differ. McNemar's test addresses marginal change for paired binary outcomes by comparing the discordant counts. Treating separately stacked repeated responses as independent people is a different, invalid sampling assumption.
Misconception
The chi-square test of independence works fine for before/after data on the same subjects, since it's still just two categorical variables.
Correction
It depends on what you ask and how the table is built. If each subject appears once, in the cell for their (before, after) pair, the chi-square test is valid but answers whether before and after are associated, not whether the proportion changed; for change, use McNemar's test. If the before and after answers are stacked as separate rows as if they came from different people, the chi-square test is invalid.
References
- NIST Dataplot Reference Manual: CHI-SQUARE INDEPENDENCE TEST, NIST/SEMATECH (2012), Description and Test Statistic.
- Statistical Power Analysis for the Behavioral Sciences, Cohen, J. (1988).
- R stats documentation: Pearson's Chi-squared Test for Count Data (chisq.test), R Core Team, Arguments: correct.
