15.7 Robust Estimation 699 M VitVki (15.6.10) CITED REFERENCES AND FURTHER READING: Efron,B.1982,The Jackknife,the Bootstrap,and Other Resampling Plans(Philadelphia:S.I.A.M.). [1] Efron,B..and Tibshirani,R.1986.Statistica/Science vol.1,pp.54-77.[2] Avni,Y.1976,Astrophysical Journal,vol.210,pp.642-646.[3] Lampton,M.,Margon,M.,and Bowyer,S.1976,Astrophysical Journal,vol.208,pp.177-190. Brownlee,K.A.1965,Statistical Theory and Methodology,2nd ed.(New York:Wiley). Martin,B.R.1971,Statistics for Physicists(New York:Academic Press) 15.7 Robust Estimation 、gad的 令 The concept of robustness has been mentioned in passing several times already. Press. In $14.I we noted that the median was a more robust estimator of central value than the mean:in 814.6 it was mentioned that rank correlation is more robust than linear correlation.The concept of outlier points as exceptions to a Gaussian model for experimental error was discussed in 815.1. The term "robust"was coined in statistics by G.E.P.Box in 1953.Various OF SCIENTIFIC definitions of greater or lesser mathematical rigor are possible for the term,but in general,referring to a statistical estimator,it means"insensitive to small departures from the idealized assumptions for which the estimator is optimized."[1,2]The word "small"can have two different interpretations,both important:either fractionally small departures for all data points,or else fractionally large departures for a small number of data points.It is the latter interpretation,leading to the notion of outlier points,that is generally the most stressful for statistical procedures. Numerica 10621 Statisticians have developed various sorts of robust statistical estimators.Many, if not most,can be grouped in one of three categories. 431 M-estimates follow from maximum-likelihood arguments very much as equa- Recipes tions(15.1.5)and (15.1.7)followed from equation(15.1.3).M-estimates are usually the most relevant class for model-fitting,that is,estimation of parameters.We (outside 腿 therefore consider these estimates in some detail below. North L-estimates are "linear combinations of order statistics."These are most applicable to estimations of central value and central tendency,though they can occasionally be applied to some problems in estimation of parameters.Two "typical"L-estimates will give you the general idea.They are(i)the median,and (ii)Tukey's trimean.defined as the weighted average of the first,second,and third quartile points in a distribution,with weights 1/4,1/2,and 1/4,respectively. R-estimates are estimates based on rank tests.For example,the equality or inequality of two distributions can be estimated by the Wilcoxon test of computing the mean rank of one distribution in a combined sample of both distributions. The Kolmogorov-Smirnov statistic (equation 14.3.6)and the Spearman rank-order
15.7 Robust Estimation 699 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). Cjk = M i=1 1 w2 i VjiVki (15.6.10) CITED REFERENCES AND FURTHER READING: Efron, B. 1982, The Jackknife, the Bootstrap, and Other Resampling Plans (Philadelphia: S.I.A.M.). [1] Efron, B., and Tibshirani, R. 1986, Statistical Science vol. 1, pp. 54–77. [2] Avni, Y. 1976, Astrophysical Journal, vol. 210, pp. 642–646. [3] Lampton, M., Margon, M., and Bowyer, S. 1976, Astrophysical Journal, vol. 208, pp. 177–190. Brownlee, K.A. 1965, Statistical Theory and Methodology, 2nd ed. (New York: Wiley). Martin, B.R. 1971, Statistics for Physicists (New York: Academic Press). 15.7 Robust Estimation The concept of robustness has been mentioned in passing several times already. In §14.1 we noted that the median was a more robust estimator of central value than the mean; in §14.6 it was mentioned that rank correlation is more robust than linear correlation. The concept of outlier points as exceptions to a Gaussian model for experimental error was discussed in §15.1. The term “robust” was coined in statistics by G.E.P. Box in 1953. Various definitions of greater or lesser mathematical rigor are possible for the term, but in general, referring to a statistical estimator, it means “insensitive to small departures from the idealized assumptions for which the estimator is optimized.” [1,2] The word “small” can have two different interpretations, both important: either fractionally small departures for all data points, or else fractionally large departures for a small number of data points. It is the latter interpretation, leading to the notion of outlier points, that is generally the most stressful for statistical procedures. Statisticians have developed various sorts of robust statistical estimators. Many, if not most, can be grouped in one of three categories. M-estimates follow from maximum-likelihood arguments very much as equations (15.1.5) and (15.1.7) followed from equation (15.1.3). M-estimates are usually the most relevant class for model-fitting, that is, estimation of parameters. We therefore consider these estimates in some detail below. L-estimates are “linear combinations of order statistics.” These are most applicable to estimations of central value and central tendency, though they can occasionally be applied to some problems in estimation of parameters. Two “typical” L-estimates will give you the general idea. They are (i) the median, and (ii) Tukey’s trimean, defined as the weighted average of the first, second, and third quartile points in a distribution, with weights 1/4, 1/2, and 1/4, respectively. R-estimates are estimates based on rank tests. For example, the equality or inequality of two distributions can be estimated by the Wilcoxon test of computing the mean rank of one distribution in a combined sample of both distributions. The Kolmogorov-Smirnov statistic (equation 14.3.6) and the Spearman rank-order
700 Chapter 15.Modeling of Data narrow central peak http://www.nr. Per read able files tail of outliers granted for (a) .com or call 1-800-872- (including this one) 7423 (North America 电r:1s t users to make one paper 1988-1992 by Cambridge University Press.Programs from NUMERICAL RECIPES IN C: THE only),or least squares fit copy for their 道S S robust straight-line fit (b) email to directcustsen Copyright (C) Figure 15.7.1. Examples where robust statistical methods are desirable:(a)A one-dimensional ART OF SCIENTIFIC COMPUTING(ISBN 0-521- distribution with a tail ofoutliers;statistical fluctuations in these outliers can prevent accurate determination of the position of the central peak.(b)A distribution in two dimensions fitted to a straight line;non-robust v@cam techniques such as least-squares fitting can have undesired sensitivity to outlying points correlation coefficient (14.6.1)are R-estimates in essence,if not always by formal 1988-1992 by Numerical Recipes -431085 definition Some other kinds ofrobust techniques,coming from the fields ofoptimal control (outside and filtering rather than from the field of mathematical statistics,are mentioned at 膜 the end of this section.Some examples where robust statistical methods are desirable North oftware. are shown in Figure 15.7.1. Estimation of Parameters by Local M-Estimates visit website machine Suppose we know that our measurement errors are not normally distributed. Then,in deriving a maximum-likelihood formula for the estimated parameters a in a model y(z;a),we would write instead of equation (15.1.3) N P=Π{exp-pl,y{r;a】△y (15.7.1)
700 Chapter 15. Modeling of Data Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). narrow central peak tail of outliers least squares fit robust straight-line fit (a) (b) Figure 15.7.1. Examples where robust statistical methods are desirable: (a) A one-dimensional distribution with a tail of outliers; statistical fluctuations in these outliers can prevent accurate determination of the position of the central peak. (b) A distribution in two dimensions fitted to a straight line; non-robust techniques such as least-squares fitting can have undesired sensitivity to outlying points. correlation coefficient (14.6.1) are R-estimates in essence, if not always by formal definition. Some other kinds of robust techniques, coming from the fields of optimal control and filtering rather than from the field of mathematical statistics, are mentioned at the end of this section. Some examples where robust statistical methods are desirable are shown in Figure 15.7.1. Estimation of Parameters by Local M-Estimates Suppose we know that our measurement errors are not normally distributed. Then, in deriving a maximum-likelihood formula for the estimated parameters a in a model y(x; a), we would write instead of equation (15.1.3) P = N i=1 {exp [−ρ(yi, y {xi; a})] ∆y} (15.7.1)
15.7 Robust Estimation 701 where the function p is the negative logarithm of the probability density.Taking the logarithm of(15.7.1)analogously with(15.1.4),we find that we want to minimize the expression p(vi,y{xi;a}) (15.7.2) =1 Very often,it is the case that the function p depends not independently on its two arguments,measured yi and predicted y(i),but only on their difference,at least if scaled by some weight factorso;which we are able to assign to each point.In this 81 case the M-estimate is said to be local,and we can replace (15.7.2)by the prescription -y(xi;a minimize over ∑p( (15.7.3) i-I where the function p(z)is a function of a single variable z=[yi-y(i)]/oi. If we now define the derivative of p(z)to be a function () RECIPES ()d() 49 (15.7.4) dz Press. then the generalization of(15.1.7)to the case of a general M-estimate is N 0= ∑1 Oy(xi;a) k=1,,M Oak (15.7.5) 40i i= IENTIFIC If you compare (15.7.3)to (15.1.3),and (15.7.5)to (15.1.7),you see at once 6 that the specialization for normally distributed errors is p= (2)=2 (normal) (15.7.6) MPUTING (ISBN 1992 If the errors are distributed as a double or two-sided exponential,namely Prob yi-y(i)}~exp (15.7.7) Numerical 10521 431 then,by contrast, (outside Recipes p(x)=lz(z)=sgn(z) (double exponential) (15.7.8) North Software. Comparing to equation(15.7.3),we see that in this case the maximum likelihood estimator is obtained by minimizing the mean absolute deviation,rather than the mean square deviation.Here the tails of the distribution,although exponentially decreasing,are asymptotically much larger than any corresponding Gaussian. A distribution with even more extensive-therefore sometimes even more realistic -tails is the Cauchy or Lorentzian distribution. 1 Prob yi-y(i) (15.7.9) 1+
15.7 Robust Estimation 701 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). where the function ρ is the negative logarithm of the probability density. Taking the logarithm of (15.7.1) analogously with (15.1.4), we find that we want to minimize the expression N i=1 ρ(yi, y {xi; a}) (15.7.2) Very often, it is the case that the function ρ depends not independently on its two arguments, measured yi and predicted y(xi), but only on their difference, at least if scaled by some weight factors σi which we are able to assign to each point. In this case the M-estimate is said to be local, and we can replace (15.7.2) by the prescription minimize over a N i=1 ρ yi − y(xi; a) σi (15.7.3) where the function ρ(z) is a function of a single variable z ≡ [yi − y(xi)]/σi. If we now define the derivative of ρ(z) to be a function ψ(z), ψ(z) ≡ dρ(z) dz (15.7.4) then the generalization of (15.1.7) to the case of a general M-estimate is 0 = N i=1 1 σi ψ yi − y(xi) σi ∂y(xi; a) ∂ak k = 1,...,M (15.7.5) If you compare (15.7.3) to (15.1.3), and (15.7.5) to (15.1.7), you see at once that the specialization for normally distributed errors is ρ(z) = 1 2 z2 ψ(z) = z (normal) (15.7.6) If the errors are distributed as a double or two-sided exponential, namely Prob {yi − y(xi)} ∼ exp − yi − y(xi) σi (15.7.7) then, by contrast, ρ(x) = |z| ψ(z) = sgn(z) (double exponential) (15.7.8) Comparing to equation (15.7.3), we see that in this case the maximum likelihood estimator is obtained by minimizing the mean absolute deviation, rather than the mean square deviation. Here the tails of the distribution, although exponentially decreasing, are asymptotically much larger than any corresponding Gaussian. A distribution with even more extensive — therefore sometimes even more realistic — tails is the Cauchy or Lorentzian distribution, Prob {yi − y(xi)} ∼ 1 1 + 1 2 yi − y(xi) σi 2 (15.7.9)
702 Chapter 15.Modeling of Data This implies p(z)=log (1+ 2 (z)= 1+52 (Lorentzian) (15.7.10) Notice that the function occurs as a weighting function in the generalized normal equations (15.7.5).For normally distributed errors,equation (15.7.6)says that the more deviant the points,the greater the weight.By contrast,when tails are somewhat more prominent,as in(15.7.7),then(15.7.8)says that all deviant points get the same relative weight,with only the sign information used.Finally,when the tails are even larger,(15.7.10)says the increases with deviation,then starts decreasing,so that very deviant points-the true outliers-are not counted at all in the estimation of the parameters. This general idea,that the weight given individual points should first increase 8 鱼君 with deviation,then decrease,motivates some additional prescriptions for which do not especially correspond to standard,textbook probability distributions.Two examples are RECIPES Andrew's sine 9 (z) sin(z/c) 2c (15.7.12) 6 where the optimal value of c for normal errors is c =6.0. Numerical Calculation of M-Estimates (ISBN To fit a model by means of an M-estimate,you first decide which M-estimate 10.621 you want,that is,which matching pair p,you want to use.We rather like Recipes Numerica (15.7.8)or(15.7.10). 431 You then have to make an unpleasant choice between two fairly difficult E Recipes problems.Either find the solution of the nonlinear set of M equations(15.7.5),or else minimize the single function in M variables(15.7.3). (outside Notice that the function (15.7.8)has a discontinuous and a discontinuous North derivative for p.Such discontinuities frequently wreak havoc on both general nonlinear equation solvers and general function minimizing routines.You might now think of rejecting(15.7.8)in favor of (15.7.10),which is smoother.However, you will find that the latter choice is also bad news for many general equation solving or minimization routines:small changes in the fitted parameters can drive (z) off its peak into one or the other of its asymptotically small regimes.Therefore, different terms in the equation spring into or out of action(almost as bad as analytic discontinuities). Don't despair.If your computer budget (or,for personal computers,patience) is up to it,this is an excellent application for the downhill simplex minimization
702 Chapter 15. Modeling of Data Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). This implies ρ(z) = log 1 + 1 2 z2 ψ(z) = z 1 + 1 2 z2 (Lorentzian) (15.7.10) Notice that the ψ function occurs as a weighting function in the generalized normal equations (15.7.5). For normally distributed errors, equation (15.7.6) says that the more deviant the points, the greater the weight. By contrast, when tails are somewhat more prominent, as in (15.7.7), then (15.7.8) says that all deviant points get the same relative weight, with only the sign information used. Finally, when the tails are even larger, (15.7.10) says the ψ increases with deviation, then starts decreasing, so that very deviant points — the true outliers — are not counted at all in the estimation of the parameters. This general idea, that the weight given individual points should first increase with deviation, then decrease, motivates some additional prescriptions for ψ which do not especially correspond to standard, textbook probability distributions. Two examples are Andrew’s sine ψ(z) = sin(z/c) 0 |z| cπ (15.7.11) If the measurement errors happen to be normal after all, with standard deviations σ i, then it can be shown that the optimal value for the constant c is c = 2.1. Tukey’s biweight ψ(z) = z(1 − z2/c2)2 0 |z| c (15.7.12) where the optimal value of c for normal errors is c = 6.0. Numerical Calculation of M-Estimates To fit a model by means of an M-estimate, you first decide which M-estimate you want, that is, which matching pair ρ, ψ you want to use. We rather like (15.7.8) or (15.7.10). You then have to make an unpleasant choice between two fairly difficult problems. Either find the solution of the nonlinear set of M equations (15.7.5), or else minimize the single function in M variables (15.7.3). Notice that the function (15.7.8) has a discontinuous ψ, and a discontinuous derivative for ρ. Such discontinuities frequently wreak havoc on both general nonlinear equation solvers and general function minimizing routines. You might now think of rejecting (15.7.8) in favor of (15.7.10), which is smoother. However, you will find that the latter choice is also bad news for many general equation solving or minimization routines: small changes in the fitted parameters can drive ψ(z) off its peak into one or the other of its asymptotically small regimes. Therefore, different terms in the equation spring into or out of action (almost as bad as analytic discontinuities). Don’t despair. If your computer budget (or, for personal computers, patience) is up to it, this is an excellent application for the downhill simplex minimization
15.7 Robust Estimation 703 algorithm exemplified in amoeba 810.4 or amebsa in $10.9.Those algorithms make no assumptions about continuity;they just ooze downhill and will work for virtually any sane choice of the function p. It is very much to your(financial)advantage to find good starting values, however.Often this is done by first fitting the model by the standard x2(nonrobust) techniques,e.g.,as described in $15.4 or $15.5.The fitted parameters thus obtained are then used as starting values in amoeba,now using the robust choice of p and minimizing the expression(15.7.3). Fitting a Line by Minimizing Absolute Deviation Occasionally there is a special case that happens to be much easier than is suggested by the general strategy outlined above.The case of equations(15.7.7)- (15.7.8),when the model is a simple straight line y(x;a,b)=a+bx (15.7.13) and where the weights o:are all equal,happens to be such a case.The problem is precisely the robust version of the problem posed in equation(15.2.1)above,namely 百ò fit a straight line through a set of data points.The merit function to be minimized is 9 a bzil (15.7.14) =1 rather than the x2 given by equation(15.2.2). The key simplification is based on the following fact:The median cM of a set of numbers ci is also that value which minimizes the sum of the absolute deviations ∑Ia-cl 6 (Proof:Differentiate the above expression with respect to cM and set it to zero.) It follows that,for fixed b,the value of a that minimizes (15.7.14)is ▣ a median [yi-bxi} (15.7.15) Equation(15.7.5)for the parameter b is Numerica 10.621 43126 0 ti sgn(yi-a-bxi) (15.7.16) i=1 (outside (where sgn(0)is to be interpreted as zero).If we replace a in this equation by the implied function a(b)of(15.7.15),then we are left with an equation in a single variable which can be solved by bracketing and bisection,as described in 89.1. (In fact,it is dangerous to use any fancier method of root-finding,because of the discontinuities in equation 15.7.16.) Here is a routine that does all this.It calls select(88.5)to find the median. The bracketing and bisection are built in to the routine,as is the x2 solution that generates the initial guesses for a and b.Notice that the evaluation of the right-hand side of(15.7.16)occurs in the function rofunc,with communication via global (top-level)variables
15.7 Robust Estimation 703 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). algorithm exemplified in amoeba §10.4 or amebsa in §10.9. Those algorithms make no assumptions about continuity; they just ooze downhill and will work for virtually any sane choice of the function ρ. It is very much to your (financial) advantage to find good starting values, however. Often this is done by first fitting the model by the standard χ2 (nonrobust) techniques, e.g., as described in §15.4 or §15.5. The fitted parameters thus obtained are then used as starting values in amoeba, now using the robust choice of ρ and minimizing the expression (15.7.3). Fitting a Line by Minimizing Absolute Deviation Occasionally there is a special case that happens to be much easier than is suggested by the general strategy outlined above. The case of equations (15.7.7)– (15.7.8), when the model is a simple straight line y(x; a, b) = a + bx (15.7.13) and where the weights σi are all equal, happens to be such a case. The problem is precisely the robust version of the problem posed in equation (15.2.1) above, namely fit a straight line through a set of data points. The merit function to be minimized is N i=1 |yi − a − bxi| (15.7.14) rather than the χ2 given by equation (15.2.2). The key simplification is based on the following fact: The median c M of a set of numbers ci is also that value which minimizes the sum of the absolute deviations i |ci − cM | (Proof: Differentiate the above expression with respect to cM and set it to zero.) It follows that, for fixed b, the value of a that minimizes (15.7.14) is a = median {yi − bxi} (15.7.15) Equation (15.7.5) for the parameter b is 0 = N i=1 xi sgn(yi − a − bxi) (15.7.16) (where sgn(0) is to be interpreted as zero). If we replace a in this equation by the implied function a(b) of (15.7.15), then we are left with an equation in a single variable which can be solved by bracketing and bisection, as described in §9.1. (In fact, it is dangerous to use any fancier method of root-finding, because of the discontinuities in equation 15.7.16.) Here is a routine that does all this. It calls select (§8.5) to find the median. The bracketing and bisection are built in to the routine, as is the χ2 solution that generates the initial guesses for a and b. Notice that the evaluation of the right-hand side of (15.7.16) occurs in the function rofunc, with communication via global (top-level) variables
704 Chapter 15. Modeling of Data #include #include "nrutil.h" int ndatat; float *xt,*yt,aa,abdevt; void medfit(float x[],float y[],int ndata,float *a,float *b,float *abdev) Fits y =a+ba by the criterion of least absolute deviations.The arrays x[1..ndata]and y[1..ndata]are the input experimental points.The fitted parameters a and b are output, along with abdev,which is the mean absolute deviation (in y)of the experimental points from the fitted line.This routine uses the routine rofunc,with communication via global variables. float rofunc(float b); int j; float bb,b1,b2,del,f,f1,f2,sigb,tempi f1 oat sx=0.0,sy=0.0,sxy=0.0,sxx=0.0,ch1sq=0.0; 18881992 ndatat=ndata; xt=x; 1600 (including this one) yt-yi for (j=1;j0.0) Bracketing. bb=b2+1.6*(b2-b1); b1=b2; v@cambridge.org personal use.Further reproduction, To order Numerical Recipes books or 1988-1992 by Numerical Recipes f1=f2: -431085 b2=bbi f2=rofunc(b2); (outside sigb=0.01*sigb; Refine until error a negligible number of standard North Software. while (fabs(b2-b1)>sigb){ deviations. bb=b1+0.5*(b2-b1); Bisection. if (bb =b1 Il bb =b2)break; f=rofunc(bb); 1f(f*f1>=0.0) f1=f; bl=bb; else f2=f; b2=bbi 2
704 Chapter 15. Modeling of Data Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). #include #include "nrutil.h" int ndatat; float *xt,*yt,aa,abdevt; void medfit(float x[], float y[], int ndata, float *a, float *b, float *abdev) Fits y = a + bx by the criterion of least absolute deviations. The arrays x[1..ndata] and y[1..ndata] are the input experimental points. The fitted parameters a and b are output, along with abdev, which is the mean absolute deviation (in y) of the experimental points from the fitted line. This routine uses the routine rofunc, with communication via global variables. { float rofunc(float b); int j; float bb,b1,b2,del,f,f1,f2,sigb,temp; float sx=0.0,sy=0.0,sxy=0.0,sxx=0.0,chisq=0.0; ndatat=ndata; xt=x; yt=y; for (j=1;j 0.0) { b2=bb+SIGN(3.0*sigb,f1); Guess bracket as 3-σ away, in the downhill direction known from f1. f2=rofunc(b2); if (b2 == b1) { *a=aa; *b=bb; *abdev=abdevt/ndata; return; } while (f1*f2 > 0.0) { Bracketing. bb=b2+1.6*(b2-b1); b1=b2; f1=f2; b2=bb; f2=rofunc(b2); } sigb=0.01*sigb; Refine until error a negligible number of standard while (fabs(b2-b1) > sigb) { deviations. bb=b1+0.5*(b2-b1); Bisection. if (bb == b1 || bb == b2) break; f=rofunc(bb); if (f*f1 >= 0.0) { f1=f; b1=bb; } else { f2=f; b2=bb; } } }
15.7 Robust Estimation 705 *a=aa; *b=bb; *abdev=abdevt/ndata; #include #include "nrutil.h" #define EPS 1.0e-7 extern int ndatat; Defined in medfit. extern float *xt,*yt,aa,abdevt; http://www.nr. float rofunc(float b) Evaluates the right-hand side of equation (15.7.16)for a given value of b.Communication with 83g the routine medfit is through global variables. float select(unsigned long k,unsigned long n,float arr[]); int j; 1.800 float *arr,d,sum=0.0; arr=vector(1,ndatat); to any from NUMERICAL RECIPESI 19881992 for (j=1;j>1,ndatat,arr); else server computer, (North America j=ndatat >>1; make one paper University Press. THE aa=0.5*(select(i,ndatat,arr)+select(j+1,ndatat,arr)); ART d 是 abdevt=0.0; Programs for (j=1;jEPS)sum +=(d >=0.0 xt[j]-xt[j]) to dir Copyright (C) free_vector(arr,1,ndatat); return sum; ectcustser 18881920 OF SCIENTIFIC COMPUTING(ISBN Other Robust Techniques v@cambr 10-621 Sometimes you may have a priori knowledge about the probable values and Further reproduction. Numerical Recipes 43108 probable uncertainties of some parameters that you are trying to estimate from a data set.In such cases you may want to perform a fit that takes this advance information properly into account,neither completely freezing a parameter at a predetermined (outside value (as in lfit $15.4)nor completely leaving it to be determined by the data set North Software. The formalism for doing this is called "use of a priori covariances." A related problem occurs in signal processing and control theory,where it is sometimes desired to"track"(i.e.,maintain an estimate of)a time-varying signal in visit website the presence of noise.If the signal is known to be characterized by some number machine of parameters that vary only slowly,then the formalism of Kalman filtering tells how the incoming,raw measurements of the signal should be processed to produce best parameter estimates as a function of time.For example,if the signal is a frequency-modulated sine wave,then the slowly varying parameter might be the instantaneous frequency.The Kalman filter for this case is called a phase-locked loop and is implemented in the circuitry of good radio receivers [3.41
15.7 Robust Estimation 705 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). *a=aa; *b=bb; *abdev=abdevt/ndata; } #include #include "nrutil.h" #define EPS 1.0e-7 extern int ndatat; Defined in medfit. extern float *xt,*yt,aa,abdevt; float rofunc(float b) Evaluates the right-hand side of equation (15.7.16) for a given value of b. Communication with the routine medfit is through global variables. { float select(unsigned long k, unsigned long n, float arr[]); int j; float *arr,d,sum=0.0; arr=vector(1,ndatat); for (j=1;j>1,ndatat,arr); } else { j=ndatat >> 1; aa=0.5*(select(j,ndatat,arr)+select(j+1,ndatat,arr)); } abdevt=0.0; for (j=1;j EPS) sum += (d >= 0.0 ? xt[j] : -xt[j]); } free_vector(arr,1,ndatat); return sum; } Other Robust Techniques Sometimes you may have a priori knowledge about the probable values and probable uncertainties of some parameters that you are trying to estimate from a data set. In such cases you may want to perform a fit that takes this advance information properly into account, neither completely freezing a parameter at a predetermined value (as in lfit §15.4) nor completely leaving it to be determined by the data set. The formalism for doing this is called “use of a priori covariances.” A related problem occurs in signal processing and control theory, where it is sometimes desired to “track” (i.e., maintain an estimate of) a time-varying signal in the presence of noise. If the signal is known to be characterized by some number of parameters that vary only slowly, then the formalism of Kalman filtering tells how the incoming, raw measurements of the signal should be processed to produce best parameter estimates as a function of time. For example, if the signal is a frequency-modulated sine wave, then the slowly varying parameter might be the instantaneous frequency. The Kalman filter for this case is called a phase-locked loop and is implemented in the circuitry of good radio receivers [3,4]
706 Chapter 15 Modeling of Data CITED REFERENCES AND FURTHER READING: Huber,P.J.1981,Robust Statistics (New York:Wiley).[1] Launer,R.L.,and Wilkinson,G.N.(eds.)1979,Robustness in Statistics (New York:Academic Press).[2] Bryson,A.E.,and Ho,Y.C.1969,Applied Optimal Control(Waltham,MA:Ginn).[3] Jazwinski,A.H.1970,Stochastic Processes and Filtering Theory (New York:Academic Press).[4] Permission is http://w.nr.com or call 1-800-872-7423(North America only),orsend email to directcustserv@cambridge.org(outside North America). granted for internet users to make one paper copy for their Copyright (C)1988-1992 by Cambridge University Press.Programs Copyright(C)1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C:THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)
706 Chapter 15. Modeling of Data Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machinereadable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). CITED REFERENCES AND FURTHER READING: Huber, P.J. 1981, Robust Statistics (New York: Wiley). [1] Launer, R.L., and Wilkinson, G.N. (eds.) 1979, Robustness in Statistics (New York: Academic Press). [2] Bryson, A. E., and Ho, Y.C. 1969, Applied Optimal Control (Waltham, MA: Ginn). [3] Jazwinski, A. H. 1970, Stochastic Processes and Filtering Theory (New York: Academic Press). [4]