Chi Square Calculator
Compute the chi square statistic from observed and expected counts. Great for goodness of fit checks and quick hypothesis testing with categories.
Enter the Details
Result will appear here...
What the chi-square calculator does
The chi-square statistic measures how far a set of observed counts sits from what you expected. This calculator works out the contribution to that statistic from a single category, from its observed count and its expected count. Add up the contributions from every category, and you have the full chi-square value for a test.
It is the heart of tests that ask whether counts across categories match a theory, from a fair die to a survey breakdown. Below is how it works and how one category's contribution fits into the whole.
How to use it
- Enter the observed value, the count you actually saw for a category.
- Enter the expected value, the count your theory predicts for it.
- Press Calculate for that category's chi-square contribution, or Reset to clear it.
How the chi-square value is worked out
For each category, you take the gap between the observed and expected counts, square it, and divide by the expected count:
Contribution = (observed minus expected)² ÷ expected
Squaring the gap makes every difference positive and gives the bigger gaps more weight. Dividing by the expected count scales each gap against how large it was supposed to be, so a gap of 10 matters far more against an expected 20 than against an expected 2000. That scaling is what lets contributions from categories of different sizes be added together fairly.
Building the full chi-square statistic
A complete chi-square test almost always covers several categories, and the full statistic is the sum of the contributions from all of them:
Chi-square = the sum of (observed minus expected)² ÷ expected, over every category
This calculator gives you one category's contribution at a time. To run a full test by hand, work out the contribution for each category in turn and add them up. The larger that total, the further your observed counts stray from what was expected, and the more the data argues against the theory that produced the expected counts.
Observed and expected counts
The observed counts are simply what you measured. The expected counts are what some hypothesis predicts. For a fair six-sided die rolled 60 times, you would expect each face 10 times, so 10 is the expected count for every face. For a survey, the expected counts might come from a known population breakdown you are comparing your sample against.
The whole test is a structured comparison of the two. If the observed counts sit close to the expected ones, the chi-square total stays small and the theory holds up. If they diverge, the total grows, and that is the signal that something other than chance may be at work.
A worked example
Suppose you roll a die 60 times and expect each face to come up 10 times. One face, though, comes up 16 times. Its contribution to the chi-square statistic is (16 minus 10)² ÷ 10 = 36 ÷ 10 = 3.6.
That is the contribution from one face alone. To test whether the whole die is fair, you would work out the contribution from each of the six faces the same way and add all six together. The sum is the chi-square value you would then check for significance.
Turning it into a p-value
Once you have the full chi-square total, its significance depends on the degrees of freedom, which for these tests is usually the number of categories minus one. The total and the degrees of freedom together give a p-value.
Take them to our chi-square to p-value calculator to get that p-value. A small p-value means the observed counts stray from the expected ones by more than chance comfortably explains, which is evidence against the hypothesis behind the expected counts.
Questions people ask
What is the chi-square statistic?
A measure of how far observed counts fall from expected counts, found by summing (observed minus expected) squared, divided by expected, across all categories.
Does this calculate a full test?
It calculates one category's contribution. For a full test, work out each category's contribution and add them together to get the total chi-square value.
Why square the difference?
Squaring makes every gap positive so they do not cancel, and gives larger gaps more weight. Dividing by the expected count then scales each gap against its size.
Where do the expected counts come from?
From the hypothesis you are testing, such as an equal split for a fair die, or a known population breakdown you are comparing your sample against.
References
A quick note on where the methods here come from. The chi-square statistic and goodness-of-fit testing are set out in the NIST/SEMATECH e-Handbook of Statistical Methods, the US government's public statistics reference. OpenStax Introductory Statistics is a free, widely used textbook covering the chi-square distribution and its tests.
- NIST/SEMATECH e-Handbook of Statistical Methods (chi-square goodness-of-fit test). https://www.itl.nist.gov/div898/handbook/
- OpenStax, Introductory Statistics (the chi-square distribution and goodness of fit). https://openstax.org/details/books/introductory-statistics-2e
Ankit Khatiwada is a researcher and graduate student in Computer Science at Saarland University, with strengths in statistics, data analysis, data engineering, and full stack development. His work sits at the intersection of quantitative reasoning and applied technology, making him a strong fit for tools that depend on clear numerical logic. At Eon Tools, he reviews number and statistical tools.
Other Tools
- Absolute Uncertainty Calculator
- Chi-Square To P-Value Calculator
- Cohen'S D Calculator
- Confidence Interval Calculator
- Degrees Of Freedom Calculator
- Margin Of Error Calculator
- P Value Calculator
- P-Value To Z-Score Calculator
- Relative Error Calculator
- Sensitivity And Specificity Calculator
- Standard Error Calculator
- T Statistic Calculator
- T Test Calculator
- Z Score Calculator
- Z-Score To P-Value Calculator