Chi-Square CalculatorChi-Square Calculator
One variable

Chi-Square Goodness of Fit Calculator

Enter your observed counts and the distribution you expect. The test checks whether the counts are consistent with it, category by category.

Chi-square (χ²)0.4700
Degrees of freedom3
p-value0.9254
Cohen's w0.0291
Critical value at α = 0.057.8147

p is not below α = 0.05: no evidence that the counts differ from the expected distribution at the 5% level. That is not proof of no effect; small samples often miss real differences.

Every expected count is at least 5 (smallest 34.75), so the chi-square approximation is fine by the strict textbook rule and by Cochran's rule.

Category by category
ObservedExpected(O − E)² / EResidual
Category 1315312.750.01620.13
Category 2108104.250.13490.37
Category 3101104.250.1013−0.32
Category 43234.750.2176−0.47

N = 556. The contributions add up to χ².

APA style χ²(3, N = 556) = 0.47, p = .925

Reproduce this result in R or Python

R

chisq.test(c(315, 108, 101, 32), p = c(0.5625, 0.1875, 0.1875, 0.0625), rescale.p = TRUE)

Python (SciPy)

from scipy.stats import chisquare
obs = [315, 108, 101, 32]
exp = [p * 556 for p in [0.5625, 0.1875, 0.1875, 0.0625]]
print(chisquare(obs, f_exp=exp))

Checked on November 21, 2026. Results computed by our statistics engine, version 1.0.0.

On this page

What goodness of fit tests

The goodness-of-fit test asks whether one categorical variable follows a distribution you state in advance. The null hypothesis is that the population proportions equal your expected proportions. Expected counts are those proportions times the total N, and the test has (categories − 1) degrees of freedom, fewer if you estimated parameters from the same data.

The expected distribution must come from theory or an outside source, not from the data you are testing. A genetics ratio, a manufacturer's stated color mix or last year's market shares all work.

Worked example: Mendel's peas

In his 1866 paper Mendel crossed pea plants and counted 556 seeds of four kinds. A 9:3:3:1 ratio is what simple inheritance of two independent traits predicts. These counts are pre-filled above; the result is our calculation from Mendel's published counts.

Seed typeObservedExpected(O − E)² / E
Round yellow315312.750.0162
Round green108104.250.1349
Wrinkled yellow101104.250.1013
Wrinkled green3234.750.2176

The contributions add to χ² = 0.4700. With 3 degrees of freedom, p = 0.9254. The counts fit the 9:3:3:1 ratio very closely: a χ² this small or smaller would happen by chance only about 7% of the time, which is why Mendel's data have been discussed for their unusually good fit.

Worked example with stated proportions

R's help page tests counts of 89, 37, 30, 28, 2 against proportions 0.4, 0.2, 0.2, 0.15, 0.05 (R reference output). Choose "Proportions that add to 1" and enter both lists to reproduce χ² = 9.9901, df 4, p = 0.0406. At the 5% level that is evidence against the stated proportions.

R then changes the last two proportions to 0.19 and 0.01. The expected count in the last category drops to 1.86, and R warns that the approximation may be incorrect. χ² is 5.7947 and p = 0.2150. One of the five expected counts is below 5, which passes Cochran's rule but fails the stricter rule, and the calculator says so.

Expected counts instead of proportions

If you already have expected counts, choose "Expected counts". SciPy's documentation tests 16, 18, 16, 14, 12, 12 first against equal shares, giving χ² = 2.0000 and p = 0.8491, and then against expected counts 16, 16, 16, 16, 16, 8, giving χ² = 3.5000 and p = 0.6234 (SciPy chisquare). Expected counts that do not add to the observed total are rescaled with a note, so only their proportions matter.

Degrees of freedom when you estimate parameters

If you fit a model to the same data first, for example estimating a Poisson mean from the counts, each estimated parameter costs one degree of freedom. Enter the number of parameters in "Parameters estimated" and df becomes (categories − 1 − parameters). SciPy calls this ddof. R's chisq.test has no such argument, so the R code we generate recomputes p with the reduced df.

Two categories

With only two categories, such as heads and tails, the goodness-of-fit test is an approximation to the exact binomial test. The calculator suggests the binomial test in that case; for small samples it is the better choice.

Common questions

Can I enter percentages as observed values?

No. Observed values must be counts. Percentages are fine for the expected distribution.

What if my expected proportions add to 0.99?

Proportions that add to between 0.99 and 1.01 are rescaled to add to 1, with a note, as R does with rescale.p. Further off than that is treated as an error.

What does a large p-value mean here?

No evidence that the counts differ from the expected distribution. It does not prove the distribution is right.

Sources