A chi-square test answers one specific question. Do the counts observed across a set of categories differ from what independence, or a stated model, would predict? Karl Pearson introduced the test in 1900, and epidemiologists still run it every week to compare exposure rates across groups, screen genotype data for errors, and check whether disease onsets cluster by season rather than spreading evenly across the year. Competing guides on this topic tend to restate the formula and stop there. Here, two contingency tables get worked by hand, every number gets checked against independent statistical software, and the guide explains exactly when the chi-square approximation stops being trustworthy so Fisher’s exact test should take over instead.
Key Takeaways
- A chi-square test compares observed category counts against the counts expected under a null model, using the statistic χ² = Σ(O − E)² / E.
- The chi-square test of independence checks whether two categorical variables are related; the goodness-of-fit test checks whether one variable’s distribution matches a hypothesized pattern.
- Degrees of freedom for a contingency table equal (rows − 1) × (columns − 1); for goodness-of-fit they equal the number of categories minus 1, minus any parameters estimated from the data.
- Cochran’s 1954 guidance holds that no more than 20% of cells should have an expected count below 5, and no cell should fall below 1. Cross that line and Fisher’s exact test becomes the safer choice.
- A significant chi-square result shows an association exists. Strength is a separate question, answered with an odds ratio, relative risk, or Cramér’s V, not the p-value alone.
In Simple Words
Picture two groups of patients, one treated and one not, with a yes or no outcome such as recovered. A chi-square test asks whether recovery looks the same in both groups or genuinely different. It builds a small table of counts, works out what those counts would look like if treatment made no difference at all, and measures how far the real counts stray from that no-difference picture. A wide gap between real and expected counts produces a small p-value and points toward a real link between treatment and outcome. A narrow gap means the pattern on the page is plausibly just chance.
Two guardrails matter before trusting the result. Every category needs to be genuinely separate, since the same patient cannot count twice, and the expected count in most cells needs to reach at least 5. Small samples need Fisher’s exact test instead, covered later in this guide.
What Is a Chi-Square Test?
Statisticians group chi-square procedures into a family that shares one trait. Each test statistic follows a chi-square distribution when the null hypothesis is true and the sample size is adequate. Two members of that family cover almost every use case a researcher meets in practice. A chi-square test of independence takes two categorical variables measured on the same subjects, such as treatment group and clinical outcome, and asks whether the value of one predicts the value of the other. A chi-square goodness-of-fit test takes a single categorical variable and asks whether its observed distribution matches a distribution specified in advance, such as an even split across four seasons or a Mendelian genetic ratio.
Choosing between these two, and between chi-square and a completely different test altogether, depends on how the data were collected and what question is being asked. Readers still deciding whether chi-square is even the right family of test for their data can work through Editverse’s interactive test selector or the statistical test flowchart before continuing.
Both chi-square versions run on the same statistic.
χ² = Σ (O − E)² / E
O stands for the observed count in a category or cell, E stands for the count expected under the null hypothesis, and the sum runs across every cell in the table. Squaring the difference removes the sign so over-counts and under-counts both push the statistic upward, and dividing by E scales each squared difference against the count actually expected there. A cell expected to hold 200 observations can absorb a gap of 10 without much fuss. A cell expected to hold 5 cannot, and the division by E reflects that directly.

How the Chi-Square Test Statistic Is Calculated
Expected frequencies come from the null hypothesis, not from a round number picked for convenience. In a contingency table, the expected count for any cell equals its row total multiplied by its column total, divided by the grand total. That formula follows directly from the independence assumption. If two variables truly have nothing to do with each other, the proportion of a column that lands in a given row should match that row’s overall share of the whole table.
A small illustration makes this concrete. Suppose 100 patients split into 50 treated and 50 untreated, and separately 45 of the 100 end up classified as cured and 55 as not cured. Under independence, the treated group should show the same 45% cure rate as the untreated group, so the expected count of cured patients among the treated works out to 50 × 45 ÷ 100, or 22.5. Expected counts do not need to be whole numbers. Only observed counts do.
Goodness-of-fit expected counts work the same way but come from a hypothesized proportion rather than a second variable. Testing whether 200 disease onsets spread evenly across four seasons sets each season’s expected count at 200 × 0.25, or 50, and the test then measures how far the real seasonal counts drift from that flat line.
Degrees of Freedom in a Chi-Square Test
Degrees of freedom tell the chi-square distribution which shape to take. A mismatched degrees-of-freedom value is easy to miss while drafting a results section, yet it changes the critical value the statistic gets compared against and can flip a borderline conclusion from significant to non-significant or back. For a contingency table with r rows and c columns, degrees of freedom equal (r − 1)(c − 1). A standard 2×2 table therefore carries exactly one degree of freedom, because once the row and column totals are fixed, only one cell can vary freely before the rest fall out by subtraction.
Goodness-of-fit degrees of freedom follow a related but distinct rule. They equal the number of categories minus 1, minus one further degree for every parameter estimated from the sample rather than fixed in advance. Testing four seasons against a flat 25% expectation uses 4 − 1 = 3 degrees of freedom, since nothing was estimated from the data. Testing genotype counts against Hardy-Weinberg proportions is more subtle, because the allele frequency used to build the expected genotype proportions is itself estimated from that same sample, and that estimation step costs an additional degree of freedom beyond the simple count-minus-one rule.
Chi-Square Test of Independence: A Fully Worked Example
Consider a two-arm comparison of 100 patients, 50 who received a treatment and 50 who did not, cross-tabulated against a binary cured or not-cured outcome. This exact dataset also runs inside Editverse’s chi-square test calculator as its loadable example, so every step below can be reproduced instantly.
| Cured | Not cured | Row total | |
|---|---|---|---|
| Treated | 30 | 20 | 50 |
| Untreated | 15 | 35 | 50 |
| Column total | 45 | 55 | 100 |
Expected counts follow the row-total-times-column-total rule from the previous section. Treated-and-cured expects 50 × 45 ÷ 100 = 22.5. Treated-and-not-cured expects 50 × 55 ÷ 100 = 27.5. Untreated-and-cured expects 50 × 45 ÷ 100 = 22.5. Untreated-and-not-cured expects 50 × 55 ÷ 100 = 27.5. Every expected count clears Cochran’s threshold of 5, so the ordinary chi-square approximation applies without qualification.
Each cell then contributes (O − E)² ÷ E to the total. Treated-and-cured contributes (30 − 22.5)² ÷ 22.5 = 2.500. Treated-and-not-cured contributes (20 − 27.5)² ÷ 27.5 = 2.045. Untreated-and-cured contributes (15 − 22.5)² ÷ 22.5 = 2.500. Untreated-and-not-cured contributes (35 − 27.5)² ÷ 27.5 = 2.045. Summed, those four contributions give χ² = 9.091 on 1 degree of freedom, corresponding to p = 0.0026, comfortably below the conventional 0.05 threshold. Applying Yates’ continuity correction, covered in full further down, lowers the statistic to 7.919 (p = 0.0049); an independently run Fisher’s exact test on the same table returns p = 0.0046. All three routes agree that treatment and outcome are associated, exactly the kind of triangulation a manuscript reviewer wants to see in a results section.
Significance alone does not describe how strong the association is. The odds of being cured run 30 to 20 among treated patients versus 15 to 35 among untreated patients, giving an odds ratio of (30 × 35) ÷ (20 × 15) = 3.5. Cramér’s V, a chi-square-based effect size bounded between 0 and 1 for a 2×2 table, works out to the square root of (9.091 ÷ 100), or 0.30, sitting between a small and a medium association by conventional benchmarks. Reporting the p-value next to the odds ratio and Cramér’s V, rather than the p-value by itself, separates a publication-ready results section from one that draws a reviewer query.
Chi-Square Goodness-of-Fit Test: A Second Worked Example
Surveillance teams frequently ask a different kind of question, not whether two variables are related, but whether one variable’s distribution matches an expected pattern. Suppose a health department logs 200 confirmed cases of a gastrointestinal illness across a calendar year and wants to know whether onsets cluster by season or spread out evenly. Under a flat, no-seasonality null hypothesis, each of the four seasons expects 200 × 0.25 = 50 cases.
| Season | Observed | Expected | (O − E)² ÷ E |
|---|---|---|---|
| Winter | 72 | 50 | 9.68 |
| Spring | 38 | 50 | 2.88 |
| Summer | 33 | 50 | 5.78 |
| Fall | 57 | 50 | 0.98 |
Summed across all four seasons, the contributions total χ² = 19.32 on 4 − 1 = 3 degrees of freedom, giving p = 0.00023. That result rejects the flat-distribution null decisively. Winter’s contribution of 9.68 and Summer’s contribution of 5.78 account for most of the total statistic, pointing directly to where the deviation actually lives. Winter runs well above its expected share and Summer well below it, rather than every season drifting slightly in the same direction, a distinction the omnibus p-value alone never reveals and that inspecting each cell’s own contribution is needed to catch.
This exact structure appears throughout epidemiology, most often in checking whether genotype counts match Hardy-Weinberg equilibrium as a genotyping quality-control step, or whether a diagnosis matches expected proportions drawn from a reference population. The mechanics never change. State the null proportions, multiply by the total sample size to get expected counts, sum the squared standardized gaps, and compare the total against a chi-square distribution with the matching degrees of freedom.
When the Chi-Square Test Breaks Down: Small Expected Cell Counts
A chi-square statistic is only ever an approximation. Its reference distribution assumes cell counts behave enough like a continuous, roughly normal quantity for a discrete sum of squared deviations to trace a smooth chi-square curve. That assumption rests on each cell holding a reasonably large expected count, in much the same way a normal approximation to a binomial proportion needs enough trials before it stops misbehaving at the tails. Once an expected count drops to 2 or 3, the handful of values the observed count can actually take sit far apart relative to their spread, the true sampling distribution of the statistic turns lumpy rather than smooth, and the chi-square curve fits it poorly.
William Cochran’s 1954 paper in Biometrics turned that theoretical concern into a working rule still taught today. No more than 20% of cells should carry an expected count below 5, and no single cell should fall below 1; cross either line and the reported p-value can no longer be trusted at face value. Simulation studies of that era produced the rule rather than a closed-form proof, and later work has kept confirming the underlying concern even as the exact threshold gets debated, including methods literature on Hardy-Weinberg testing that describes the ordinary chi-square goodness-of-fit test as very sensitive to small sample size or rare allele frequency.
A small worked table shows the practical stakes plainly. Take a 2×2 table with counts of 4, 1, 1, and 4, where every expected count equals 2.5, comfortably below Cochran’s floor. The uncorrected chi-square statistic comes out to 3.6 on 1 degree of freedom, for p = 0.058, a result tempting enough to call “trending toward significance.” Yates’ continuity correction pulls that same table down to χ² = 1.6 (p = 0.206), and an independently run Fisher’s exact test lands at p = 0.206 as well, agreeing almost exactly with the corrected chi-square and flatly contradicting the uncorrected version. Reporting the uncorrected p-value here would overstate the evidence for an association that the exact test does not support.
Yates’ Continuity Correction Explained
Frank Yates proposed a fix for small 2×2 tables in a 1934 paper in the Journal of the Royal Statistical Society. Because the chi-square distribution is continuous while cell counts are discrete integers, Yates suggested subtracting 0.5 from the absolute value of each (O − E) difference before squaring, which shrinks the statistic and pushes the p-value upward relative to the uncorrected version. In the small 4-1-1-4 table above, that adjustment moved the statistic from 3.6 down to 1.6, precisely the kind of correction meant to keep the uncorrected test from over-claiming significance in sparse tables.
Whether that correction should apply by default has been argued for decades without full resolution, and this guide will not pretend the matter is settled. Haviland’s 1990 paper in Statistics in Medicine argued that the Yates-corrected statistic is overly conservative and that a plain Pearson chi-square already controls Type I error adequately for most 2×2 tables researchers actually encounter. A more recent analysis reached the opposite conclusion. Prescott’s 2021 paper in Statistics in Medicine recommends testing 2×2 tables using double the one-tailed exact probability from Fisher’s test, or the Yates-corrected chi-square as its approximation, specifically for medical research applications. Given that live disagreement between careful statisticians, the safest practical stance is reporting which version was used and leaning on Fisher’s exact test rather than either chi-square variant whenever a table is small enough for the choice to matter.
Fisher’s Exact Test: The Alternative for Small Samples
Ronald Fisher described the exact approach in a 1922 paper in the Journal of the Royal Statistical Society, building on the same contingency-table logic Pearson had introduced two decades earlier. Rather than approximating a sampling distribution with a smooth curve, Fisher’s exact test fixes the row and column totals and calculates the exact probability of every possible table at least as extreme as the one observed, using the hypergeometric distribution. No approximation step means no risk of the smooth-curve mismatch described above, which is exactly why the exact test holds up where the ordinary chi-square does not.
Sahai and Khurshid’s 1995 review in the Journal of Biopharmaceutical Statistics walks through the tradeoffs in detail and notes that the exact test can itself be conservative for certain table configurations, so switching to Fisher’s does not automatically produce a more powerful test, only a more defensible one when sample sizes are small. A practical decision rule follows directly from Cochran’s threshold above. Run the ordinary chi-square test when every, or nearly every, expected count reaches 5 or more, and switch to Fisher’s exact test once that condition fails, regardless of how large the overall sample looks, since a large total can still hide one sparse cell inside an unbalanced table.
Real-World Applications of the Chi-Square Test in Epidemiology
Published epidemiological research leans on chi-square procedures constantly, almost always as a first-pass screen before more elaborate modeling. Hazra and Gogtay’s biostatistics tutorial in the Indian Journal of Dermatology lists Pearson’s chi-square, McNemar’s chi-square for paired binary data, and the Mantel-Haenszel chi-square for stratified tables as the three variants clinical researchers meet most often, each suited to a different data structure rather than being interchangeable options.
Genetic epidemiology relies on the goodness-of-fit version as a routine quality-control step. Genotyping studies test whether observed genotype counts at a given locus match Hardy-Weinberg proportions, and a significant deviation often signals genotyping error, population stratification, or genuine selection pressure rather than a finding to report at face value, a distinction genetics methods chapters on Hardy-Weinberg testing walk through in detail for researchers building genetic association studies. A widely used tutorial on the 2×2 table published in Disability and Rehabilitation works through a breast-cancer risk-factor table end to end and argues that journal editors should require both observed and expected cell counts in every published table, not the test statistic alone, so readers can judge for themselves whether Cochran’s threshold was met.
Outside genetics, the test of independence turns up in case-control comparisons of exposure by disease status, cross-sectional surveys comparing a categorical outcome across demographic strata, and diagnostic studies comparing test results across patient subgroups. Surveillance data gets checked with the goodness-of-fit version whenever it needs comparing against an expected pattern, seasonal or otherwise, exactly as demonstrated above.

Common Mistakes in Chi-Square Test Reporting
A handful of errors recur across submitted manuscripts and published papers alike.
- Entering percentages instead of raw counts. Chi-square formulas operate on frequencies, not proportions, so converting a percentage back to an actual count before testing is mandatory, not optional.
- Ignoring the expected-count threshold. Publishing a chi-square p-value from a table with several cells under 5, without acknowledging the limitation or switching to Fisher’s exact test, ranks among the most avoidable statistical errors in this area.
- Applying the independence test to paired data. Before-and-after measurements or matched pairs on the same subjects violate the independence assumption outright. McNemar’s test exists precisely for that situation.
- Reporting significance without an effect size. A p-value confirms an association exists. Whether that association is large enough to matter clinically is a separate question, so Cramér’s V, phi, or an odds ratio belongs next to every chi-square result.
- Getting degrees of freedom wrong. A mismatched value is easy for a statistical reviewer to catch and signals that the analysis was not checked carefully before submission.
How to Report a Chi-Square Test in Your Manuscript
Most journals in the health sciences follow a version of the same reporting template. State the test name, the degrees of freedom in parentheses, the sample size, the statistic, and the p-value, in that order, for example “χ²(1, N = 100) = 9.09, p = .003.” Follow immediately with the effect size and, for a 2×2 table, the odds ratio or relative risk with its confidence interval. A widely used guide to statistical misinterpretation published in the European Journal of Epidemiology makes the point that a p-value alone, without an accompanying interval estimate, invites readers to over-read significant as large or important.
A results table should show observed counts for every cell, not percentages alone, so a careful reader can recompute the test independently. Methods sections should name which correction, if any, was applied, whether uncorrected Pearson, Yates-corrected, or Fisher’s exact, and state the software and version used. Researchers still weighing chi-square against other options for a broader analysis plan may also find Editverse’s guide to choosing the right statistical test useful for the parts of a manuscript that fall outside categorical data.
Need Expert Help With Your Statistical Analysis?
Editverse biostatisticians build contingency tables, choose between chi-square and Fisher’s exact correctly, and deliver publication-ready results with fully reproducible R output. Run the numbers first with the free chi-square test calculator, or hand over the raw data directly through the Just Data Service for full analysis, write-up, and journal submission support.
Conclusion
Running a chi-square test correctly takes more than plugging counts into a formula. Expected frequencies need to come from a clearly stated null hypothesis, degrees of freedom need to match the table’s actual shape, and the choice between the ordinary chi-square, the Yates-corrected version, and Fisher’s exact test needs to follow from the size of the smallest expected cell rather than habit. Both worked tables above, cross-checked against independent statistical software at every step, show how much a result can shift once expected counts run small, and why a p-value copied from software output without checking that number first tells an incomplete story.
Categorical data of this kind sits at the center of case-control studies, diagnostic accuracy papers, and genetic association work, exactly why manuscript reviewers scrutinize this particular test so closely. Getting the assumptions right the first time, and reporting an effect size alongside the p-value, heads off the revision request before it gets written.
FAQ
What is a chi-square test used for?
A chi-square test checks whether observed category counts differ from the counts expected under a null hypothesis, either because two categorical variables are related, the test of independence, or because one variable’s distribution does not match a stated pattern, the goodness-of-fit test.
What is the chi-square test formula?
χ² = Σ (O − E)² / E, where O is each cell’s observed count, E is that cell’s expected count under the null hypothesis, and the sum runs across every cell in the table.
How many degrees of freedom does a chi-square test have?
A contingency table has (rows − 1) × (columns − 1) degrees of freedom, so a 2×2 table has exactly 1. A goodness-of-fit test has the number of categories minus 1, minus one more for each parameter estimated from the sample.
When should I use Fisher’s exact test instead of chi-square?
Switch to Fisher’s exact test when more than 20% of a table’s cells have an expected count below 5, or any single cell has an expected count below 1, following Cochran’s 1954 guidance.
Should I always apply Yates’ continuity correction?
Statisticians disagree. Some evidence suggests the correction is overly conservative for larger 2×2 tables, while other recent work recommends it, or an equivalent exact test, specifically for medical research. Reporting which version was used matters more than picking a universal default.
What is the difference between the chi-square test of independence and goodness-of-fit test?
The test of independence compares two categorical variables against each other inside a contingency table. The goodness-of-fit test compares a single variable’s observed distribution against a distribution specified in advance.
Does a significant chi-square result tell me how strong the association is?
No. Significance only indicates that an association is unlikely to be due to chance at the chosen alpha level. Strength requires a separate effect size such as Cramér’s V, phi, or an odds ratio.
Can chi-square tests be used on continuous data?
Not directly. Continuous measurements need grouping into categories first, which discards information, so a t-test, ANOVA, or regression model is usually the better choice when the outcome is genuinely continuous.
References
- Pearson K. On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. Philos Mag. 1900;50(302):157–175. doi.org/10.1080/14786440009463897
- Fisher RA. On the interpretation of χ² from contingency tables, and the calculation of P. J R Stat Soc. 1922;85(1):87–94. doi.org/10.2307/2340521
- Yates F. Contingency tables involving small numbers and the χ² test. Suppl J R Stat Soc. 1934;1(2):217–235. doi.org/10.2307/2983604
- Cochran WG. Some methods for strengthening the common χ² tests. Biometrics. 1954;10(4):417–451. doi.org/10.2307/3001616
- Haviland MG. Yates’s correction for continuity and the analysis of 2 x 2 contingency tables. Stat Med. 1990;9(4):363–367. PMID 2362976
- Prescott RJ. Two-tailed significance tests for 2 x 2 contingency tables. What is the alternative? Stat Med. 2021;38(22):4264–4269. PMID 31264237
- Sahai H, Khurshid A. On analysis of epidemiological data involving a 2 x 2 contingency table, an overview of Fisher’s exact test and Yates’ correction for continuity. J Biopharm Stat. 1995;5(1):43–70. PMID 7613560
- Hazra A, Gogtay N. Biostatistics series module 4, comparing groups, categorical variables. Indian J Dermatol. 2016;61(4):385–392. PMID 27512183
- Wang J, Shete S. Testing departure from Hardy-Weinberg proportions. Methods Mol Biol. 2012;850:77–102. PMID 22307695
- Rigby AS. Statistical methods in epidemiology. VII. An overview of the chi2 test for 2 x 2 contingency table analysis. Disabil Rehabil. 2002;23(16):693–697. PMID 11732558
- Greenland S, Senn SJ, Rothman KJ, et al. Statistical tests, P values, confidence intervals, and power, a guide to misinterpretations. Eur J Epidemiol. 2016;31(4):337–350. PMID 27209009
