What Is a Chi-Square Statistic? Types and Formula

A chi-square statistic is one number that sums up how far real-world counts stray from the counts you’d expect if chance alone were at work. A value near zero means your data look like the expectation, and a large value means something beyond chance may be going on. It works on counts in categories, like how many people chose each option, rather than on averages, which is why it shows up everywhere from genetics classes to survey reports.

What the Chi-Square Statistic Compares

Two sets of numbers go in. The observed values are the actual counts in each category of your data.1Math is Fun. Chi-Square Test The expected values are the counts you’d predict if a “nothing going on” assumption were true, which statisticians call the null hypothesis.2quantpsy.org. Calculation for the Chi-Square Test Because the test works on counts in categories, data measured on a scale must first be grouped into bins, like a frequency table, before you can use it.3National Institute of Standards and Technology. Chi-Square Goodness-of-Fit Test

Take a bag of candy claimed to hold equal numbers of five flavors, and say you count 100 pieces. A fair split predicts 20 of each flavor. That 20 is the expected count. Your actual tally, maybe 28 red and 12 green, is the observed count. The chi-square asks whether gaps like 28 versus 20 are bigger than the random variation you’d see from one bag to the next.

For a single list of categories with no reason to favor any, each expected count is the total sample divided by the number of categories.4quantpsy.org. Calculation for the Chi-Square Test So 120 rolls of a fair die give an expected 20 for each face. Expected counts are averages over many imagined samples, so a value like 34.5 is perfectly fine, while observed counts are always whole numbers because they are real tallies.

For a two-way table, each cell’s expected count is its row total times its column total, divided by the overall total.5quantpsy.org. Calculation for the Chi-Square Test The logic is this: if the two variables were unrelated, the overall pattern in the row and column totals would simply spread across the cells. Say 60% of all respondents are in one row and 30% are in one column. With no relationship, about 18% of everyone should land in the cell where that row and column meet. Multiplying the totals and dividing by the grand total does exactly that, multiplying the two proportions and scaling back up to a count.

The Chi-Square Formula Step by Step

The formula is χ² = Σ (O − E)² / E.6Math is Fun. Chi-Square Test O is each observed count, E is each expected count, and Σ tells you to add up the result for every category.7Math is Fun. Chi-Square Test

Each step has a job. Squaring the gap makes categories that came in below expectation count just as much as ones that came in above.8JMP. Chi-Square Goodness of Fit Test Dividing by the expected count scales each gap to its size, so a miss of 8 counts for more when only 7 were expected than when many more were.9JMP. Chi-Square Goodness of Fit Test That means categories with small expected counts can dominate the total.

To work it by hand, list each category with its observed and expected count side by side. Subtract expected from observed for every row, keeping the sign at first. Square each difference, then divide by that row’s expected count. Add the column of results to get the chi-square value.

In one example, four categories gave pieces of 1.72, 0.007, 9.14, and 12.5, for a total chi-square of about 23.4.10Yale University Department of Statistics. What Is a Chi-Square Statistic? Types and Formula The two categories with small expected counts supplied almost all of that total.

A few slips are common. Dividing by the observed count instead of the expected count gives the wrong answer. Forgetting to square lets positive and negative gaps cancel to near zero. Using percentages instead of raw counts distorts the statistic. And the value can never be negative, so a negative result signals an arithmetic error.

A total of 0 would mean observed and expected counts match perfectly, which almost never happens. The raw total also can’t be judged alone, because what counts as large depends on the degrees of freedom, covered below.

Types of Chi-Square Tests and When to Use Each

The goodness-of-fit test checks whether one variable’s counts match a claimed pattern or distribution.11National Institute of Standards and Technology. Chi-Square Goodness-of-Fit Test It can be applied to almost any distribution, as long as the data are sorted into classes.12National Institute of Standards and Technology. Chi-Square Goodness-of-Fit Test A typical question is whether a company’s customers are spread evenly across four regions, or whether sales follow a claimed split such as 40/30/20/10. The claimed pattern doesn’t have to be equal shares; you can supply any set of proportions and the expected counts follow from them. Only one categorical variable is involved, so the data are a single row or column of counts rather than a table.

The tests of independence and homogeneity both use a two-way table and the same formula and degrees of freedom.13Albert. AP® Statistics Review: Setting Up a Chi-Square Test for Homogeneity or Independence They answer different questions and come from different study designs.14Albert. AP® Statistics Review: Setting Up a Chi-Square Test for Homogeneity or Independence A test of independence takes one random sample and records two variables for each person.15UCLA Statistics. Chi-square Tests A test of homogeneity samples a fixed number from each group separately, then measures one variable.16Albert. AP® Statistics Review: Setting Up a Chi-Square Test for Homogeneity or Independence Surveying all employed people about gender and union membership tests independence, while sampling men and women separately tests homogeneity.17The Analysis Factor. Chi Square Test of Independence or Homogeneity? The arithmetic is identical, so write the conclusion to match the design: “related” for independence, “distributed the same across groups” for homogeneity.

A separate chi-square test checks whether a population’s variance, its spread, equals a specified value.18NIST/SEMATECH e-Handbook of Statistical Methods. Chi-Square Test for the Variance It can be one-sided or two-sided, and its hypotheses are stated in terms of variance or standard deviation.19Mathematics LibreTexts. Chi-Square Distribution

To choose quickly: one categorical variable compared to a claimed split means goodness of fit. Two categorical variables from one sample means independence. Several groups sampled separately and compared on one variable means homogeneity. A question about the spread of measured values means the variance test.

Degrees of Freedom and Reading Your Result

Degrees of freedom (df) count how many values are free to vary. For goodness of fit it is categories minus 1, and for a two-way table it is (rows − 1) × (columns − 1). The reason is that when the total is fixed, knowing all but one category’s count determines the last. For a die with six faces and 120 rolls, knowing five faces’ counts forces the sixth, giving 5 df. In a two-way table with fixed row and column totals, once you fill in (rows − 1) × (columns − 1) cells, the rest are determined.

This matters because the chi-square distribution’s shape depends on df. It is very lopsided with a long right tail at a df of 1 or 2.20Pearson. What happens to the shape of the chi-square distribution – Larson 8th Edition Ch 6 Problem 6.4.2 As df rises it grows more symmetric and closer to a bell curve.21Online Statistics Education. What Is a Chi-Square Statistic? Types and Formula

With 1 df and the usual 0.05 cutoff, the critical value is 3.84.22Biology Simulations. How to use chi-square to test for Hardy-Weinberg equilibrium In a genetics example, a chi-square of 13.71 beat 3.84 and the population was judged not at Hardy-Weinberg equilibrium.23Biology Simulations. How to use chi-square to test for Hardy-Weinberg equilibrium To use a chi-square table, find the row for your df and the column for your cutoff, usually 0.05. If your value exceeds the table number, the gap is unlikely to be chance alone. Bigger df means bigger critical values, so the same chi-square matters less in larger tables.

Software skips the table. It takes your chi-square and df and reports the p-value, which is the chance of a gap this big if the null hypothesis were true. Below 0.05 is the common cutoff. A p-value under your cutoff means you reject the “nothing going on” assumption. A p-value above it means the gap is the sort chance could plausibly produce, which does not prove the assumption is true. Rejecting the assumption does not tell you which categories caused the difference, and it does not prove cause and effect.

When You Can Use It and What to Do When You Can’t

The common rule is that every expected count should be at least 5.24MetricGate. Chi-Square Test: When Assumptions Break A more lenient version allows up to 20% of cells below 5, as long as none is below 1.25PubMed Central. The Chi-square test of independence The rule is about expected counts, not observed ones, so an observed count of 3 is fine if expected counts are all above 5.26The Analysis Factor. Chi-Square test: Do you need 5 observations per cell? A sample of at least 5 times the number of cells usually satisfies it.27PubMed Central. The Chi-square test of independence

The reason is that the chi-square distribution is a smooth approximation to counts that can only jump in whole numbers. When expected counts are small, the real distribution is lumpy and the approximation fits poorly, so the p-value can be off. Larger expected counts make the fit closer.

So compute every expected count first and scan for the smallest. If your software prints a note such as “cells with expected count less than 5,” read it as a flag that the p-value may be unreliable. Do this before interpreting anything.

When expected counts fall below 5, Fisher’s exact test is often used instead.28The Analysis Factor. Chi-Square test: Do you need 5 observations per cell? Most software offers it for 2×2 tables. You can also combine sparse categories into broader ones when that makes sense, or collect more data so expected counts rise. The Yates correction sometimes offered for 2×2 tables tends to be overly cautious, and the plain chi-square usually works well.29PubMed. Yates’s correction for continuity and the analysis of 2 x 2 contingency tables

Other requirements are easy to forget. Each person or item should be counted in only one cell. Observations must be independent, so repeated measures on the same person break the test. And use raw counts, never percentages or averages.

Significant Versus Strong Effect Size

The chi-square test is very sensitive to sample size.30University of Utah. The Chi-Square Test for Independence With a large enough sample, even trivial relationships look statistically significant.31University of Utah. The Chi-Square Test for Independence That’s because chi-square grows with sample size and with the number of rows and columns, not just association strength.32CASRAI. Cramér’s V: Effect Size for Categorical Data Doubling every count while keeping proportions doubles the chi-square, and the p-value shrinks even though the relationship hasn’t changed.

A survey of tens of thousands finding 51% of one group and 49% of another prefer a product can come out highly significant, yet a two-point difference may be too small to matter. The p-value answers whether the pattern is likely due to chance, not whether it is big enough to care about.

For strength, use an effect size. For a 2×2 table, phi measures strength on a 0-to-1 scale, where 0 means no association and 1 a perfect one.33GraphPad. What Is a Chi-Square Statistic? Types and Formula Cramér’s V extends this to larger tables on the same 0-to-1 scale.34GraphPad. What Is a Chi-Square Statistic? Types and Formula Common guidelines treat 0.1 as small, 0.3 medium, and 0.5 large.35Real Statistics Using Excel. What Is a Chi-Square Statistic? Types and Formula Both divide out the sample size, and V also adjusts for table size, so a V of 0.25 means comparable strength whether the table is 2×3 or 4×5.36CASRAI. Cramér’s V: Effect Size for Categorical Data The raw chi-square can’t do this, since two studies’ totals can’t be compared directly.

When reporting, give the chi-square value, df, and p-value together, then add phi or Cramér’s V so readers can judge strength. A tiny p-value with a V near 0.1 means real but weak.

Finding Which Cells Drive the Result

The overall test only says that somewhere in the table the counts differ from expectation, not where. The adjusted residual rescales each cell’s gap so it can be compared on a standard scale.37Cornell Statistical Consulting Unit. Using Adjusted Standardized Residuals for Interpreting Contingency Tables That lets you test individual cells after the overall test.38Cornell Statistical Consulting Unit. Using Adjusted Standardized Residuals for Interpreting Contingency Tables A common rule flags cells beyond about ±2 in small tables and ±3 in large ones.39ASM Science Journal. Chi-square and Adjusted Standardised Residual Analysis This is usually done only once the overall test is significant.

A positive residual means more cases than expected in that cell, and a negative one means fewer. Many programs report these as “adjusted residuals” alongside the main test. When scanning many cells, use the stricter ±3 cutoff to avoid false alarms.

Without software, look back at your worked sum to see which cells contributed most. Large single contributions point to where the difference lies. This is a rough guide, not a formal test.