17.11.2012 Views

Numerical recipes

Numerical recipes

Numerical recipes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

662 Chapter 15. Modeling of Data<br />

This problem is often called linear regression, a terminology that originated, long<br />

ago, in the social sciences. We assume that the uncertainty σi associated with<br />

each measurement yi is known, and that the xi’s (values of the dependent variable)<br />

are known exactly.<br />

To measure how well the model agrees with the data, we use the chi-square<br />

merit function (15.1.5), which in this case is<br />

χ 2 (a, b) =<br />

N�<br />

�<br />

yi − a − bxi<br />

i=1<br />

σi<br />

� 2<br />

(15.2.2)<br />

If the measurement errors are normally distributed, then this merit function will give<br />

maximum likelihood parameter estimations of a and b; if the errors are not normally<br />

distributed, then the estimations are not maximum likelihood, but may still be useful<br />

in a practical sense. In §15.7, we will treat the case where outlier points are so<br />

numerous as to render the χ 2 merit function useless.<br />

Equation (15.2.2) is minimized to determine a and b. At its minimum,<br />

derivatives of χ 2 (a, b) with respect to a, b vanish.<br />

0= ∂χ2<br />

∂a<br />

0= ∂χ2<br />

∂b<br />

= −2<br />

= −2<br />

N�<br />

i=1<br />

N�<br />

i=1<br />

yi − a − bxi<br />

σ 2 i<br />

xi(yi − a − bxi)<br />

σ 2 i<br />

(15.2.3)<br />

These conditions can be rewritten in a convenient form if we define the following<br />

sums:<br />

S ≡<br />

N�<br />

1<br />

σ<br />

i=1<br />

2 i<br />

N�<br />

x<br />

Sxx ≡<br />

i=1<br />

2 i<br />

σ2 i<br />

N�<br />

xi<br />

Sx ≡<br />

σ<br />

i=1<br />

2 i<br />

Sxy ≡<br />

With these definitions (15.2.3) becomes<br />

N�<br />

i=1<br />

xiyi<br />

σ 2 i<br />

aS + bSx = Sy<br />

aSx + bSxx = Sxy<br />

N�<br />

yi<br />

Sy ≡<br />

σ<br />

i=1<br />

2 i<br />

The solution of these two equations in two unknowns is calculated as<br />

∆ ≡ SSxx − (Sx) 2<br />

a = SxxSy − SxSxy<br />

∆<br />

b = SSxy − SxSy<br />

∆<br />

Equation (15.2.6) gives the solution for the best-fit model parameters a and b.<br />

(15.2.4)<br />

(15.2.5)<br />

(15.2.6)<br />

Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)<br />

Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by <strong>Numerical</strong> Recipes Software.<br />

Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copying of machinereadable<br />

files (including this one) to any server computer, is strictly prohibited. To order <strong>Numerical</strong> Recipes books or CDROMs, visit website<br />

http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!