Thursday, September 16, 2010

Does Least Squares Make the Best Choice for Coefficients?

Least Squares is often used to find a fit to a set of data. Linear Least Squares is easier since the solution for the unknown coefficients only involves a set of equations which are linear functions of the unknowns. The primary condition for a least squares fit is that the sum of the squares of the residuals be a minimum. The result is that portions of the fitted curve can have a definite deviation from the data set and still result in a minimum value for the sum.

For the fits of the data for the Zener diode I used Mathcad's genfit function. For the composite functions of the last fit the individual fits can also be done by fitting lines in a log-log plot*. One of the problems that I encountered in doing the fits is that the fitted function tended to cut corners in the region of the "knee" where the characteristics change from lower currents to higher ones. As a result there is a correlation among neighboring residuals there. Intuitively one would expect that the residuals would be randomly distributed with respect to the fitted curve for the best fit. There seemed to be something wrong with the residuals.

I decided to give the rms residual more control in doing the fit. I tried dividing the data into sections with each section being represented by a term in the fit function. The result is that the residuals differed for each region. This method also seemed somewhat arbitrary since the terms for the function depended on how the data was partitioned. The results suggested the use of a Taylor series for the current involving exponential functions. Fitting a quadratic function of the first fit didn't work. The difference between the fit for lower currents and the data looked closer to an exponential function that was fairly linear for lower currents so I tried multiplying the current by a factor involving an exponential term. That worked much better than the Taylor series. Varying the number of data points included in the first fit optimized the final fit. The rms residual was closer to the result of a tedious process involving a search for the coefficients in a region of fixed size and a random choice from among a few of the lowest values of the sum of the squares of the residuals to avoid getting "stuck in a loop." (The results of the second fit method weren't consistent. The coefficients posted were the best values found.)

The results show the utility of the residuals in analyzing the results of a fit and comparing one fit method with another.

The economists like to use linear models for optimization problems but nonlinear models may prove to be more useful. Fits can be used to find approximate functions for observable relations in a theory. Doing what is best for the individual is not necessisarily at odds with doing what is best for the group. The problem may be similar to that of finding the best fit for a set of data.

*edit: One would have to do a semi-log plot. For the first fit involving the lower curve one would also have to ignore the small constant, u_0, and plot log(I1/mA) vs V. For the second plot it would be log(I2/I1 - 1) vs I1 (I2>I1) with I1 being the current in the first fit and I2 that of the second fit.

No comments: