How to use the chi-square calculator
- Enter your observed frequencies as comma-separated numbers in the first field.
- Enter the expected frequencies under your null hypothesis in the second field.
- The chi square calculator updates instantly, showing the test statistic, degrees of freedom and p-value.
- Compare the p-value to your significance level (commonly 0.05) to decide whether to reject the null hypothesis.
How the chi-square statistic is calculated
The goodness of fit test compares what you actually observed to what you would expect if a specific hypothesis were true. The formula sums the squared differences between observed (O) and expected (E) counts, divided by the expected counts:
X² = Σ (Oᵢ - Eᵢ)² / Eᵢ
For example, suppose you roll a six-sided die 60 times and get counts of 8, 12, 9, 11, 10 and 10. If the die is fair, you expect 10 for each face. The calculation is:
(8-10)²/10 + (12-10)²/10 + (9-10)²/10 + (11-10)²/10 + (10-10)²/10 + (10-10)²/10
= 4/10 + 4/10 + 1/10 + 1/10 + 0 + 0 = 1.0
The degrees of freedom equal the number of categories minus one. Here, df = 6 - 1 = 5. This chi square calculator evaluates the p-value from the chi-square distribution using those two numbers.
Understanding the p-value
The p-value tells you the probability of obtaining a test statistic at least as extreme as the one computed, assuming the null hypothesis is correct. A small p-value suggests the observed data are unlikely under that hypothesis.
In most scientific work, a threshold of 0.05 is used. If the p-value is below 0.05, researchers typically reject the null hypothesis and conclude the data do not fit the expected distribution. If it is 0.05 or above, there is not enough evidence to reject it.
This tool computes the p-value using the regularized upper incomplete gamma function, which is the exact cumulative distribution for the chi-square family. You do not need to look up tables manually.
Reference table of critical values
The table below shows the chi-square critical values at the 0.05 significance level for common degrees of freedom. If your computed statistic exceeds the critical value, the result is significant at that level.
| Degrees of freedom | Critical value (α = 0.05) |
|---|---|
| 1 | 3.841 |
| 2 | 5.991 |
| 3 | 7.815 |
| 4 | 9.488 |
| 5 | 11.070 |
| 6 | 12.592 |
| 10 | 18.307 |
For instance, with 5 degrees of freedom, any chi-square statistic above 11.070 yields a p-value below 0.05.
When to use a goodness of fit test
A goodness of fit test applies whenever you have categorical count data and want to check whether it follows a particular distribution. Common scenarios include:
- Testing whether a die, coin or spinner is fair.
- Checking if genetic crosses produce offspring in the expected Mendelian ratios, such as 3:1 or 1:2:1.
- Evaluating whether customer preferences across product categories are evenly distributed.
- Verifying that arrivals per time interval follow a Poisson distribution by comparing observed bin counts to theoretical ones.
Note that this chi square calculator handles the goodness of fit variant only. For testing independence between two variables in a contingency table, you would need a different setup that computes expected values from marginal totals.
Assumptions and common mistakes
The chi-square test relies on several assumptions. Violating them can make the p-value unreliable.
- Count data only. The inputs must be frequencies (counts), not percentages, means or continuous measurements. Feeding proportions instead of raw counts is a frequent error.
- Expected counts should be large enough. A standard rule is that every expected frequency should be at least 5. When expected counts fall below 5, the chi-square approximation to the true distribution weakens, and an exact test may be more appropriate.
- Independent observations. Each item should belong to exactly one category, and the placement of one item should not influence another.
- Matching lengths. The observed and expected lists must contain the same number of categories.
If your total sample size is very small, consider combining sparse categories before running the test, provided doing so makes substantive sense.
Worked examples
Each result below was produced by the same code the tool runs, so you can check your own numbers against them.
| Example | Input | Result |
|---|---|---|
| Fair die (60 rolls) | Observed frequencies: 8, 12, 9, 11, 10, 10; Expected frequencies: 10, 10, 10, 10, 10, 10 | Chi-square statistic: 1; Degrees of freedom: 5; p-value: 0.9626 |
| Genetics 1:2:1 ratio | Observed frequencies: 22, 51, 27; Expected frequencies: 25, 50, 25 | Chi-square statistic: 0.54; Degrees of freedom: 2; p-value: 0.7634 |
| Survey preference | Observed frequencies: 45, 30, 25; Expected frequencies: 33.33, 33.33, 33.33 | Chi-square statistic: 6.5007; Degrees of freedom: 2; p-value: 0 |
FAQ
What does a chi square calculator do?
It computes the chi-square test statistic and corresponding p-value by comparing observed category counts against expected counts. This tells you how well your data fits a hypothesized distribution.
What is the difference between a goodness of fit test and a test of independence?
A goodness of fit test checks one categorical variable against a theoretical distribution. A test of independence examines whether two categorical variables are related, using a two-way contingency table.
Why must expected frequencies be at least 5?
The chi-square distribution is a continuous approximation. When expected counts drop below 5, the approximation becomes inaccurate and the p-value may be misleading.
Can I enter percentages instead of counts?
No. The chi-square formula requires actual frequencies. Entering percentages will produce an incorrect statistic because the scale of the data changes the result.
How are degrees of freedom determined?
For a goodness of fit test, degrees of freedom equal the number of categories minus one. If you estimate parameters from the data, subtract one additional degree of freedom per estimated parameter.
Is my data sent to a server?
No. This chi square calculator processes everything locally in your browser. Nothing is uploaded or stored.