Goodness-of-Fit Tests: Chi-Square & Kolmogorov–Smirnov
Goodness-of-fit tests measure a particular discrepancy between observed data and a fully stated distributional model. Chi-square compares binned counts; Kolmogorov–Smirnov compares cumulative distributions, and each has failure modes that matter more than the convenience of a p-value.
A goodness-of-fit (GOF) test asks whether data are compatible with a specified probability model. It does not certify that the model is true. Every finite dataset is compatible with many alternatives, and every imperfect model will eventually be rejected with enough data. The useful question is whether the discrepancy measured by the chosen statistic is too large to attribute to sampling variation under the null model.
The chi-square and Kolmogorov–Smirnov (KS) tests look similar only at the decision layer. They compare different objects and are sensitive to different departures.
The common testing mechanism #
A GOF procedure needs four explicit pieces:
- A null distribution or category probabilities .
- A statistic that compresses a discrepancy into one number.
- The sampling distribution of when the null is true, including any parameters estimated from the same data.
- A predeclared decision or diagnostic use.
The p-value is for a statistic where larger means worse fit. It is not , nor is the probability that an alternative is true.
Chi-square: discrepancy in counts #
For mutually exclusive categories, let be observed counts and expected counts under the null. Pearson's statistic is
Why divide by ? A deviation of ten counts is surprising when ten were expected but ordinary when ten thousand were expected. Under independent sampling and sufficiently informative expected counts, is approximately chi-square distributed.
If all category probabilities are specified in advance, the degrees of freedom are : once and counts are known, the last count is fixed. Estimating independent parameters from the same observations usually reduces this to . Ignoring that reduction makes the reference distribution wrong.
Worked count example #
Sixty throws of a proposed fair die give counts . The expected count is 10 in every cell:
With five degrees of freedom, this is far below the usual 5% critical value. The data do not provide evidence against fairness—but they also do not prove exact fairness. A die whose probabilities differ by tiny amounts could easily produce these counts.
Sparse expected cells undermine the chi-square approximation. The remedy is not blind adherence to a universal “five per cell” slogan: combine categories only when that preserves the scientific question, or compute an exact/Monte Carlo null distribution. Binning a continuous variable also discards information and makes the result depend on arbitrary cut points.
Kolmogorov–Smirnov: the largest CDF gap #
For a continuous sample , the empirical cumulative distribution function is
The one-sample KS statistic is
It measures the largest vertical separation between the empirical and hypothesized CDFs. Because a CDF integrates density, KS avoids bins and detects shifts in location, scale, or shape. It is usually most sensitive near the center and less sensitive in the tails.
The familiar distribution-free KS critical values apply to a continuous, fully specified . If a normal mean or variance is estimated from the tested sample, the ordinary KS calibration no longer applies; use an appropriate correction or a parametric bootstrap that repeats parameter estimation inside every simulated sample. Ties or discrete outcomes also change the null distribution.
flowchart TD H["State the complete null model"] --> S["Choose a discrepancy that sees the failure of interest"] S --> C["Calibrate it under the actual fitting procedure"] C --> P["Compute statistic and p-value"] P --> D["Inspect where and how the model misses"]
Choosing a test by the failure you care about #
| Question | Useful first tool | Blind spot |
|---|---|---|
| Do categorical frequencies match stated probabilities? | Chi-square or exact multinomial simulation | Categories may hide within-bin structure |
| Does a continuous sample match a fully specified CDF anywhere? | KS | Relatively weak tail sensitivity |
| Are tails especially important? | Tail-weighted statistics, quantile diagnostics, domain loss | A single global p-value may hide direction and cost |
| Were parameters fitted on these data? | Parametric bootstrap or a test with the correct fitted-null law | Textbook critical values are often invalid |
Always pair a test with an informative plot: observed versus expected counts with residuals, an empirical-versus-model CDF, a Q–Q plot, and tail diagnostics. The plot locates the failure that the p-value only ranks.
Counterexamples and misconceptions #
- Large samples reject harmless imperfections. If is a convenient approximation rather than a physical law, effect sizes and consequences matter more than eventual rejection.
- Small samples fail to detect consequential alternatives. “Not significant” can mean insufficient resolution.
- Trying many distributions and reporting the best p-value invalidates the nominal interpretation. Model selection has consumed the same data.
- A fitted histogram is not an independent null. Choosing bins after seeing the data changes the question.
- Passing normality does not validate a downstream model. Independence, variance structure, functional form, and measurement process may still fail.
A GOF test is therefore a calibrated diagnostic for one discrepancy—not a universal model-quality score.
Sources
- bookData Recognition and Classification: Lecture Notespdfnotes
- docsNIST/SEMATECH e-Handbook: Goodness of Fit
- docsNIST/SEMATECH e-Handbook: Chi-Square Goodness-of-Fit Test
- docsNIST/SEMATECH e-Handbook: Kolmogorov–Smirnov Test