How well do the counts match what you expected?
Goodness-of-fit and independence tests of counts: χ², degrees of freedom, p-value and expected counts, drawn live.
What you enter stays on your device while you use this tool. Opening a shared link sends the settings in its address to HowToolbox to prepare the page.
Separate with spaces, line breaks or semicolons.
Proportions, ratios or counts; empty for equal.
p-value
0.925
χ² = 0.47 (df = 3) gives p = 0.925: the counts fit the expected ones (not significant at the 5% level).
The chi-square distribution with the test statistic
Key values as a table
| Statistic | Value |
|---|---|
| Chi-square χ² | 0.47 |
| Critical χ² | 7.815 |
| p-value | 0.925 |
Observed (solid) and expected (hatched) counts
Key values as a table
| Category | Observed counts | Expected | Residual |
|---|---|---|---|
| 1 | 315 | 312.8 | 0.13 |
| 2 | 108 | 104.3 | 0.37 |
| 3 | 101 | 104.3 | −0.32 |
| 4 | 32 | 34.75 | −0.47 |
Chi-square results
- Chi-square χ²
- 0.47
- Degrees of freedom
- 3
- p-value
- 0.925
- Critical χ²
- 7.815
- Total count
- 556
- Expected counts below 5
- 0
Goodness-of-fit and independence tests of counts: χ², degrees of freedom, p-value and expected counts, drawn live.
How to use
- Choose Goodness of fit to compare counts with expected proportions, or Independence to test whether the rows and columns of a table are related.
- Type the observed counts and the expected ratio (leave it empty for equal shares), or the table with one row per line.
- Read the p-value and the sentence; the curve shades the rejection region and the tail beyond χ², and the bars compare each observed count with its expected one. Drag the critical line to change α.
How it works
A chi-square test asks whether counts differ from what a hypothesis predicts by more than chance would explain. It adds up, over every category, the squared difference between the observed count O and the expected count E, divided by E: χ² = Σ (O − E)² ÷ E. The larger χ², the worse the fit; the p-value is the chance of a χ² at least this large if the hypothesis were true.
For goodness of fit, the expected counts are the total times each expected proportion, and the degrees of freedom are the number of categories minus one. Mendel's 556 peas, 315, 108, 101 and 32 against a 9 : 3 : 3 : 1 ratio, expect 312.75, 104.25, 104.25 and 34.75, giving χ² ≈ 0.47 with 3 degrees of freedom and p ≈ 0.93: a very good fit. For a table, each cell expects row total × column total ÷ grand total if rows and columns are independent, with (rows − 1)(columns − 1) degrees of freedom. The method follows the NIST/SEMATECH e-Handbook of Statistical Methods.
The test needs counts of independent observations, not percentages or measurements. The χ² approximation is doubtful when expected counts are small (a common rule: all at least 5); then merge categories or use an exact test. A significant result says the counts differ, not why.
Worked example
Do 315, 108, 101 and 32 pea plants fit the 9:3:3:1 ratio of Mendel's cross?
- Expected counts out of 556: 312.75, 104.25, 104.25 and 34.75.
- χ² = Σ (O − E)² ÷ E = 0.47, with 3 degrees of freedom.
- The critical value at 5% is 7.81; the p-value is 0.925.
χ² = 0.47 is far below 7.81 (p = 0.925): the counts fit the 9:3:3:1 ratio.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods: §1.3.5.15 Chi-Square Goodness-of-Fit TestUsed for: formula
- R documentation: chisq.testUsed for: formula
Frequently asked questions
What is the difference between goodness of fit and independence?
Goodness of fit compares one set of counts with fixed expected proportions, such as a fair die or a genetic ratio. Independence asks whether two classifications of the same subjects, the rows and columns of a table, are related.
Can I enter percentages?
As expected proportions, yes: 25 25 50 works like 1 1 2. The observed values must be counts, because the test depends on how many observations there are.
Does a small p-value mean a strong association?
No. A large sample can make a small association statistically significant. Use Cramér’s V alongside the p-value to judge the strength of an association in a table.
Does a large p-value prove my expected proportions are correct?
No. It means these data do not provide enough evidence against the expected proportions at the chosen significance level. A small sample can miss a real difference.
Can I test repeated measurements from the same people?
Not with this ordinary chi-square test. Its observations must be independent; paired or repeated categorical data need a method designed for that dependence.





