Goodness-of-Fit Testing

Statistics
Introduced by
Karl Pearson
Year
1900
Type
Hypothesis testing framework for model adequacy
Family
Statistical testing

What does it do?

Goodness-of-fit (GOF) testing is a family of hypothesis tests that assess whether observed data are consistent with a specified probability distribution or model.

Karl Pearson's chi-square test (1900) is the earliest widely used form, comparing observed and expected counts across categories. A GOF test yields a p-value for the discrepancy between data and model, but it does not by itself measure how well the model fits in practical terms. The term should not be confused with regression goodness of fit (R-squared), which summarises how much of the variation in the dependent variable a linear regression explains. The distributional tests on this page answer a different question.

The intuition behind the method

A goodness-of-fit test asks how surprising the observed data would be if the hypothesised model were true. It computes a statistic that measures the gap between the data and the model's expected values, then compares that statistic with its distribution under the null hypothesis. A small p-value means a gap this large would be unlikely under the model, which is evidence against it. A large p-value means the data are not inconsistent with the model at the chosen significance level; it does not establish that the model is correct.

History

Karl Pearson introduced the chi-square goodness-of-fit test in 1900 as a way to compare observed and expected frequencies. Later procedures for continuous data, including the Kolmogorov-Smirnov test, the Anderson-Darling statistic and the Shapiro-Wilk test for normality, provide alternatives to the chi-square approach when observations are not naturally grouped into counts. Such tests are now available in most statistical software.

When to use it

Choose a GOF test when the question is whether a specified distribution or model is compatible with a sample, for example when checking a distributional assumption before a parametric analysis, or whether regression residuals match an assumed error distribution. Use the chi-square test for counts in categories or bins. Its chi-square reference distribution is adequate only when no cell sizes are too small, so sparse bins should be merged before testing. For continuous data against a fully specified distribution, use Kolmogorov-Smirnov or Anderson-Darling. For normality specifically, Shapiro-Wilk is more powerful than either the general chi-square or Kolmogorov-Smirnov tests and is the preferable choice. Do not rely on the test alone with large samples, because it will flag trivial deviations; pair it with Q-Q plots or histograms. If the model parameters are estimated from the same data, the standard reference distributions no longer apply without adjustment: for the chi-square test the degrees of freedom are reduced accordingly, and for continuous-distribution tests a variant designed for estimated parameters is needed. The test also assumes independent sampling, so it is not appropriate for strongly dependent data.

Limitations and considerations

  • Power depends on sample size: large samples detect small deviations that may be practically irrelevant, while small samples can miss substantial misfit.
  • Assumes the null model is completely specified; when parameters are estimated from the same data, the usual reference distributions are not valid without adjustment.
  • A non-significant result does not show that the model is correct; it shows only that the data give no evidence against it at the chosen level.
  • The p-value does not measure the size or shape of the deviation; two different models can yield similar p-values while departing from the data in very different ways.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Gives a formal decision rule: the p-value is compared with a significance level chosen before the analysis.
  • Several variants suit different data types: chi-square for categorised counts, Kolmogorov-Smirnov and Anderson-Darling for continuous distributions, and Shapiro-Wilk for normality.
  • The chi-square statistic is built from observed and expected counts category by category, so each category's contribution to the discrepancy can be inspected.
  • A rejection gives a formal basis for model criticism, indicating that the specified model is inconsistent with the data.

Applications

  • Quality control: testing whether manufacturing measurements are consistent with a normal distribution before applying control chart rules.
  • Epidemiology: checking whether counts of cases across areas fit a Poisson model, as a first step before looking for clustering.
  • Finance: testing whether stock returns are consistent with a normal distribution, as a check on the assumptions of portfolio risk models.
  • Regression diagnostics: checking whether residuals are consistent with an assumed error distribution, such as normality. Constancy of residual variance is not assessed by a GOF test and requires a separate diagnostic.
  • Survival analysis: testing whether time-to-event data are consistent with a hypothesised distribution such as the Weibull or exponential.

How it works

How it works

1

Compute a statistic that measures the discrepancy between observed data and model predictions. For the chi-square test this is the sum, over categories, of the squared difference between observed and expected counts divided by the expected count. For the Kolmogorov-Smirnov test it is the largest vertical distance between the empirical and the hypothesised cumulative distribution functions.

Formula
T = \chi^2 = \sum_{i} \frac{(O_i - E_i)^2}{E_i}
2

Under the null hypothesis that the model is correct, the statistic follows a known reference distribution, such as the chi-square distribution for binned counts when expected counts are adequate, or a Kolmogorov-type distribution for a fully specified continuous model. These reference distributions hold only under their stated assumptions, including that the model parameters are known rather than estimated from the same data. When the chi-square test is applied with parameters estimated from the data, the degrees of freedom are reduced by the number of estimated parameters.

Formula
T \sim \chi^2, \text{KS}, \text{AD, or other under } H_0
3

Compute the p-value as the probability, assuming the model is true, of a test statistic at least as large as the observed value, P(T ≥ T_obs | H0).

Formula
p\text{-value} = P(T_{\text{obs}} | H_0 \text{ true})

Common pitfalls

  • Treating p > 0.05 as proof that the model is correct; a non-rejection reflects limited evidence, not confirmation.
  • Ignoring effect size: a statistically significant result may reflect a deviation too small to matter for the analysis.
  • Comparing statistics from different GOF tests as if they shared a scale or reference distribution; each test has its own distribution and its own sensitivity to particular kinds of misfit.
  • Applying the test to dependent or non-random samples, such as autocorrelated time series, where the independence assumption fails.
  • Estimating parameters from the data and then reading p-values from standard tables, which gives p-values that are not valid for the test as stated.

Frequently asked questions

What does p > 0.05 really mean in a GOF test?

If the model were true, a statistic at least as extreme as the one observed would occur with probability greater than 0.05. This does not mean the model is correct, and it does not mean the data deviate from the model only 5% of the time. It means the data give no strong evidence against the model at the 0.05 level, and many other models may fit equally well.

Why do large samples reject models that seem to fit well?

Test power increases with sample size. Large samples detect tiny deviations; a model may be practically adequate but statistically significantly different. Always combine GOF tests with visual inspection (Q-Q plots, residual plots).

Which GOF test should I use?

Depends on context: chi-square for discrete or categorised data, provided no cell sizes are too small; Kolmogorov-Smirnov or Anderson-Darling for continuous data against a fully specified distribution; and Shapiro-Wilk for normality, where it is more powerful than the general tests. Check your specific question and data type; consult software documentation.

Can I use multiple GOF tests on the same data?

Avoid multiple hypothesis testing on the same data; you inflate false positive risk. If testing multiple hypotheses, apply correction methods (Bonferroni, Holm). Better to choose one pre-specified test.

Does GOF testing replace visual inspection?

No. Combine both: GOF tests provide formal hypothesis testing, but residual plots, Q-Q plots, and histograms reveal the nature and magnitude of deviations. Together they give complete diagnostic insight.

Related methods

Sources

  1. Pearson, K. (1900). On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. Philosophical Magazine, 50(302), 157-175.

    Open DOI reference
  2. Cramér, H. (1928). On the composition of elementary errors. Skandinavisk Aktuarietidskrift, 11, 141-180.

    Open publication reference
  3. Kolmogorov, A. N. (1933). Sulla determinazione empirica di una legge di distribuzione. Giornale dell'Istituto Italiano degli Attuari, 4, 83-91.

    Open publication reference
  4. 2015_Book_StatisticalAnalysisAndDataDisp, p. 149

  5. Econometrics in Theory and Practice: Analysis of Cross Section, Time Series and Panel Data with Stata 15.1 (2019), Sect. 3.2