Chi-Square Goodness-of-Fit Test
Test whether the observed counts across categories match an expected distribution, such as equal proportions or a theoretical model. Get the chi-square statistic, degrees of freedom and p-value, with expected-count conditions checked.
Run Goodness-of-Fit Test →What is a Chi-Square Goodness-of-Fit Test?
A chi-square goodness-of-fit test compares the observed frequencies across the categories of a single categorical variable against a set of expected frequencies derived from a hypothesized distribution. It answers whether the data fits the expected pattern or departs from it significantly.
The expected distribution can be uniform (all categories equally likely), based on a theoretical model, or based on known population proportions. The test sums a standardized measure of the gap between observed and expected counts in each category to form the chi-square statistic.
A large chi-square statistic, and correspondingly small p-value, means the observed counts differ from what the hypothesized distribution predicts by more than chance would explain. The test relies on adequate expected counts in each category to be valid.
In plain terms: You have counts across a few categories and an idea of what they should look like, say, evenly split, or matching last year. This test checks whether reality matches that expectation or is far enough off that something real is going on.
Key Points
One Categorical Variable
Tests the distribution of a single variable's categories against expected proportions. For association between two variables, use the independence test.
Expected Distribution
Expected counts may be equal, theoretical, or from known proportions. The test measures departure from that expectation.
Expected-Count Condition
A common rule: expected counts should be at least 5 in each category (or most categories) for the approximation to hold.
Key Formulas
Interpreting the Result
The null hypothesis is that the data follows the expected distribution. A small p-value means the fit is poor: observed counts deviate from expected by more than chance allows, so you reject the hypothesized distribution.
Examine which categories contribute most to the chi-square statistic. Large (O minus E) squared over E terms show where the data departs most from expectation, which is often more informative than the overall p-value alone.
Assumptions & Validation
Categorical Counts
The data are counts of independent observations in mutually exclusive categories.
If violated: Do not apply to percentages or continuous data directly.
Adequate Expected Counts
Expected counts are large enough (commonly at least 5 per category).
If violated: Combine sparse categories or use an exact test.
Independence
Each observation falls in exactly one category and is independent of the others.
If violated: Repeated or paired counts need a different method.
⚠️ Check assumptions first
The chi-square approximation degrades when expected counts are small, a common rule being that each expected count should be at least 5. With sparse categories the p-value becomes unreliable. Combine small categories where it makes sense, or use an exact test. Also remember the test works on raw counts, not percentages; converting to percentages first invalidates it.
When NOT to Use Chi-Square Goodness-of-Fit Test
Two Variables
To test association between two categorical variables, use the chi-square test of independence.
Small Expected Counts
When expected counts are low, use an exact test rather than the chi-square approximation.
Continuous Distribution Fit
To test whether continuous data fits a distribution, the Kolmogorov-Smirnov or Shapiro-Wilk test is more appropriate.
Industry Applications
Fairness & Uniformity
Test whether outcomes are equally likely, such as whether a die or a process is unbiased across categories.
Distribution Conformance
Check whether observed category shares match known or expected proportions.
Quality Categories
Test whether defect-type counts follow an expected pattern.
Survey Responses
Compare observed response distributions against a hypothesized or historical split.
Frequently Asked Questions
What is the difference between the goodness-of-fit and independence chi-square tests?
The goodness-of-fit test examines a single categorical variable, comparing its observed category counts against an expected distribution such as equal proportions or a theoretical model. The test of independence examines two categorical variables in a contingency table, testing whether they are associated. Both use the same chi-square formula and distribution, but they answer different questions: fit to an expectation versus association between variables.
What expected distribution can I test against?
The expected distribution can be uniform, meaning all categories are equally likely, based on a theoretical model that predicts specific proportions, or based on known population proportions from external data. The test compares your observed counts against the expected counts implied by whichever distribution you specify, and judges whether the departure is larger than chance would produce.
What is the expected-count rule of thumb?
A widely used guideline is that the expected count in each category should be at least 5 for the chi-square approximation to be reliable. Some formulations allow a few categories to fall slightly below this as long as most meet it. When expected counts are too small, the approximation becomes inaccurate, and categories should be combined or an exact test used instead.
How are the degrees of freedom determined?
For a goodness-of-fit test, the degrees of freedom equal the number of categories minus one. If the expected distribution requires estimating parameters from the data, an additional degree of freedom is subtracted for each estimated parameter. The degrees of freedom determine the shape of the chi-square distribution used to compute the p-value.
Can I run a chi-square test on percentages?
No. The chi-square test must be performed on raw observed counts, not percentages or proportions. Converting to percentages discards the sample size information that the test depends on, and running the test on percentages produces meaningless results. Always enter the actual frequency counts, and let the test work with the totals directly.
What does a significant goodness-of-fit result tell me?
A significant result, indicated by a small p-value, means the observed counts depart from the expected distribution by more than sampling variation would explain, so you reject the hypothesis that the data follows that distribution. To understand where the misfit occurs, examine the individual category contributions to the chi-square statistic, since large contributions pinpoint the categories driving the departure.
Test Whether Data Fits an Expected Distribution
Run a chi-square goodness-of-fit test with full diagnostics. Free during Beta.
Run Goodness-of-Fit Test →