Home / Statistics & Probability / Probability Distributions / Chi-Square Test Statistic

Formula & Calculator

Chi-Square Test Statistic

The chi-square statistic measures how much observed data deviates from what you would expect under a null hypothesis. It is the sum of (observed minus expected) squared, divided by expected, across all categories. For example, if you expect 50 heads and 50 tails in 100 coin flips but observe 60 and 40, chi-square quantifies that difference. It is used for goodness-of-fit tests and tests of independence in contingency tables, common in surveys and experiments.

Statistics Probability Hypothesis Testing
VORZEP · HYPOTHESIS TESTS & GOODNESS OF FIT

Chi-Square Test Statistic Calculator

Compute χ² = Σ (O − E)² / E from observed and expected counts, then compare against the critical value from the chi-square distribution. The calculator shows the observed-vs-expected comparison, the per-cell contributions, the sampling distribution with the critical region, and every algebraic step — all live.

χ² = Σ ( O − E )² / E · df = k − 1 · reject H₀ if χ² > χ²crit
Data entry mode
Significance level α
Observed : Expected Enter one pair per line as O : E, where O is the observed count and E is the expected count under the null hypothesis. For a goodness-of-fit test, E is usually the same for every category (total / k). Comments starting with # are ignored. k = 6
Enter at least one valid O : E pair.
6 categories detected · Σ O = 80 · Σ E = 80.00
2 × 2 contingency table Enter the four observed cell counts. Expected values are computed from the row and column marginals: Eij = (rowi × colj) / N. Degrees of freedom = (2−1)(2−1) = 1. Ideal for a chi-square test of independence or homogeneity. N = 120
Row totals: [50, 70] · Col totals: [55, 65] · E = [[22.92, 27.08], [32.08, 37.92]]
The chi-square statistic measures how far the observed counts are from the expected counts under the null hypothesis. Large values provide evidence against H₀.
CHI-SQUARE TEST STATISTIC
6.4000
df = 5 · p = 0.2693 · critical = 11.0705 · α = 0.05
FAIL TO REJECT H₀
χ² = Σ (O − E)² / E = 6.4000
Step-by-step solution
Contribution of each cell (O − E)² / E
O ≥ E (surplus) O < E (deficit) Mean contribution χ²/df
Chi-square distribution with rejection region
Acceptance region (1 − α) Rejection region (α) Observed χ²
Observed vs expected counts
Observed (O) Expected (E)
Sensitivity & effect size
Companion statistics
Observed vs expected — live schematic
Observed count O Expected count E Largest positive deviation Largest negative deviation
Chi-square distribution with critical value — live schematic
Acceptance region (1 − α) Rejection region (α) Observed χ² statistic Critical value χ²crit
What the chi-square statistic really measures
O − Edeviation from expectation
²
(O − E)²squared deviation
÷
Escale by expectation
Σ →
χ²test statistic

Why divide by E?

Dividing (O − E)² by E standardises each deviation by the magnitude of the expected count. A deviation of 5 is very different when E = 10 (relative error 50%) than when E = 1000 (relative error 0.5%). Under the null hypothesis, each standardised term contributes roughly one unit of chi-square on average, so the total χ² has an expected value equal to the degrees of freedom.

The chi-square distribution

Under H₀ and with sufficiently large expected counts (each E ≥ 5 by Cochran's rule), the statistic χ² = Σ (O − E)² / E follows a chi-square distribution with df = k − 1 for goodness of fit, or df = (r−1)(c−1) for an r×c contingency table. The distribution is right-skewed, defined only for non-negative values, and approaches a normal shape as df grows. Its mean equals df and its variance equals 2·df.

p-value and critical value

The p-value is the probability of observing a chi-square statistic at least as extreme as the one computed, assuming H₀ is true. It equals the area under the chi-square curve to the right of χ². The critical value χ²crit is the cutoff such that the area to its right equals α. If χ² > χ²crit, reject H₀; if the p-value is less than α, the same conclusion. The two approaches are mathematically equivalent and always agree.

Assumptions and limitations

Chi-square tests require independent observations and reasonably large expected counts — typically E ≥ 5 for every cell. Small expected counts inflate the false-positive rate; use Fisher's exact test for 2×2 tables with small counts, or pool categories. The test also assumes a simple random sample from the population. Finally, a significant chi-square tells you the distributions differ, but not which category drives the difference — inspect the contributions to find the source.

How to Use This Calculator

The chi-square statistic measures how far observed counts are from the counts expected under the null hypothesis — a large value is evidence against H₀.

1. Choose the data entry mode

Use O : E mode for goodness-of-fit tests where you have one observed and one expected count per category. Switch to 2 × 2 table mode for a test of independence or homogeneity with two rows and two columns.

2. Enter your data

In O : E mode, type one pair per line as O : E. Lines starting with # are ignored, so you can annotate categories. In 2 × 2 mode, fill the four cell counts — the calculator computes all the expected values for you from the marginals.

3. Pick a significance level α

Choose 0.10, 0.05, 0.01, or 0.001. The calculator looks up the corresponding critical value χ²crit for your degrees of freedom and highlights whether the statistic falls in the rejection region.

4. Read the result and verdict

The result card shows χ², degrees of freedom, the p-value, and the critical value. A colour-coded verdict tells you whether to reject or fail to reject H₀, along with a rough classification of the effect size using Cohen's w (or Cramér's V for contingency tables).

5. Study the diagrams and charts

The observed-vs-expected diagram shows the two sets of counts side by side, highlighting the largest surplus and deficit. The chi-square distribution curve shows the rejection region in amber and marks your statistic and the critical value.

6. Switch to Advanced for depth

Advanced mode adds the chi-square sampling distribution curve, the observed-vs-expected bar chart, a sensitivity panel showing how χ² responds to changes in each cell, and a full companion statistics table with Cohen's w, Cramér's V, and the largest contributing cell.

What This Tool Offers

Built around the classic chi-square test statistic χ² = Σ (O − E)² / E for goodness-of-fit and contingency tests.

Full test output

χ², degrees of freedom, p-value, critical value at the chosen α, and a clear reject/fail-to-reject verdict — everything a hypothesis test needs.

Two entry modes

O : E pairs for goodness-of-fit tests, and a 2 × 2 contingency table where expected values are computed automatically from the marginals.

Contribution chart

Per-cell contributions (O − E)² / E drawn as bars, coloured by sign, with a horizontal line at the mean contribution χ²/df.

Chi-square distribution

The full density curve for the given df, with the acceptance and rejection regions shaded and the observed statistic and critical value marked.

Observed vs expected

Side-by-side grouped bars comparing observed and expected counts for every category, highlighting the biggest deviations.

Reference tables

Critical values by α and df, common chi-square test types, effect size guidelines, and a full variable reference table.

Reference Tables & Extra Tools

A critical-value lookup and a p-value converter plus formula and effect size references.

p-value from χ² and df

χ²
df
p-value = 0.2693 · critical at α = 0.05 is 11.0705

Critical value lookup

df
α
χ²crit = 11.0705 at df = 5, α = 0.05

Chi-Square Formulas at a Glance

For goodness-of-fit and contingency table tests.

QuantityFormulaNotes
Test statisticχ² = Σ (O − E)² / ESum over all cells
df (goodness of fit)df = k − 1k = number of categories
df (r × c table)df = (r − 1)(c − 1)For 2 × 2, df = 1
Expected (goodness of fit)E = N / kEqual-probability null
Expected (contingency)Eij = (rowi · colj) / NFrom marginals
Critical regionχ² > χ²crit(df, α)Right-tailed test
p-valueP(χ²df > observed χ²)Area to the right
Cohen's w (goodness of fit)w = √(χ² / N)N = total sample size
Cramér's V (r × c)V = √(χ² / (N · min(r−1, c−1)))For 2 × 2, V = φ

Common Chi-Square Tests

When to use each variant.

TestPurposedfTypical use
Goodness of fitCompare observed frequencies to a hypothesised distributionk − 1Fair die, Mendelian ratios, Poisson fit
Test of independenceCheck if two categorical variables are associated(r−1)(c−1)Smoking × disease, gender × preference
Test of homogeneityCheck if two populations have the same distribution(r−1)(c−1)Two treatments, two regions
McNemar's testPaired binary data1Before/after paired measurements
Fisher's exact testSmall-sample 2 × 2 alternative—When any E < 5

Effect Size Guidelines (Cohen's w)

How large a chi-square result actually matters in practice.

w or VInterpretationExample
< 0.10Trivial / negligibleDepartures from fairness you would not notice
0.10 – 0.30Small effectA die slightly biased toward one face
0.30 – 0.50Medium effectA gene with moderate association to a trait
≥ 0.50Large effectA strongly loaded die or a clear treatment effect

Variable Reference

SymbolMeaningTypical rangeNotes
OObserved count≥ 0 integerFrom the actual sample
EExpected count under H₀> 0Should be ≥ 5 in every cell
χ²Chi-square test statistic≥ 0Sum of standardised squared deviations
kNumber of categories≥ 2For goodness of fit
r, cRows and columns≥ 2 eachFor contingency tables
dfDegrees of freedom≥ 1k − 1 or (r−1)(c−1)
NTotal sample size≥ 1Σ O = Σ E
αSignificance level0.001 – 0.10Usually 0.05
wCohen's effect size≥ 0√(χ² / N)
VCramér's V0 – 1For contingency tables

What Does χ² = Σ (O − E)² / E Measure?

The chi-square statistic measures how far the observed counts in a sample depart from the counts you would expect if the null hypothesis were true. Each cell contributes the squared deviation (O − E)², divided by the expected count E to put all cells on a comparable scale. Summing across cells gives a single number that summarises the overall mismatch between data and hypothesis. Under H₀, if the sample is large enough, this statistic follows a chi-square distribution with a known number of degrees of freedom, which lets us compute a p-value and make a decision.

The chi-square test is the standard tool for categorical data. It applies to goodness-of-fit problems (does a die produce equal frequencies? do genes follow a 3:1 ratio? does a Poisson model fit these counts?), to tests of independence (are smoking and lung disease associated? does gender influence product preference?), and to tests of homogeneity (do two hospitals have the same infection rates?). In all of these, the underlying logic is the same: compute the expected counts under the null, measure how far the observations are from those expectations, and ask whether the difference is larger than chance alone would produce.

Chi-Square Test Statistic Formula

The defining formula is:

χ² = Σ ( O − E )² / E

For a goodness-of-fit test where the null hypothesis specifies equal probabilities across k categories:

E = N / k   for every cell
df = k − 1

For an r × c contingency table, expected counts come from the marginals:

Eij = ( rowi · colj ) / N
df = ( r − 1 ) · ( c − 1 )

Effect size measures that accompany the test:

Cohen's w = √( χ² / N )
Cramér's V = √( χ² / ( N · min(r−1, c−1) ) )

Chi-Square Variables

SymbolMeaningNotes
OObserved countThe count actually recorded in each cell
EExpected countWhat the count would be under H₀; must be ≥ 5
χ²Test statisticAlways non-negative; large values indicate departures from H₀
kNumber of categoriesFor goodness of fit
r, cTable dimensionsFor tests of independence or homogeneity
dfDegrees of freedomDetermines which chi-square curve to use
NTotal countΣ O across all cells; equals Σ E
αSignificance levelProbability of Type I error if H₀ true
pp-valueP(χ²df > observed) under H₀

How Each Part Affects the Chi-Square Statistic

Because each term is a squared deviation divided by the expectation, the chi-square statistic is very sensitive to cells with small expected counts. A deviation of 5 contributes 5² / 10 = 2.5 when E = 10, but only 5² / 1000 = 0.025 when E = 1000. This is exactly the desired behaviour: relative rather than absolute deviations matter. It is also why small expected counts inflate the statistic and can cause false positives — a cell with E = 2 and O = 7 has a standardised contribution of 12.5, which on its own can push the test to significance. Cochran's rule of E ≥ 5 in every cell protects against this.

The sum over cells grows both with the number of categories and with the size of the deviations. For a fixed total N, spreading the sample across more categories means each cell has a smaller E and the statistic is more sensitive to sampling noise — which is why df grows and the critical value grows with it. The test is designed so that under H₀, the expected value of χ² equals df, regardless of k or the sample size. This elegant invariance is what makes the chi-square distribution the correct reference distribution for the statistic, and it is why the same formula works for such a wide range of categorical problems.

Chi-Square Calculation Examples

Fair die test
Observed: 10, 12, 20, 14, 10, 14 · Expected: 13.333 each
Contributions: 0.833, 0.133, 3.333, 0.033, 0.833, 0.033
χ² = 5.200 · df = 5 · p ≈ 0.3924 · fail to reject H₀
Mendel 3:1 ratio
Observed: 787 dominant, 277 recessive · Expected: 798, 266
Contributions: 0.152, 0.455
χ² = 0.607 · df = 1 · p ≈ 0.436 · fail to reject H₀
Fair coin
Observed: 60 heads, 40 tails · Expected: 50, 50
Contributions: 2.0, 2.0
χ² = 4.000 · df = 1 · p ≈ 0.0455 · reject H₀ at α = 0.05
2 × 2 contingency table
Table: a = 30, b = 20, c = 25, d = 45 · N = 120
Row totals: 50, 70 · Col totals: 55, 65
Expected: 22.92, 27.08, 32.08, 37.92
χ² = 5.094 · df = 1 · p ≈ 0.0240 · reject H₀ at α = 0.05

Frequently Asked Questions

The chi-square statistic χ² = Σ (O − E)² / E measures how far observed counts O depart from the counts E expected under a null hypothesis. Each cell contributes the squared deviation divided by the expected count, so cells with small expectations contribute disproportionately when they deviate. Under H₀ and with sufficiently large expected counts, the statistic follows a chi-square distribution with a known number of degrees of freedom, which lets you compute a p-value and decide whether the departure is statistically significant.

Use a chi-square test whenever you have categorical data and want to compare observed counts to expected counts. Three classic situations: (1) goodness-of-fit — does the observed distribution match a hypothesised one, such as a fair die or a Mendelian ratio? (2) test of independence — are two categorical variables associated, such as smoking and disease? (3) test of homogeneity — do two populations have the same distribution across categories? All three use the same statistic, differing only in how expected counts are computed and how df is determined.

The chi-square distribution is a large-sample approximation to the true distribution of the test statistic. When expected counts are very small, each cell contributes a large and highly variable amount, and the sum no longer follows a chi-square distribution closely. The traditional rule (Cochran's rule) is that every expected count should be at least 5 for the approximation to be reliable. If some cells have E < 5, you can pool sparse categories, use Fisher's exact test for 2 × 2 tables, or use a Monte Carlo permutation test.

Degrees of freedom is the number of independent pieces of information that go into the statistic. In a goodness-of-fit test with k categories, the observed counts must sum to the fixed total N, so once you know k − 1 of them, the last is determined. That leaves k − 1 independent deviations, and the chi-square distribution has k − 1 degrees of freedom. In a contingency table, the row and column totals are fixed by the observed margins, so df = (r − 1)(c − 1). The df parameter fixes the shape of the chi-square curve — its mean equals df and its variance equals 2·df.

They are two ways of answering the same question. The critical value χ²crit is a fixed threshold determined by α and df — the value such that P(χ²df > χ²crit) = α. If your statistic exceeds it, reject H₀. The p-value is the probability of observing a statistic as extreme or more extreme than yours, assuming H₀ is true — it is the area under the chi-square curve to the right of your statistic. If p < α, reject H₀. The two rules always give the same answer because they are mathematically equivalent.

Cramér's V is an effect size measure for the chi-square test of independence. It is defined as V = √(χ² / (N · min(r−1, c−1))), where N is the total sample size and r, c are the table dimensions. V ranges from 0 (no association) to 1 (perfect association), so it tells you how strong the relationship is, not just whether it is statistically significant. Report V alongside the p-value whenever you have a large sample, because a tiny and practically irrelevant association can be statistically significant with a large enough N.

Both use the same chi-square formula and the same df, but they answer different questions. A test of independence asks whether two categorical variables measured on the same individuals are associated — for example, is gender associated with political affiliation among a single sample of voters? A test of homogeneity asks whether two or more populations have the same distribution across a categorical variable — for example, do men and women have the same distribution of political affiliation, sampled separately from each group? The mathematics is identical; only the sampling design and interpretation differ.

Calculating...

Variables

Symbol Quantity Unit
χ² Chi-square statistic
O Observed frequency
E Expected frequency

What it means

The chi‑square statistic measures the discrepancy between observed frequencies (O) and expected frequencies (E) under a null hypothesis. It is used in tests of independence (contingency tables) and goodness‑of‑fit (checking distribution assumptions). The statistic follows a chi‑square distribution with degrees of freedom determined by the number of categories. It is widely used in social sciences, biology, and marketing research. A large χ² indicates a significant difference between observed and expected. Understanding the chi‑square test is essential for analysing categorical data.

Worked example

Chi-Square Test Statistic – Two Examples

Real‑World
Scenario: In a goodness‑of‑fit test, observed=45, expected=50. Compute chi‑square contribution.
ParameterValue
O45
E50
1χ² = (45−50)² / 50 = 25/50 = 0.5
Result 0.5 ✓ Contribution
Scenario: Observed=120, expected=100. Compute χ².
ParameterValue
O120
E100
1χ² = (120−100)² / 100 = 400/100 = 4
Result 4 ✓ Contribution
Insight: The chi‑square statistic sums squared differences between observed and expected frequencies. It is used for categorical data analysis.

Common mistakes

  • Chi‑square test statistic: Used for goodness‑of‑fit and independence tests.
  • O: Observed frequencies – counts, not proportions.
  • E: Expected frequencies under the null hypothesis.
  • Summation: Sum over all categories (O−E)²/E.
  • Degrees of freedom: Depends on the test – do not forget.

Applications

The chi‑square test statistic, χ² = Σ((O−E)²/E), compares observed frequencies (O) with expected frequencies (E) under a null hypothesis. It is widely used for goodness‑of‑fit tests and for testing independence in contingency tables. Engineers use it to analyse categorical data, such as defects by type, customer preferences, or inspection results. In quality control, it helps determine if a process distribution conforms to expectations. In market research, it tests associations between variables. By calculating the chi‑square statistic, professionals can test whether observed data deviate significantly from expected patterns. This non‑parametric test is robust and applicable to many scenarios, making it a staple in statistical analysis.

  • Goodness‑of‑fit testing (e.g., uniform distribution of defects)
  • Contingency table analysis (test of independence)
    • Quality control – checking product attribute distributions
    • Market research – association between demographics and preferences
    • Biology – genetic cross analysis
    • Social sciences – survey response analysis