Matlab functions    from  BioméCardio    

 
   polycenter
sffilt   

polydeg

Find an optimal degree for polynomial fitting

Contents

Download

polydeg.m

Syntax

   n = polydeg(x,y)

Description

n = polydeg(x,y) finds the optimal degree for polynomial fitting according to the Akaike's information criterion.

Assuming that you have some data points through which you want to pass a fitting polynomial, the obvious question for some to ask is which degree to choose. A linear or first degree polynomial approximation might represent your data very poorly. On the other side, a very high order polynomial, say 30, could result in a little convenient and unnecessarily complex model. Clearly, a compromise must be made between the precision and the complexity of the polynomial model. Akaike's information criterion (AIC), developed by Hirotsugu Akaike can be used as a measure of the goodness of fit.

If you want to fit N data points y(x) with a polynomial p(x) of degree n (i.e. with n+1 degrees of freedom), the Akaike's information criterion is defined by:

where the residual sum of squares RSS is given by:

AIC favours goodness of fit via RSS and includes a penalty that is an increasing function of the number of estimated parameters and which discourages overfitting. The preferred model is the one that provides the lowest AIC value. The AIC minimization thus attempts to find the model that best explains the data with a minimum of degrees of freedom.

Notes:

Examples

Load census data from Matlab and fit data points with a polynomial.

load census

The optimal degree according to the AIC methodology is given by polydeg:

n = polydeg(cdate,pop)
n =

     2

Now, let us compare the original data with the fitting polynomial:

p = polyfit(cdate,pop,n);
plot(cdate,pop,'o',cdate,polyval(p,cdate),'k')

Create a noisy signal:

x = linspace(0,10,300);
y = sin(x.^3/100).^2 + 0.05*randn(size(x));

The optimal degree for polynomial fitting is:

n = polydeg(x,y)
n =

    21

Use orthofit for polynomial fitting and check the result:

ys = orthofit(x,y,n);
plot(x,y,'.',x,ys,'k')

Information

AIC on Wikipedia.

See also

polyfit, orthofit

About the author

Damien Garcia, Eng., Ph.D.
Assistant professor, Department of radiology
CRCHUM, University of Montreal Hospital
Montreal, QC, Canada
Damien.Garcia.REMOVE-THIS@BiomeCardio.com

www.biomecardio.com