Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

8. Hypothesis tests and goodness of fit

School of Engineering, Nazarbayev University

Track: core  ·  Prerequisites: Chapters 4 and 5

Reading: Taylor, ch. 5.8, 9 and 12 · Bevington & Robinson, ch. 4.4 and 11 · Fornasini, ch. 9 to 11 · Rouaud, ch. I.G and I.H

Error analysis constantly asks yes-or-no questions. Does the result agree with theory? Do two laboratories agree? Are these readings normally distributed? Does the fit need a quadratic term? Is there a correlation? A hypothesis test turns such a question into a probability statement. This chapter sets out the logic once and then applies it to the tests that experimenters use most:

  1. the logic of a test: null hypothesis, test statistic, pp-value, and the two kinds of error;

  2. comparing results: the zz and tt tests;

  3. the χ2\chi^2 test of a distribution;

  4. the FF test, for comparing variances and for deciding whether a model needs another parameter;

  5. the linear correlation coefficient;

  6. what goes wrong when many tests are made.

8.1 The logic of a test

  1. State a null hypothesis H0H_0, usually the “nothing new” option: the result agrees with theory, the two methods measure the same thing, the data are normal.

  2. Choose a test statistic whose distribution is known if H0H_0 is true: for example z=∣x1−x2∣/u12+u22z = |x_1 - x_2|/\sqrt{u_1^2 + u_2^2}, standard normal under H0H_0 (Section 1.6).

  3. Compute the pp-value: the probability, if H0H_0 were true, of a value of the statistic at least as extreme as the one observed.

  4. If pp is below a significance level α\alpha chosen in advance (often 0.05), reject H0H_0.

Two kinds of error are possible. A type I error rejects a true null hypothesis; it happens with probability α\alpha by construction. A type II error fails to reject a false one; its probability depends on how far the truth is from H0H_0 and on how much data there is. One minus that probability is the power of the test.

Three misreadings are common enough to name.

  • The pp-value is not the probability that H0H_0 is true. It is a probability about the data, computed assuming H0H_0.

  • A large pp-value does not prove H0H_0; it may only mean that the test had too little power to see a real effect.

  • A small pp-value does not mean the effect is large; with enough data any tiny difference becomes “significant”. Always quote the size of the effect with its uncertainty as well.

If H0H_0 is true and the statistic’s distribution is right, the pp-value is uniformly distributed between 0 and 1: a fraction α\alpha of all experiments fall below α\alpha. A simulation shows this, together with the power of a zz test for a real difference of 1.5 and 3 standard uncertainties.

true difference 0.0 u: P(p < 0.05) = 0.050
true difference 1.5 u: P(p < 0.05) = 0.322
true difference 3.0 u: P(p < 0.05) = 0.851

With no real difference, 5 % of experiments cross the threshold, as designed. A real difference of 1.5 standard uncertainties is detected only a third of the time; a difference of 3 is detected 85 % of the time. A “non-significant” result is therefore weak evidence of agreement unless the test had good power for the size of difference that would matter.

8.2 Comparing results: zz and tt

When the standard uncertainties are known, the zz statistic of Section 1.6 is the right test. When they are themselves estimated from small samples, the statistic follows Student’s tt distribution instead (Section 5.5), and using normal probabilities overstates the significance.

For two means xˉ1\bar x_1, xˉ2\bar x_2 from samples of sizes N1N_1, N2N_2 with sample standard deviations s1s_1, s2s_2, the Welch test uses

t=xˉ1−xˉ2s12/N1+s22/N2t = \frac{\bar x_1 - \bar x_2}{\sqrt{s_1^2/N_1 + s_2^2/N_2}}

with an effective number of degrees of freedom given by the Welch–Satterthwaite formula,

νeff=(s12/N1+s22/N2)2(s12/N1)2N1−1+(s22/N2)2N2−1,\nu_\text{eff} = \frac{(s_1^2/N_1 + s_2^2/N_2)^2}{\dfrac{(s_1^2/N_1)^2}{N_1 - 1} + \dfrac{(s_2^2/N_2)^2}{N_2 - 1}} ,

the same formula the GUM uses for the effective degrees of freedom of a combined uncertainty.

difference -0.0595 +/- 0.0197 m/s^2
treated as z (normal): p = 0.0025
Welch t test         : t = 3.02, p = 0.0214

The normal approximation would report the difference as more significant than it is, because it ignores the uncertainty of ss from four or five readings.

8.3 The χ2\chi^2 test of a distribution

Are a set of readings consistent with a proposed distribution, for example a normal one? Sort the NN readings into kk bins; let OjO_j be the observed and EjE_j the expected number in bin jj. If the proposed distribution is right, each OjO_j fluctuates about EjE_j with variance close to EjE_j (Poisson), so

χ2=∑j=1k(Oj−Ej)2Ej\chi^2 = \sum_{j=1}^{k}\frac{(O_j - E_j)^2}{E_j}

follows approximately the χ2\chi^2 distribution with ν=k−1−c\nu = k - 1 - c degrees of freedom: one is lost because the total is fixed, and cc more for the parameters estimated from the data (two for a normal distribution with fitted μ\mu and σ\sigma). The approximation requires Ej≳5E_j \gtrsim 5 in every bin; merge bins in the tails if necessary (Taylor, ch. 12).

Below, 500 readings are tested against a normal distribution: once when they are normal, once when they come from a distribution with heavier tails (Student’s tt with 4 degrees of freedom, scaled to the same standard deviation). The test is then repeated on many samples of different sizes to find how often it rejects each.

normal readings       : chi2 =   3.0 for 5 dof, p = 0.7027
   observed: [31 44 86 88 99 76 42 34] 
   expected: [33.4 45.9 74.9 95.7 95.7 74.9 45.9 33.4]
heavy-tailed readings : chi2 =  26.2 for 5 dof, p = 0.0001
   observed: [ 27  41  58 130 111  75  32  26] 
   expected: [33.4 45.9 74.9 95.7 95.7 74.9 45.9 33.4]

fraction of samples rejected at the 5 % level (1000 samples each)
   N     normal    heavy-tailed
  100     0.056      0.332
  200     0.062      0.586
  500     0.058      0.961
 1000     0.070      0.999

The heavy-tailed sample has too many readings near the centre and too few on the shoulders. (Even its outermost bins look underpopulated, because the standard deviation used to place the bins was inflated by a few extreme readings.) The test detects the difference. The table shows the price of a modest sample: with 100 or 200 readings, the test misses the heavy tails in a large fraction of samples. (Its false-alarm rate for truly normal data is slightly above 5 %, because μ\mu and σ\sigma were estimated from the unbinned readings; the loss of exactly two degrees of freedom is an approximation.) Tests of normality with more power for small samples exist (Shapiro–Wilk is a standard choice), and a normal probability plot, the sorted readings against normal quantiles, is often more informative than any single number.

The same statistic, written as χ2=∑(yi−fi)2/σi2\chi^2 = \sum (y_i - f_i)^2/\sigma_i^2, is the goodness of fit of a least-squares fit (Section 11.4), with ν=N−p\nu = N - p for pp fitted parameters. Its expected value is ν\nu and its standard deviation 2ν\sqrt{2\nu}, so a reduced chi-square of 1.3 is unremarkable for 10 degrees of freedom (p=0.22p = 0.22) and a clear failure for 200 (p=0.002p = 0.002).

reduced chi-square 1.3 with  10 dof: p = 0.2237
reduced chi-square 1.3 with  50 dof: p = 0.0754
reduced chi-square 1.3 with 200 dof: p = 0.0028

8.4 The FF test

Comparing two variances. If s12s_1^2 and s22s_2^2 come from N1N_1 and N2N_2 normal readings with the same true variance, F=s12/s22F = s_1^2/s_2^2 follows the FF distribution with (N1−1,N2−1)(N_1 - 1, N_2 - 1) degrees of freedom. Is a new instrument really more precise than the old one?

Does a model need another term? Fit the data with a model of p1p_1 parameters, then with a larger one of p2>p1p_2 > p_1 that contains the first as a special case (a quadratic containing a straight line). The extra parameters always reduce χ2\chi^2, even if they are not needed. The question is whether they reduce it by more than chance would. With known uncertainties, the reduction Δχ2=χ12−χ22\Delta\chi^2 = \chi^2_1 - \chi^2_2 is itself χ2\chi^2-distributed with p2−p1p_2 - p_1 degrees of freedom if the smaller model is right. With uncertainties estimated from the scatter, the ratio

F=Δχ2/(p2−p1)χ22/(N−p2)F = \frac{\Delta\chi^2/(p_2 - p_1)}{\chi^2_2/(N - p_2)}

follows the FF distribution with (p2−p1,N−p2)(p_2 - p_1, N - p_2) degrees of freedom (Bevington & Robinson, ch. 11.4). Below, ten points with a slight curvature are tested for the need for a quadratic term.

quadratic term: F = 2.4, p = 0.1665
power to detect the quadratic term: c = 0.25 -> 0.23, 0.5 -> 0.69, 0.75 -> 0.95

The power is lower than one might expect. A quadratic term cx2cx^2 on 0≤x≤10 \le x \le 1 raises yy by cc at the end of the range, but most of it is absorbed by the slope and intercept of the straight line: the part that a line cannot reproduce is only about c/6c/6 at the ends and c/12c/12 in the middle. With c=0.5c = 0.5 that is 0.08, less than twice the noise of a single point, and ten points detect it about two times in three. The data set above happens to be one of the other third: the curvature is real, but this test on these data cannot establish it (p=0.17p = 0.17).

8.5 The linear correlation coefficient

For NN pairs (xi,yi)(x_i, y_i) the correlation coefficient

r=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2∑(yi−yˉ)2r = \frac{\sum (x_i - \bar x)(y_i - \bar y)}{\sqrt{\sum (x_i - \bar x)^2\sum (y_i - \bar y)^2}}

lies between -1 and 1. It answers one narrow question: is there evidence of a linear relation at all? If xx and yy are independent, rr scatters around zero with a width of about 1/N1/\sqrt{N}, and the probability of ∣r∣|r| exceeding an observed value can be computed from the statistic t=r(N−2)/(1−r2)t = r\sqrt{(N-2)/(1 - r^2)}, which has a tt distribution with N−2N-2 degrees of freedom (Taylor, ch. 9.4 and Appendix C, tabulates these probabilities).

N =   5: |r| > 0.878 needed for significance at 5 %
N =  10: |r| > 0.632 needed for significance at 5 %
N =  30: |r| > 0.361 needed for significance at 5 %
N = 100: |r| > 0.197 needed for significance at 5 %

With five points, ∣r∣=0.8|r| = 0.8 can arise by chance more than one time in ten. With a hundred, ∣r∣=0.2|r| = 0.2 is significant. The coefficient is not a measure of how good a fit is, nor of whether two methods agree: two instruments whose readings differ by a factor of 2 are perfectly correlated. The fit residuals and χ2\chi^2 answer those questions (Section 11.6).

8.6 Many tests at once

A test at the 5 % level wrongly rejects a true hypothesis once in twenty. Make twenty independent tests and the chance of at least one false alarm is 1−0.9520=64 %1 - 0.95^{20} = 64\,\%. Searching a spectrum for a peak in any of 100 positions, trying several fit models, or testing many samples all invite this trap, which particle physicists call the look-elsewhere effect. The simplest protection (Bonferroni) is to divide α\alpha by the number of tests; more refined procedures exist. The essential point is to report how many tests were made, including the unsuccessful ones.

tests:                   1      5     10     20     50    100
P(>= 1 false alarm):  0.05   0.23   0.40   0.64   0.92   0.99
<Figure size 1012x792 with 4 Axes>

(a) Distribution of pp-values: uniform when H0H_0 is true (blue), piled up near zero when it is false. (b) The χ2\chi^2 test of Section 8.3 for the heavy-tailed sample. (c) Power of the FF test for a quadratic term with ten points of noise 0.05. (d) Distribution of the correlation coefficient of uncorrelated data for several sample sizes.

Summary

  • A pp-value is the probability of data at least as extreme as observed if H0H_0 is true; it is not the probability that H0H_0 is true.

  • Non-significance means little without power; significance means little without the size of the effect.

  • Use tt, not zz, when the uncertainties come from small samples.

  • The χ2\chi^2 test compares data with a distribution or a model; count the degrees of freedom carefully, and know that χν2\chi^2_\nu scatters by 2/ν\sqrt{2/\nu}.

  • The FF test decides whether extra parameters are justified.

  • rr tests for the presence of a linear relation, not for agreement.

  • Report the number of tests made.

Exercises

  1. Two thermometers are compared at 12 temperatures; the standard deviations of their readings about the mean are 0.21 K and 0.13 K. Is the second one significantly more precise?

  2. Repeat the χ2\chi^2 test of Section 8.3 on 1000 independent heavy-tailed samples of 200 readings. What fraction is rejected? With 1000 readings per sample?

  3. Simulate data from a straight line and apply the FF test for a quadratic term many times. Verify that it rejects the straight line in 5 % of cases.

  4. A student finds r=0.995r = 0.995 between the readings of a new and a reference thermometer and concludes that the new one is accurate. What should be computed instead?

  5. A peak search tests 200 independent channels at the 3σ level. How many false peaks are expected? At what local significance should a peak be claimed so that the global false-alarm probability is 1 %?