F = 0.01 0.05 0.10 0.50 0.90 0.95 0.99

ν

1 0.000 0.004 0.016 0.455 2.706 3.841 6.635

2 0.005 0.051 0.105 0.693 2.303 2.996 4.605

3 0.038 0.117 0.195 0.789 2.084 2.605 3.782

4 0.074 0.178 0.266 0.839 1.945 2.374 3.319

5 0.111 0.229 0.322 0.870 1.847 2.214 3.017

6 0.145 0.273 0.367 0.891 1.774 2.099 2.802

7 0.177 0.310 0.405 0.907 1.717 2.010 2.639

8 0.206 0.342 0.436 0.918 1.670 1.938 2.511

9 0.232 0.369 0.463 0.927 1.632 1.880 2.407

10 0.256 0.394 0.487 0.934 1.599 1.831 2.321

11 0.278 0.416 0.507 0.940 1.570 1.789 2.248

12 0.298 0.436 0.525 0.945 1.546 1.752 2.185

13 0.316 0.453 0.542 0.949 1.524 1.720 2.130

14 0.333 0.469 0.556 0.953 1.505 1.692 2.082

15 0.349 0.484 0.570 0.956 1.487 1.666 2.039

20 0.413 0.543 0.622 0.967 1.421 1.571 1.878

25 0.461 0.584 0.659 0.973 1.375 1.506 1.773

30 0.498 0.616 0.687 0.978 1.342 1.459 1.696

40 0.554 0.663 0.726 0.983 1.295 1.394 1.592

50 0.594 0.695 0.754 0.987 1.263 1.350 1.523

60 0.625 0.720 0.774 0.989 1.240 1.318 1.473

70 0.649 0.739 0.790 0.990 1.222 1.293 1.435

80 0.669 0.755 0.803 0.992 1.207 1.273 1.404

90 0.686 0.768 0.814 0.993 1.195 1.257 1.379

100 0.701 0.779 0.824 0.993 1.185 1.243 1.358

∞ 1 ’ c 1 ’√ 1 ’ a 1

b √1 + a 1 + b 1 + c

√

a = 1.81/ ν b = 2.32/ ν c = 3.29/ ν

number of degrees of freedom ν is not necessarily equal to the number of

data points over which the square deviations are summed; correlation be-

tween the points and the “use” of data points to determine parameters in

a function to which the data are ¬tted, will decrease the number of e¬ec-

tive degrees of freedom. For example, if a straight line (two parameters) is

¬tted to two points, there are no deviations and no degrees of freedom; if

a straight line is ¬tted to n independent data points, there are only n ’ 2

534 Splines for everything

degrees of freedom. If we would duplicate every data point, the values of χ2

and of n would both double, but χ2 /n would not change, and neither would

the number of degrees of freedom change. The e¬ective number of degrees

of freedom equals the number of data points divided by a correlation length

of the data and reduced by the number of (independent) parameters in the

¬tted function.

It is clear that a criterium based on acceptance of a χ2 -value does not

su¬ce to choose the parameters of a model. In the context of splines we

choose the additional criterium to minimize the curvature of the constructed

function. We choose natural splines, as these have the least curvature among

all splines through the same points.6 The total curvature C of a cubic spline

is given by

n’1

xn xn hi

f |xn ’ f f dx = ’

2

C= (f ) dx = f fi fi dξ

x0

x0 x0 0

i=0

n’1 n’1

hi

= ’6 fi dξ = ’6 qi (fi+1 ’ fi ).

qi (19.34)

0

i=0 i=0

This can be rewritten as

n’1 n

(qi ’ qi’1 )fi ’ qn’1 fn = 6

C = 6 q0 f0 + δi fi , (19.35)

i=1 i=0

where

δi = qi ’ qi’1 , i = 1, . . . , n ’ 1,

δn = ’qn’1 .

δ 0 = q0 , (19.36)

In order to minimize C while χ2 is to be constrained at a given value, we

use a Lagrange multiplier 7 » and minimize the function C + »χ2 :

n

(yi ’ fi )2

Minimize δi fi + » . (19.37)

2

σi

0

Here we have absorbed the constant 6 in the Lagrange multiplier. Note

that the variables are fi , i = 0, . . . , n, while the δi ™s follow from the spline

through fi ; yi and σi are constants. For » an initial value is chosen, and the

6 There are circumstances that external knowledge would imply other boundary conditions than

vanishing second derivatives, e.g. in the case of periodic conditions. It is possible to construct

programs for other boundary conditions, but in general one may choose some extra points at,

or just beyond, the boundaries such that certain prescribed conditions will be ful¬lled.

7 This is the standard way to optimize a function in the presence of a constraint. For its use see

Chapter 17, footnote on page 456.

19.3 Fitting splines 535

procedure is iterated until the desired value of χ2 is obtained. Since χ2 is a

statistical quantity, it may well happen that the desired value of χ2 is not

even reached with the smoothest possible curve (a straight line with C = 0);

in that case the straight line is an acceptable least squares ¬t to a linear

function.

In order to solve (19.37), we solve the set of equations obtained by setting

the derivatives to all fk equal to zero:

n

yk ’ fk

‚δi

’ 2»

δk + fi = 0, k = 1, . . . , n. (19.38)

2

‚fk σk

i=0

Now, it is easy to show that δ is a homogeneous linear function of f : δ = Mf .

The matrix M appears to be symmetric, as can be shown by a straightfor-

ward but cumbersome inspection of the matrices M is composed of. We

leave the proof to the interested reader. Since ‚δi /‚fk = Mik = Mki , the

second term in (19.38) equals Mki fi = δk . Thus

yk ’ fk

» = δk , i = 0, . . . , n, (19.39)

2

σk

is the condition to be imposed on the spline parameters to obtain the

smoothest curve (in terms of least curvature) with a constrained value of

χ2 . By varying », the smoothest curve that is statistically compatible with

the data is obtained.

Equation (19.39), together with (19.10), expressing q in f and g, and the

continuity conditions that lead to the matrix equation (19.12) or (19.26),

yields a matrix equation from which the spline parameters can be solved.

The equation is now ¬ve-diagonal but symmetric; complete expressions can

be found in Engeln-M¨llges and Uhlig (1996), who also give expressions for

u

di¬erent boundary conditions. A Python program is given in Section 19.6.

Figure 19.4 shows ¬tting splines through 11 points that were generated as

normal-distributed random deviations from the parabola y = 0.2x2 . Three

¬tting splines were generated with di¬erent overall weight factors for the

data points: w = 1000 yields a spline through the points; w = 0.2 yields a

value of χ2 /n approximately equal to the mean expectation 1; w = 0.001

yields a least squares ¬t to an (almost) straight line. Note that the “best”