Chi Square Goodness of Fit Test
Calculate a chi square goodness of fit statistic, degrees of freedom and approximate p value from observed and expected counts.
Goodness of fit
The chi square goodness of fit test compares observed category counts with counts expected under the null hypothesis. Each category contributes (O − E)²/E and the statistic is their sum. Expected counts are not probabilities. For sixty observations and three equally likely categories, expected counts are 20, 20, 20.
Example and degrees of freedom
Observed counts 15, 20, 25 give a statistic of 2.5. If no distribution parameters were estimated from these data, degrees of freedom are 3 − 1 = 2 and the approximate p value is 0.286505. Fitting q parameters from the same data reduces degrees of freedom to k − 1 − q.
Validity
Expected counts must be sufficiently large. The approximate p value can be misleading for sparse categories. The calculator does not verify this condition or the independence of observations. It displays the smallest expected count for review. Contingency tables and variance tests are outside its scope.
Inspect each category's contribution
Do not adjust the expected distribution arbitrarily after looking at the observed list. First specify the probabilities assigned to categories by the null hypothesis. Multiply them by the observation total to obtain expected counts. Categories must follow the same order in both lists. A different order can preserve totals while changing the comparison.
For an illustrative example, observed counts are 12, 18 and 30 and expected counts are 20, 20 and 20. Both totals are 60. Contributions are 64/20 = 3.2, 4/20 = 0.2 and 100/20 = 5, giving a statistic of 8.4. With no fitted parameters, degrees of freedom are 2. At this particular degree count, the upper tail is exp(−8.4/2), giving approximately p = 0.014996.
The last category contributes most, but this alone does not explain the cause. Squaring removes the direction of deviations. Inspect category counts and residuals too. With more observations, the same proportional difference can produce a larger statistic. Do not confuse p with practical effect size. Combining categories in response to results changes the analysis plan and requires separate justification.
Frequently asked questions
How do you calculate a chi square test for goodness of fit?
In this example, observed counts 15 20 25 and expected counts 20 20 20 give a chi square statistic of 2.5 and 2 degrees of freedom with 0 parameters estimated from the data. Sum squared observed minus expected differences divided by expected counts, checking independence and adequate expected counts separately.
Related calculators
-
Statistics and Data Analysis
Hypothesis Test and p Value
Calculate a p value from a known z, t, chi square or F statistic and compare it with your significance level. -
Statistics and Data Analysis
Binomial and Poisson Distributions
Calculate exact count, cumulative and upper tail probabilities, plus the mean and variance of discrete event counts. -
Statistics and Data Analysis
Confidence Interval for a Mean
Calculate a confidence interval from summary statistics. Use a normal interval for known population deviation or a t interval for sample deviation. -
Statistics and Data Analysis
Data Charts and Moving Average
Create histograms, box plots, scatter plots and trailing moving averages. Download data as CSV and charts as SVG. -
Statistics and Data Analysis
Descriptive Statistics Calculator
Find the mean, median, modes, sample and population variance, standard deviation, quartiles and percentiles from a data list. -
Statistics and Data Analysis
Linear Interpolation and Extrapolation
Find y at an x value between or beyond two known points, together with the slope and relative position.
Found a mistake or something missing?
If a value looks wrong, a size is missing or you need a feature, write to us and we will fix it.