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.
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
Critical value lookup
Chi-Square Formulas at a Glance
For goodness-of-fit and contingency table tests.
| Quantity | Formula | Notes |
|---|---|---|
| Test statistic | χ² = Σ (O − E)² / E | Sum over all cells |
| df (goodness of fit) | df = k − 1 | k = number of categories |
| df (r × c table) | df = (r − 1)(c − 1) | For 2 × 2, df = 1 |
| Expected (goodness of fit) | E = N / k | Equal-probability null |
| Expected (contingency) | Eij = (rowi · colj) / N | From marginals |
| Critical region | χ² > χ²crit(df, α) | Right-tailed test |
| p-value | P(χ²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.
| Test | Purpose | df | Typical use |
|---|---|---|---|
| Goodness of fit | Compare observed frequencies to a hypothesised distribution | k − 1 | Fair die, Mendelian ratios, Poisson fit |
| Test of independence | Check if two categorical variables are associated | (r−1)(c−1) | Smoking × disease, gender × preference |
| Test of homogeneity | Check if two populations have the same distribution | (r−1)(c−1) | Two treatments, two regions |
| McNemar's test | Paired binary data | 1 | Before/after paired measurements |
| Fisher's exact test | Small-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 V | Interpretation | Example |
|---|---|---|
| < 0.10 | Trivial / negligible | Departures from fairness you would not notice |
| 0.10 – 0.30 | Small effect | A die slightly biased toward one face |
| 0.30 – 0.50 | Medium effect | A gene with moderate association to a trait |
| ≥ 0.50 | Large effect | A strongly loaded die or a clear treatment effect |
Variable Reference
| Symbol | Meaning | Typical range | Notes |
|---|---|---|---|
| O | Observed count | ≥ 0 integer | From the actual sample |
| E | Expected count under H₀ | > 0 | Should be ≥ 5 in every cell |
| χ² | Chi-square test statistic | ≥ 0 | Sum of standardised squared deviations |
| k | Number of categories | ≥ 2 | For goodness of fit |
| r, c | Rows and columns | ≥ 2 each | For contingency tables |
| df | Degrees of freedom | ≥ 1 | k − 1 or (r−1)(c−1) |
| N | Total sample size | ≥ 1 | Σ O = Σ E |
| α | Significance level | 0.001 – 0.10 | Usually 0.05 |
| w | Cohen's effect size | ≥ 0 | √(χ² / N) |
| V | Cramér's V | 0 – 1 | For 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:
For a goodness-of-fit test where the null hypothesis specifies equal probabilities across k categories:
df = k − 1
For an r × c contingency table, expected counts come from the marginals:
df = ( r − 1 ) · ( c − 1 )
Effect size measures that accompany the test:
Cramér's V = √( χ² / ( N · min(r−1, c−1) ) )
Chi-Square Variables
| Symbol | Meaning | Notes |
|---|---|---|
| O | Observed count | The count actually recorded in each cell |
| E | Expected count | What the count would be under H₀; must be ≥ 5 |
| χ² | Test statistic | Always non-negative; large values indicate departures from H₀ |
| k | Number of categories | For goodness of fit |
| r, c | Table dimensions | For tests of independence or homogeneity |
| df | Degrees of freedom | Determines which chi-square curve to use |
| N | Total count | Σ O across all cells; equals Σ E |
| α | Significance level | Probability of Type I error if H₀ true |
| p | p-value | P(χ²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
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₀
Observed: 787 dominant, 277 recessive · Expected: 798, 266
Contributions: 0.152, 0.455
χ² = 0.607 · df = 1 · p ≈ 0.436 · fail to reject H₀
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
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.
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| Parameter | Value |
|---|---|
| O | 45 |
| E | 50 |
| Parameter | Value |
|---|---|
| O | 120 |
| E | 100 |
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
Related calculators · Probability Distributions
Recently updated formulas
Suggest an improvement
Found a mistake? Have a better example? Let us know.
You may send up to 3 suggestions per 24 hours.