Chi-Square Goodness of Fit Calculator
Test if data fits expected distribution.
Enter at least 2 observed values
Enter observed frequencies to test goodness of fit
What Is the Chi-Square Goodness-of-Fit Test?
The chi-square goodness-of-fit test determines whether observed frequencies match expected frequencies for a single categorical variable.
Question answered: "Does the observed distribution match the expected distribution?"
Examples:
- "Is this die fair?" (expect equal frequencies for 1-6)
- "Does our customer base match the general population demographics?"
- "Do survey responses follow the expected proportions?"
Goodness-of-Fit vs. Independence
Goodness-of-fit: One variable, testing against specified expected proportions.
Independence: Two variables, testing whether they're related.
Both use chi-square, but answer different questions.
The Hypotheses
H₀: Observed frequencies match expected proportions.
H₁: Observed frequencies don't match expected proportions.
This is always a two-sided test—any deviation from expected counts against H₀.
Calculating the Test
Step 1: State Expected Proportions
For a fair die: 1/6 for each face (equal).
For matching population: proportions from census or reference data.
Step 2: Calculate Expected Frequencies
E = n × expected proportion
For 120 die rolls expecting equal distribution: E = 120 × (1/6) = 20 for each face.
Step 3: Calculate Chi-Square
χ² = Σ[(O - E)² / E]
| Face | Observed | Expected | (O-E)² | (O-E)²/E |
|---|---|---|---|---|
| 1 | 25 | 20 | 25 | 1.25 |
| 2 | 17 | 20 | 9 | 0.45 |
| 3 | 15 | 20 | 25 | 1.25 |
| 4 | 22 | 20 | 4 | 0.20 |
| 5 | 18 | 20 | 4 | 0.20 |
| 6 | 23 | 20 | 9 | 0.45 |
| Total | 120 | 120 | 3.80 |
Step 4: Find Degrees of Freedom
df = k - 1
Where k = number of categories.
For die: df = 6 - 1 = 5
If parameters were estimated from data, subtract additional df.
Step 5: Calculate P-Value
Compare χ² = 3.80 to chi-square distribution with df = 5.
p = 0.58
Conclusion: No evidence the die is unfair (p > 0.05). Observed frequencies are consistent with fair die hypothesis.
Applications
Testing Randomness
Are outcomes uniformly distributed?
- Lottery numbers
- Random number generators
- Shuffled decks
Testing Theoretical Distributions
Do genetics follow Mendelian ratios?
- Expected 3:1 or 9:3:3:1 ratios
- Compare observed to theoretical
Comparing to Known Population
Does sample match population proportions?
- Demographics (age, gender, race)
- Market segments
- Geographic distributions
Survey Response Distributions
Do responses follow expected patterns?
- Likert scale distributions
- Multiple choice distributions
Quality Control
Do defect types occur in expected proportions? Do products fall into expected quality grades?
Specifying Expected Proportions
Equal (Uniform) Distribution
All categories equally likely.
Die: 1/6 each Days of week: 1/7 each
Theoretical Proportions
Based on theory or prior knowledge.
Mendelian genetics: 3:1 ratio → 0.75 and 0.25
Historical/Population Proportions
Based on previous data or reference population.
National demographics applied to local sample.
Estimated from Data
Parameters estimated from sample, then tested.
Warning: Estimating parameters uses up degrees of freedom.
When Parameters Are Estimated
If you estimate k parameters from the data:
df = categories - 1 - k
Example: Fitting Poisson distribution
- Estimate λ from sample mean (1 parameter)
- df = categories - 1 - 1 = categories - 2
This penalizes for "peeking" at the data to set expectations.
Assumptions
Independence
Observations are independent—one outcome doesn't affect another.
Expected Frequencies
Traditional rule: All E ≥ 5
Modern guidance:
- No E < 1
- No more than 20% of categories with E < 5
If violated: Combine categories or use exact test.
Random Sampling
Data represents random sample from population of interest.
Interpreting Results
Significant Result (p < α)
Observed distribution differs from expected. The model doesn't fit.
Examine (O-E)/E for each category to see which deviate most.
Non-Significant Result (p ≥ α)
Data is consistent with expected distribution. Cannot conclude model is wrong.
Caution: Doesn't prove the model is correct—just that data doesn't contradict it.
Effect Size
Chi-square value alone doesn't indicate effect size (depends on n).
Options for effect size:
Root Mean Square Residual: √[Σ(O-E)²/E / n]
Cramér's V (for comparison with baseline): V = √[χ² / (n(k-1))]
Common Mistakes
Confusing with Independence Test
Goodness-of-fit tests one variable against expectations. Independence tests relationship between two variables.
Not Specifying Expectations in Advance
Expectations should be stated before seeing data. Post-hoc expectations inflate Type I error.
Ignoring Category Combination
When expected frequencies are too low, combine categories logically.
Testing Estimated Parameters Without df Adjustment
If you estimated parameters from the data, reduce df accordingly.
Combining Categories
When some expected frequencies are too small:
Before:
| Category | O | E |
|---|---|---|
| A | 45 | 40 |
| B | 38 | 40 |
| C | 12 | 15 |
| D | 3 | 3 |
| E | 2 | 2 |
Categories D and E have E < 5.
After combining D and E:
| Category | O | E |
|---|---|---|
| A | 45 | 40 |
| B | 38 | 40 |
| C | 12 | 15 |
| D+E | 5 | 5 |
Now all E ≥ 5.
Example: Testing Mendelian Ratios
Experiment: Cross pea plants, expect 3:1 ratio of yellow to green.
Data: 315 yellow, 108 green (total 423)
Expected:
- Yellow: 423 × 0.75 = 317.25
- Green: 423 × 0.25 = 105.75
Chi-square: χ² = (315-317.25)²/317.25 + (108-105.75)²/105.75 χ² = 0.016 + 0.048 = 0.064
P-value: For df = 1, p = 0.80
Conclusion: Data is consistent with 3:1 Mendelian ratio.
Relationship to Other Tests
Binomial Test
For two categories, binomial test is more accurate for small samples.
Chi-square approximates binomial for large n.
Kolmogorov-Smirnov
Tests fit to continuous distributions.
Chi-square requires categorical/binned data.
Likelihood Ratio (G-test)
Alternative to chi-square with similar properties.
G = 2Σ[O × ln(O/E)]
Some prefer for theoretical reasons.
Reporting Results
APA format:
"A chi-square goodness-of-fit test indicated that the observed distribution of die outcomes did not differ significantly from uniform distribution, χ²(5) = 3.80, p = .58."
For significant results:
"A chi-square goodness-of-fit test revealed that customer age distribution differed significantly from national demographics, χ²(4) = 23.5, p < .001. Customers aged 25-34 were overrepresented (observed 35%, expected 22%)."
Historical Context
Karl Pearson introduced the chi-square goodness-of-fit test in 1900.
His original application was testing whether observed data fit theoretical probability distributions—hence "goodness of fit."
The test became fundamental in genetics for testing Mendelian inheritance, in physics for testing theoretical predictions, and across sciences for testing any categorical distribution.
Related Calculations
- Chi-Square Independence Test — Two variables
- Binomial Test — Two categories exact
- Chi-Square Distribution — P-values
- Normal Probability Calculator — Continuous distributions
Summary
The chi-square goodness-of-fit test compares observed category frequencies to expected frequencies specified by a theoretical model or prior knowledge. Calculate expected frequencies as n × proportion, compute χ² = Σ(O-E)²/E, and compare to chi-square distribution with df = k-1 (minus any estimated parameters). Assumptions require adequate expected frequencies in all categories. A significant result indicates the data doesn't fit the expected distribution; examine residuals to identify which categories deviate. Always specify expected proportions before analyzing data.