Parameters
Enter the observed frequencies and the theoretical probabilities separated by commas. If you don't provide probabilities, a uniform distribution is assumed.
Observed counts in each category, separated by commas. The total of all frequencies is the sample size n.
Theoretical probability of each category under H₀, in the same order as the observed frequencies. They must add up to 1; if you leave the field empty, a uniform distribution is assumed (the same probability for every category).
Risk of rejecting H₀ (that the observed distribution matches the theoretical one) when it is true. The usual value is 0.05.
Rejection regions and observed statistic
What is the chi-square goodness-of-fit test?
It is the test for deciding whether the data of one categorical variable are distributed across its categories as a theoretical model predicts. You count the observations falling into each category and compare them with what would be expected: do the six faces of a die come up equally often? Are births spread evenly across the days of the week? Do the four phenotypes of a cross appear in the 9:3:3:1 ratio that genetics predicts? Are sales distributed across regions as they were last year?
The null hypothesis states that the category probabilities are those of the model; the alternative, that at least one is different:
\(H_0: p_1 = p_{1,0},\ p_2 = p_{2,0},\ \ldots,\ p_k = p_{k,0}\)
\(H_1\): some \(p_i\) differs from the one given by the model
The statistic
\( \chi^2 = \sum_{i=1}^{k} \dfrac{(O_i - E_i)^2}{E_i}, \qquad E_i = n\,p_{i,0}, \qquad df = k - 1 \)
- \(O_i\): observed frequency in category \(i\).
- \(E_i\): expected frequency if \(H_0\) were true: the total \(n\) times the theoretical probability.
- \(k\): number of categories.
Each term measures how far the observed count is from the expected one, squared so that excesses and shortfalls do not cancel out, and divided by the expected count to put it in proportion: a difference of 10 is huge if 20 were expected and negligible if 2000 were. If the data fit the model, the statistic is small; the larger it is, the worse the fit.
Under \(H_0\), it approximately follows a chi-square distribution with \(k - 1\) degrees of freedom. One is subtracted because the frequencies add up to \(n\): once \(k - 1\) are known, the last one is determined. The test is always right-tailed: only large values are evidence against the model.
Decision rule
- If the p-value is less than \(\alpha\), \(H_0\) is rejected: the data do not fit the theoretical distribution.
- If the p-value is greater than or equal to \(\alpha\), the data are compatible with the model.
- Not rejecting \(H_0\) does not prove that the model is the true one.
Conditions for use
- Frequencies, not percentages: the statistic needs counts. With the same percentages, the result changes completely depending on whether there are 50 or 5000 observations behind them.
- Independent observations, each classified into a single category.
- Large enough expected frequencies: the chi-square approximation is reliable when all expected frequencies are at least 5 (or, by Cochran's rule, when no more than 20% are below 5 and none is below 1). What counts are the expected frequencies, not the observed ones. If the condition fails, merge infrequent categories; the calculator warns you.
- Probabilities set in advance: if the theoretical probabilities are computed by estimating parameters from the data themselves (for example, fitting a Poisson by estimating its mean), one further degree of freedom must be subtracted for each estimated parameter. The calculator uses \(k - 1\), which corresponds to known probabilities.
For ungrouped continuous data, a specific test such as Kolmogorov-Smirnov or, for normality, Shapiro-Wilk is preferable. And if you want to study the relationship between two categorical variables, the appropriate test is the chi-square test of independence.
Worked example 1: is the die fair?
A die is rolled 60 times with these frequencies: 8, 12, 9, 11, 10 and 10. If the die is fair, each face has probability 1/6 and \(E_i = 60/6 = 10\) appearances of each are expected. We test with \(\alpha = 0.05\).
\( \chi^2 = \dfrac{(8-10)^2}{10} + \dfrac{(12-10)^2}{10} + \dfrac{(9-10)^2}{10} + \dfrac{(11-10)^2}{10} + 0 + 0 = 0.4 + 0.4 + 0.1 + 0.1 = 1.0 \)
With \(df = 5\), the critical value is 11.07 and the p-value is \(p \approx 0.963\). \(H_0\) is not rejected: the results are perfectly compatible with a fair die.
But be careful about concluding that the die "is" fair. With only 60 rolls, the test detects with 80% probability only medium or large deviations (w ≈ 0.46): a slightly loaded die would pass the test almost every time. Detecting small deviations would take more than a thousand rolls.
In the calculator: observed frequencies "8, 12, 9, 11, 10, 10", with the theoretical probabilities left empty (uniform distribution).
Worked example 2: unequal theoretical proportions
In his pea experiment, Mendel classified 556 seeds into four types and obtained 315, 108, 101 and 32. His theory predicts the ratio 9:3:3:1, that is, probabilities 0.5625, 0.1875, 0.1875 and 0.0625. The expected frequencies are:
| Type | Observed | Theoretical probability | Expected | \((O-E)^2/E\) |
|---|---|---|---|---|
| Round and yellow | 315 | 9/16 | 312.75 | 0.016 |
| Round and green | 108 | 3/16 | 104.25 | 0.135 |
| Wrinkled and yellow | 101 | 3/16 | 104.25 | 0.101 |
| Wrinkled and green | 32 | 1/16 | 34.75 | 0.218 |
The statistic is \(\chi^2 \approx 0.47\) with \(df = 3\), and the p-value is \(p \approx 0.925\). \(H_0\) is not rejected: the data fit the theory very well. Here the sample is large: with 556 seeds even small deviations (w ≈ 0.14) would be detected, so the good fit says considerably more than in the die example.
In the calculator: frequencies "315, 108, 101, 32" and probabilities "0.5625, 0.1875, 0.1875, 0.0625".
How to interpret the result
Rejecting \(H_0\) (p-value < α) indicates that the observed distribution differs from the theoretical one, but not in which categories. To find out, compare the observed and expected frequencies in the table that accompanies the result: the categories with the largest \((O-E)^2/E\) contribute the most. Remember too that, with very large samples, tiny and irrelevant deviations become significant.
Not rejecting \(H_0\) indicates that the data are compatible with the model, not that the model is true: they would also be compatible with other similar models.
In the calculator, the result shows the decision with the p-value, the χ² statistic with its degrees of freedom and a sentence stating the conclusion. On the chart, the red area is the rejection region on the chi-square distribution and the line marks the observed statistic. Under "Calculation details" you will find the critical value, the effect size and the smallest expected frequency.
Effect size: Cohen's w
To measure how far the data depart from the model, regardless of sample size, Cohen's w is used: \(w = \sqrt{\chi^2/n}\). As a rough guide, 0.1 is a small deviation, 0.3 medium and 0.5 large. In the die example, \(w \approx 0.13\); in Mendel's, \(w \approx 0.03\).
Power and minimum detectable deviation
Below the conclusion, the calculator shows the minimum detectable deviation: the smallest w that, with your sample size and number of categories, the test would detect with 80% probability. This is what lets you judge a non-significant result: if only large deviations would be detected, the fact that the data "fit" says little. The link opens the sample size calculator for the chi-square goodness-of-fit test with your number of categories and your α.
Common mistakes
- Entering percentages or proportions instead of counts.
- Looking at the observed frequencies, rather than the expected ones, to check the "at least 5" rule.
- Reading a good fit as proof that the model is true, especially with small samples.
- Not adjusting the degrees of freedom when the theoretical probabilities were estimated from the same data.
- Merging categories after seeing the data until the desired result is obtained.
- Using it with observations that are not independent, such as several answers from the same person.
Frequently asked questions
- What is the chi-square goodness-of-fit test for? To check whether the observed frequencies of a categorical variable match those predicted by a theoretical distribution.
- How are the expected frequencies computed? By multiplying the total number of observations by the theoretical probability of each category. If you give no probabilities, all categories are assumed equally likely.
- How many degrees of freedom does it have? The number of categories minus 1. If the theoretical probabilities are estimated from the data, 1 more is subtracted for each estimated parameter.
- What condition must the expected frequencies meet? They should be at least 5 in almost all categories. If not, merge categories.
- Can I use percentages? No. The statistic needs counts: the same percentage split gives different results depending on the sample size.
- What does not rejecting H₀ mean? That the data are compatible with the model, not that the model is true. With small samples, only large deviations would be detected.
- How does it differ from the chi-square test of independence? The goodness-of-fit test compares one variable with a theoretical distribution; the test of independence studies the relationship between two variables in a contingency table.
- What is the minimum detectable deviation? The smallest effect size, measured with Cohen's w, that the test would detect with 80% probability given your sample size.
Reference: Pearson's chi-squared test — Wikipedia