Least squares

From Wikipedia, the free encyclopedia
  (Redirected from Method of least squares)
Jump to: navigation, search

The method of least squares is a standard approach to the approximate solution of overdetermined systems, i.e. sets of equations in which there are more equations than unknowns. "Least squares" means that the overall solution minimizes the sum of the squares of the errors made in solving every single equation.

The most important application is in data fitting. The best fit in the least-squares sense minimizes the sum of squared residuals, a residual being the difference between an observed value and the fitted value provided by a model.

Least squares problems fall into two categories: linear or ordinary least squares and non-linear least squares, depending on whether or not the residuals are linear in all unknowns. The linear least-squares problem occurs in statistical regression analysis; it has a closed-form solution. The non-linear problem has no closed-form solution and is usually solved by iterative refinement; at each iteration the system is approximated by a linear one, thus the core calculation is similar in both cases.

The least-squares method was first described by Carl Friedrich Gauss around 1794.[1] Least squares corresponds to the maximum likelihood criterion if the experimental errors have a normal distribution and can also be derived as a method of moments estimator.

The following discussion is mostly presented in terms of linear functions but the use of least-squares is valid and practical for more general families of functions. For example, the Fourier series approximation of degree n is optimal in the least-squares sense, amongst all approximations in terms of trigonometric polynomials of degree n. Also, by iteratively applying local quadratic approximation to the likelihood (through the Fisher information), the least-squares method may be used to fit a generalized linear model.

The result of fitting a set of data points with a quadratic function.

Contents

[edit] History

[edit] Context

The method of least squares grew out of the fields of astronomy and geodesy as scientists and mathematicians sought to provide solutions to the challenges of navigating the Earth's oceans during the Age of Exploration. The accurate description of the behavior of celestial bodies was key to enabling ships to sail in open seas where before sailors had relied on land sightings to determine the positions of their ships.

The method was the culmination of several advances that took place during the course of the eighteenth century[2]:

[edit] The method

Carl Friedrich Gauss is credited with developing the fundamentals of the basis for least-squares analysis in 1795 at the age of eighteen. Legendre was the first to publish the method, however.

An early demonstration of the strength of Gauss's method came when it was used to predict the future location of the newly discovered asteroid Ceres. On January 1, 1801, the Italian astronomer Giuseppe Piazzi discovered Ceres and was able to track its path for 40 days before it was lost in the glare of the sun. Based on this data, astronomers desired to determine the location of Ceres after it emerged from behind the sun without solving the complicated Kepler's nonlinear equations of planetary motion. The only predictions that successfully allowed Hungarian astronomer Franz Xaver von Zach to relocate Ceres were those performed by the 24-year-old Gauss using least-squares analysis.

Gauss did not publish the method until 1809, when it appeared in volume two of his work on celestial mechanics, Theoria Motus Corporum Coelestium in sectionibus conicis solem ambientium. In 1822, Gauss was able to state that the least-squares approach to regression analysis is optimal in the sense that in a linear model where the errors have a mean of zero, are uncorrelated, and have equal variances, the best linear unbiased estimator of the coefficients is the least-squares estimator. This result is known as the Gauss–Markov theorem.

The idea of least-squares analysis was also independently formulated by the Frenchman Adrien-Marie Legendre in 1805 and the American Robert Adrain in 1808. In the next two centuries workers in the theory of errors and in statistics found many different ways of implementing least squares.[3].

[edit] Problem statement

The objective consists of adjusting the parameters of a model function to best fit a data set. A simple data set consists of n points (data pairs) (x_i,y_i)\!, i = 1, ..., n, where x_i\! is an independent variable and y_i\! is a dependent variable whose value is found by observation. The model function has the form f(x,β), where the m adjustable parameters are held in the vector \boldsymbol \beta. The goal is to find the parameter values for the model which "best" fits the data. The least squares method finds its optimum when the sum, S, of squared residuals

S=\sum_{i=1}^{n}{r_i}^2

is a minimum. A residual is defined as the difference between the value predicted by the model and the actual value of the dependent variable

r_i=y_i-f(x_i,\boldsymbol \beta).

An example of a model is that of the straight line. Denoting the intercept as β0 and the slope as β1, the model function is given by f(x,\boldsymbol \beta)=\beta_0+\beta_1 x. See linear least squares for a fully worked out example of this model.

A data point may consist of more than one independent variable. For an example, when fitting a plane to a set of height measurements, the plane is a function of two independent variables, x and z, say. In the most general case there may be one or more independent variables and one or more dependent variables at each data point.

[edit] Solving the least squares problem

The minimum of the sum of squares is found by setting the gradient to zero. Since the model contains m parameters there are m gradient equations.

\frac{\partial S}{\partial \beta_j}=2\sum_i r_i\frac{\partial r_i}{\partial \beta_j}=0,\ j=1,\ldots,m

and since r_i=y_i-f(x_i,\boldsymbol \beta)\, the gradient equations become

-2\sum_i \frac{\partial f(x_i,\boldsymbol \beta)}{\partial \beta_j} r_i=0,\ j=1,\ldots,m.

The gradient equations apply to all least squares problems. Each particular problem requires particular expressions for the model and its partial derivatives.

[edit] Linear least squares

A regression model is a linear one when the model comprises a linear combination of the parameters, i.e.

 f(x_i, \beta) = \sum_{j = 1}^{m} \beta_j \phi_j(x_{i})

where the coefficients, φj, are functions of xi.

Letting

 X_{ij}= \frac{\partial f(x_i,\boldsymbol \beta)}{\partial \beta_j}=   \phi_j(x_{i}) . \,

we can then see that in that case the least square estimate (or estimator, in the context of a random sample),  \boldsymbol \beta is given by

 \boldsymbol{\hat\beta} =( X ^TX)^{-1}X^{T}\boldsymbol y.

For a derivation of this estimate see Linear least squares.

[edit] Functional analysis

A generalization to approximation of a data set is the approximation of a function by a sum of other functions, usually an orthogonal set:[4][5]

f(x) \approx f_n (x) = a_1 \phi _1 (x) + a_2 \phi _2(x) + \cdots + a_n \phi _n (x), \

with the set of functions {\  \phi _j (x) } an orthonormal set over the interval of interest, say [a, b]. The coefficients {\ a_j } are selected to make the magnitude of the difference ||f − f n ||2 as small as possible. For example, the magnitude, or norm, of a function g (x ) over the interval [a, b] can be defined by:[6]

 \|g\| = \left(\int_a^b g^*(x)g(x) \, dx \right)^{1/2}

where the ‘*’ denotes complex conjugate in the case of complex functions.[7] The { \phi_j (x)\  } satisfy orthonormality relations:[8]

 \int_a^b \phi _i^* (x)\phi _j (x) \, dx =\delta_{ij},

where δij is the Kronecker delta. Substituting function f n into these equations then leads to the n-dimensional Pythagorean theorem:[9]

\|f_n\|^2 = |a_1|^2 + |a_2|^2 + \cdots + |a_n|^2. \,

The coefficients {\ a_j } making ||f − f n ||2 as small as possible are found to be:[4]

a_j = \int_a^b \phi _j^* (x)f (x) \, dx.

The generalization of the n-dimensional Pythagorean theorem to infinite-dimensional  real inner product spaces is known as Parseval's identity or Parseval's equation.[10] Particular examples of such a representation of a function are the Fourier series and the generalized Fourier series.

[edit] Non-linear least squares

There is no closed-form solution to a non-linear least squares problem. Instead, numerical algorithms are used to find the value of the parameters β which minimize the objective. Most algorithms involve choosing initial values for the parameters. Then, the parameters are refined iteratively, that is, the values are obtained by successive approximation.

{\beta_j}^{k+1}={\beta_j}^k+\Delta \beta_j

k is an iteration number and the vector of increments, \Delta \beta_j\, is known as the shift vector. In some commonly used algorithms, at each iteration the model may be linearized by approximation to a first-order Taylor series expansion about  \boldsymbol \beta^k\!


\begin{align}
f(x_i,\boldsymbol \beta) & = f^k(x_i,\boldsymbol \beta) +\sum_j \frac{\partial f(x_i,\boldsymbol \beta)}{\partial \beta_j} \left(\beta_j-{\beta_j}^k \right) \\
& = f^k(x_i,\boldsymbol \beta) +\sum_j J_{ij} \Delta\beta_j.
\end{align}

The Jacobian, J, is a function of constants, the independent variable and the parameters, so it changes from one iteration to the next. The residuals are given by

r_i=y_i- f^k(x_i,\boldsymbol \beta)- \sum_{j=1}^{m} J_{ij}\Delta\beta_j=\Delta y_i- \sum_{j=1}^{m} J_{ij}\Delta\beta_j.

To minimize the sum of squares of ri, the gradient equation is set to zero and solved for  \Delta \beta_j\!

-2\sum_{i=1}^{n}J_{ij} \left( \Delta y_i-\sum_{j=1}^{m} J_{ij}\Delta \beta_j \right)=0

which, on rearrangement, become m simultaneous linear equations, the normal equations.

\sum_{i=1}^{n}\sum_{k=1}^{m} J_{ij}J_{ik}\Delta \beta_k=\sum_{i=1}^{n} J_{ij}\Delta y_i \qquad (j=1,\ldots,m)\,

The normal equations are written in matrix notation as

\mathbf{\left(J^TJ\right)\Delta \boldsymbol \beta=J^T\Delta y}.\,

These are the defining equations of the Gauss–Newton algorithm.

[edit] Differences between linear and non-linear least squares

These differences must be considered whenever the solution to a non-linear least squares problem is being sought.

[edit] Least squares, regression analysis and statistics

The methods of least squares and regression analysis are conceptually different. However, the method of least squares is often used to generate estimators and other statistics in regression analysis.

Consider a simple example drawn from physics. A spring should obey Hooke's law which states that the extension of a spring is proportional to the force, F, applied to it.

f(F_i,k)=kF_i\!

constitutes the model, where F is the independent variable. To estimate the force constant, k, a series of n measurements with different forces will produce a set of data, (F_i, y_i), i=1,n\!, where yi is a measured spring extension. Each experimental observation will contain some error. If we denote this error \varepsilon, we may specify an empirical model for our observations,

 y_i = kF_i + \varepsilon_i. \,

There are many methods we might use to estimate the unknown parameter k. Noting that the n equations in the m variables in our data comprise an overdetermined system with one unknown and n equations, we may choose to estimate k using least squares. The sum of squares to be minimized is

 S = \sum_{i=1}^{n} \left(y_i - kF_i\right)^2.

The least squares estimate of the force constant, k, is given by

\hat k=\frac{\sum_i F_i y_i}{\sum_i {F_i}^2}.

Here it is assumed that application of the force causes the spring to expand and, having derived the force constant by least squares fitting, the extension can be predicted from Hooke's law.

In regression analysis the researcher specifies an empirical model. For example, a very common model is the straight line model which is used to test if there is a linear relationship between dependent and independent variable. If a linear relationship is found to exist, the variables are said to be correlated. However, correlation does not prove causation, as both variables may be correlated with other, hidden, variables, or the dependent variable may "reverse" cause the independent variables, or the variables may be otherwise spuriously correlated. For example, suppose there is a correlation between deaths by drowning and the volume of ice cream sales at a particular beach. Yet, both the number of people going swimming and the volume of ice cream sales increase as the weather gets hotter, and presumably the number of deaths by drowning is correlated with the number of people going swimming. Perhaps an increase in swimmers causes both the other variables to increase.

In order to make statistical tests on the results it is necessary to make assumptions about the nature of the experimental errors. A common (but not necessary) assumption is that the errors belong to a Normal distribution. The central limit theorem supports the idea that this is a good approximation in many cases.

However, if the errors are not normally distributed, a central limit theorem often nonetheless implies that the parameter estimates will be approximately normally distributed so long as the sample is reasonably large. For this reason, given the important property that the error is mean independent of the independent variables, the distribution of the error term is not an important issue in regression analysis. Specifically, it is not typically important whether the error term follows a normal distribution.

In a least squares calculation with unit weights, or in linear regression, the variance on the jth parameter, denoted \text{var}(\hat{\beta}_j), is usually estimated with

\text{var}(\hat{\beta}_j)= \sigma^2\left( \left[X^TX\right]^{-1}\right)_{jj} \approx \frac{S}{n-m}\left( \left[X^TX\right]^{-1}\right)_{jj},

where the true residual variance σ2 is replaced by an estimate based on the minimised value of the sum of squares objective function S.

Confidence limits can be found if the probability distribution of the parameters is known, or an asymptotic approximation is made, or assumed. Likewise statistical tests on the residuals can be made if the probability distribution of the residuals is known or assumed. The probability distribution of any linear combination of the dependent variables can be derived if the probability distribution of experimental errors is known or assumed. Inference is particularly straightforward if the errors are assumed to follow a normal distribution, which implies that the parameter estimates and residuals will also be normally distributed conditional on the values of the independent variables.

[edit] Weighted least squares

The expressions given above are based on the implicit assumption that the errors are uncorrelated with each other and with the independent variables and have equal variance. The Gauss–Markov theorem shows that, when this is so, \hat\boldsymbol\beta is a best linear unbiased estimator (BLUE). If, however, the measurements are uncorrelated but have different uncertainties, a modified approach might be adopted. Aitken showed that when a weighted sum of squared residuals is minimized, \hat\boldsymbol\beta is BLUE if each weight is equal to the reciprocal of the variance of the measurement.

 S = \sum_{i=1}^{n} W_{ii}{r_i}^2,\qquad W_{ii}=\frac{1}{{\sigma_i}^2}

The gradient equations for this sum of squares are

-2\sum_i W_{ii}\frac{\partial f(x_i,\boldsymbol \beta)}{\partial \beta_j} r_i=0,\qquad j=1,\ldots,n

which, in a linear least squares system give the modified normal equations,

\sum_{i=1}^{n}\sum_{k=1}^{m} X_{ij}W_{ii}X_{ik}\hat \beta_k=\sum_{i=1}^{n} X_{ij}W_{ii}y_i, \qquad j=1,\ldots,m\,.

When the observational errors are uncorrelated and the weight matrix, W, is diagonal, these may be written as

\mathbf{\left(X^TWX\right)\hat \boldsymbol \beta=X^TWy}.

If the errors are correlated, the resulting estimator is BLUE if the weight matrix is equal to the inverse of the variance-covariance matrix of the observations.

When the errors are uncorrelated, it is convenient to simplify the calculations to factor the weight matrix as w_{ii}=\sqrt W_{ii}. The normal equations can then be written as

\mathbf{\left(X'^TX'\right)\hat \boldsymbol \beta=X'^Ty'}\,

where

\mathbf{X'}=\mathbf{wX}, \mathbf{y'}=\mathbf{wy}.\,

For non-linear least squares systems a similar argument shows that the normal equations should be modified as follows.

\mathbf{\left(J^TWJ\right)\boldsymbol \Delta\beta=J^TW \boldsymbol\Delta y}.\,

Note that for empirical tests, the appropriate W is not known for sure and must be estimated. For this Feasible Generalized Least Squares (FGLS) techniques may be used.

[edit] Relationship to principal components

The first principal component about the mean of a set of points can be represented by that line which most closely approaches the data points (as measured by squared distance of closest approach, i.e. perpendicular to the line). In contrast, linear least squares tries to minimize the distance in the y direction only. Thus, although the two use a similar error metric, linear least squares is a method that treats one dimension of the data preferentially, while PCA treats all dimensions equally.

[edit] LASSO method

In some contexts a regularized version of the least squares solution may be preferable. The LASSO (least absolute shrinkage and selection operator) algorithm, for example, finds a least-squares solution with the constraint that | β | 1, the L1-norm of the parameter vector, is no greater than a given value. Equivalently, it may solve an unconstrained minimization of the least-squares penalty with α | β | 1 added, where α is a constant (this is the Lagrangian form of the constrained problem.) This problem may be solved using quadratic programming or more general convex optimization methods, as well as by specific algorithms such as the least angle regression algorithm. The L1-regularized formulation is useful in some contexts due to its tendency to prefer solutions with fewer nonzero parameter values, effectively reducing the number of variables upon which the given solution is dependent.[11] For this reason, the LASSO and its variants are fundamental to the field of compressed sensing.

[edit] See also

[edit] Notes

  1. ^ Bretscher, Otto (1995). Linear Algebra With Applications, 3rd ed.. Upper Saddle River NJ: Prentice Hall. 
  2. ^ Stigler, Stephen M. (1986). The History of Statistics: The Measurement of Uncertainty Before 1900. Cambridge, MA: Belknap Press of Harvard University Press. ISBN 0674403401. 
  3. ^ See J. Aldrich (1998). "Doing Least Squares: Perspectives from Gauss and Yule". International Statistical Review 66 (1): 61–81. doi:10.1111/j.1751-5823.1998.tb00406.x. 
  4. ^ a b Cornelius Lanczos (1988). Applied analysis (Reprint of 1956 Prentice-Hall ed.). Dover Publications. pp. 212–213. ISBN 048665656X. http://books.google.com/books?id=6E85hExIqHYC&pg=PA212. 
  5. ^ See also Fejér's theorem.
  6. ^ Gerald B Folland (2009). "Equation 3.14". Fourier analysis and its application (Reprint of Wadsworth and Brooks/Cole 1992 ed.). American Mathematical Society Bookstore. p. 69. ISBN 0821847902. http://books.google.com/books?id=ix2iCQ-o9x4C&pg=PA69. 
  7. ^ The extension of Pythagoras' theorem in this manner leads to function spaces and the notion of Lebesgue measure, an idea of “space” more general than the original basis of Euclidean geometry.
  8. ^ Gerald B Folland (2009-01-13). "Equation 3.17". cited work. p. 69. ISBN 0821847902. http://books.google.com/books?id=ix2iCQ-o9x4C&pg=PA69. 
  9. ^ David J. Saville, Graham R. Wood (1991). "§2.5 Sum of squares". Statistical methods: the geometric approach (3rd ed.). Springer. p. 30. ISBN 0387975179. http://books.google.com/books?id=8ummgMVRev0C&pg=PA30. 
  10. ^ Gerald B Folland (2009-01-13). "Equation 3.22". cited work. p. 77. ISBN 0821847902. http://books.google.com/books?id=ix2iCQ-o9x4C&pg=PA77. 
  11. ^ Tibshirani, R. (1996). "Regression shrinkage and selection via the lasso.". J. Royal. Statist. Soc B. 58 (1): 267–288. 

[edit] References

[edit] External links

Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages