Least squares method
From DDWiki
The Method of Least Squares is used to fit a continuous curve to a set of discrete data points. It was pioneered by Carl Friedrich Gauss in 1795 when he was only 18 years old. Least Squares was also independently developed by Adrien-Marie Legendre and Robert Adrain in the early 1800's. The method is optimal for many situations, which is proven by the Gauss-Markov theorem.
Contents |
Applications
Least squares method can be used for any set of data points which appear to have a trend in the data. It is necessary to define a function form before applying the method. There are two main types of least squares functions, linear and nonlinear. Linear methods can be used any time the relationship between the output function and the unknown coefficients is linear. For example, polynomials of any order can be used in linear least squares. Function forms where the coefficients are not linearly related to the output require that nonlinear methods be used, however. Exponents and logarithms are two examples of these nonlinear functions.
Linear Least Squares
As the name implies, the goal of the least squares method is to minimize the squares of the differences between the discrete data points and the function prediction. If a data set of n data points exists where each independent variable xi corresponds to a dependant variable yi, then the difference can be expressed as:
It follows that the sum of the squares of the differences is expressed as:
In order to minimize this value, it is necessary to take the derivative of summation with respect to each of the unknown coefficients and set each to zero:
For a function with m number of unknown coefficients, this will yield m equations. By solving this system of equations, an analytical solution can be found. This is one major advantage to the least squares method. There is no need for iteration or approximation with the linear least squares method.
In matrix form, the equation to be regressed can be expressed as:
The equation can rearranged by placing the error component on the left hand side and squaring both sides:
To minimize the residuals, if there exist least-squares estimator
, the first-order condition of minimization should be satisfied. Thus,
The least-squares estimator is:
However, if endogenous variables are correlated with the disturbances (as in a system of simultaneous equations), or if the disturbances are correlated between multiple equations, using OLS estimators to estimate structural parameters can cause biased coefficient estimates.
Example of Linear Least Squares
Take a data set of n points (xi,yi). By inspection, it appears that a straight line can be fit to approximate the data. The equation for the line will be:
Which makes the sum of the squares of the differences:
Taking the derivative with respect to both unknown variables yields:
Solving for a0 and a1 simultaneously gives the analytical solution:
Nonlinear Least Squares Method
Since the linear least squares method is very straight-forward and robust, it is desirable to transform nonlinear function forms into a linear form. This allows a solution to be found as stated above. For example, if an exponential model seems appropriate, taking the natural log of both sides linearizes the relationship:
becomes
Simply solve the linearized equation as stated above, substitute the resulting a values back in to the original function form, and the solution is given, again analytically. Some function forms do not lend themselves to such simple transformations, however. In these cases, a Taylor series expansion should be employed. This form of least squares is known as the Gauss-Newton method. A Δa term arises from this, and therefore an iterative method must be used. The ending criteria is when the a terms converge, and Δa goes to zero. Please find more specific information on this relatively complex method in the links below.
References
- Wikipedia Article
- Optimization Technology Center
- Chapra, S. C. and Canale, R. P. Numerical Methods for Engineers, 4th Ed. 2002
- Greene, W.H., 2003, Econometric analysis, Prentice Hall, Upper Saddle River, N.J.

