Least squares

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 leastsquares sense minimizes the sum of squared residuals, a residual being the difference between an observed value and the fitted value provided by a model. When the problem has substantial uncertainties in the independent variable (the 'x' variable), then simple regression and least squares methods have problems; in such cases, the methodology required for fitting errorsinvariables models may be considered instead of that for least squares.
Least squares problems fall into two categories: linear or ordinary least squares and nonlinear least squares, depending on whether or not the residuals are linear in all unknowns. The linear leastsquares problem occurs in statistical regression analysis; it has a closedform solution. A closedform solution (or closedform expression) is any formula that can be evaluated in a finite number of standard operations. The nonlinear problem has no closedform 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 leastsquares 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 leastsquares is valid and practical for more general families of functions. For example, the Fourier series approximation of degree n is optimal in the leastsquares 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 leastsquares method may be used to fit a generalized linear model.
Contents
History
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]}:
 The combination of different observations taken under the same conditions contrary to simply trying one's best to observe and record a single observation accurately. This approach was notably used by Tobias Mayer while studying the librations of the moon.
 The combination of different observations as being the best estimate of the true value; errors decrease with aggregation rather than increase, perhaps first expressed by Roger Cotes.
 The combination of different observations taken under different conditions as notably performed by Roger Joseph Boscovich in his work on the shape of the earth and PierreSimon Laplace in his work in explaining the differences in motion of Jupiter and Saturn.
 The development of a criterion that can be evaluated to determine when the solution with the minimum error has been achieved, developed by Laplace in his Method of Least Squares.
The method
Carl Friedrich Gauss is credited with developing the fundamentals of the basis for leastsquares 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 24yearold Gauss using leastsquares 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 leastsquares 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 leastsquares estimator. This result is known as the Gauss–Markov theorem.
The idea of leastsquares analysis was also independently formulated by the Frenchman AdrienMarie 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]}
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) , i = 1, ..., n, where is an independent variable and 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 . 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
is a minimum. A residual is defined as the difference between the actual value of the dependent variable and the value predicted by the model.
 .
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 . 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.
Limitations
This regression formulation considers only residuals in the dependent variable. There is an implicit assumption that errors in the independent variable are zero or strictly controlled so as to be negligible. When errors in the independent variable are nonnegligible, models of measurement error can be used; such methods are more robust for parameter estimation than for hypothesis testing or for computing confidence intervals.^{[4]}
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.
and since the gradient equations become
 .
The gradient equations apply to all least squares problems. Each particular problem requires particular expressions for the model and its partial derivatives.
Linear least squares
Main article: Linear least squaresA regression model is a linear one when the model comprises a linear combination of the parameters, i.e.,
where the coefficients, ϕ_{j}, are functions of x_{i}.
Letting
we can then see that in that case the least square estimate (or estimator, in the context of a random sample), is given by
For a derivation of this estimate see Linear least squares.
Functional analysis
See also: Fourier series and Generalized Fourier seriesA generalization to approximation of a data set is the approximation of a function by a sum of other functions, usually an orthogonal set:^{[5]}
with the set of functions {} an orthonormal set over the interval of interest, say [a, b]: see also Fejér's theorem. The coefficients {} 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]}
where the ‘*’ denotes complex conjugate in the case of complex functions. 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. The { } satisfy orthonormality relations:^{[7]}
where δ_{ij} is the Kronecker delta. Substituting function f_{n} into these equations then leads to the ndimensional Pythagorean theorem:^{[8]}
The coefficients {a_{j}} making f − f_{n}^{2} as small as possible are found to be:^{[5]}
The generalization of the ndimensional Pythagorean theorem to infinitedimensional real inner product spaces is known as Parseval's identity or Parseval's equation.^{[9]} Particular examples of such a representation of a function are the Fourier series and the generalized Fourier series.
Nonlinear least squares
Main article: Nonlinear least squaresThere is no closedform solution to a nonlinear 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.
k is an iteration number and the vector of increments, is known as the shift vector. In some commonly used algorithms, at each iteration the model may be linearized by approximation to a firstorder Taylor series expansion about
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
 .
To minimize the sum of squares of r_{i}, the gradient equation is set to zero and solved for
which, on rearrangement, become m simultaneous linear equations, the normal equations.
The normal equations are written in matrix notation as
These are the defining equations of the Gauss–Newton algorithm.
Differences between linear and nonlinear least squares
 The model function, f, in LLSQ (linear least squares) is a linear combination of parameters of the form The model may represent a straight line, a parabola or any other linear combination of functions. In NLLSQ (nonlinear least squares) the parameters appear as functions, such as β^{2},e^{βx} and so forth. If the derivatives are either constant or depend only on the values of the independent variable, the model is linear in the parameters. Otherwise the model is nonlinear.
 Algorithms for finding the solution to a NLLSQ problem require initial values for the parameters, LLSQ does not.
 Like LLSQ, solution algorithms for NLLSQ often require that the Jacobian be calculated. Analytical expressions for the partial derivatives can be complicated. If analytical expressions are impossible to obtain either the partial derivatives must be calculated by numerical approximation or an estimate must be made of the Jacobian.
 In NLLSQ nonconvergence (failure of the algorithm to find a minimum) is a common phenomenon whereas the LLSQ is globally concave so nonconvergence is not an issue.
 NLLSQ is usually an iterative process. The iterative process has to be terminated when a convergence criterion is satisfied. LLSQ solutions can be computed using direct methods, although problems with large numbers of parameters are typically solved with iterative methods, such as the Gauss–Seidel method.
 In LLSQ the solution is unique, but in NLLSQ there may be multiple minima in the sum of squares.
 Under the condition that the errors are uncorrelated with the predictor variables, LLSQ yields unbiased estimates, but even under that condition NLLSQ estimates are generally biased.
These differences must be considered whenever the solution to a nonlinear least squares problem is being sought.
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.
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, , where y_{i} is a measured spring extension. Each experimental observation will contain some error. If we denote this error ε, we may specify an empirical model for our observations,
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
The least squares estimate of the force constant, k, is given by
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.
 The Gauss–Markov theorem. In a linear model in which the errors have expectation zero conditional on the independent variables, are uncorrelated and have equal variances, the best linear unbiased estimator of any linear combination of the observations, is its leastsquares estimator. "Best" means that the least squares estimators of the parameters have minimum variance. The assumption of equal variance is valid when the errors all belong to the same distribution.
 In a linear model, if the errors belong to a Normal distribution the least squares estimators are also the maximum likelihood estimators.
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 mean is 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 , is usually estimated with
where the true residual variance σ^{2} is replaced by an estimate based on the minimised value of the sum of squares objective function S. The denominator, nm, is the statistical degrees of freedom; see effective degrees of freedom for generalizations.
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.
Weighted least squares
See also: Weighted meanThe 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, 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, is BLUE if each weight is equal to the reciprocal of the variance of the measurement.
The gradient equations for this sum of squares are
which, in a linear least squares system give the modified normal equations,
When the observational errors are uncorrelated and the weight matrix, W, is diagonal, these may be written as
If the errors are correlated, the resulting estimator is BLUE if the weight matrix is equal to the inverse of the variancecovariance matrix of the observations.
When the errors are uncorrelated, it is convenient to simplify the calculations to factor the weight matrix as . The normal equations can then be written as
where
For nonlinear least squares systems a similar argument shows that the normal equations should be modified as follows.
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.
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.
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 leastsquares solution with the constraint that , the L^{1}norm of the parameter vector, is no greater than a given value. Equivalently, it may solve an unconstrained minimization of the leastsquares penalty with 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 L^{1}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.^{[10]} For this reason, the LASSO and its variants are fundamental to the field of compressed sensing.
See also
 Best linear unbiased prediction (BLUP)
 L_{2} norm
 Least absolute deviation
 Measurement uncertainty
 Root mean square
 Squared deviations
 Quadratic loss function
Notes
 ^ Bretscher, Otto (1995). Linear Algebra With Applications, 3rd ed.. Upper Saddle River NJ: Prentice Hall.
 ^ Stigler, Stephen M. (1986). The History of Statistics: The Measurement of Uncertainty Before 1900. Cambridge, MA: Belknap Press of Harvard University Press. ISBN 0674403401.
 ^ See J. Aldrich (1998). "Doing Least Squares: Perspectives from Gauss and Yule". International Statistical Review 66 (1): 61–81. doi:10.1111/j.17515823.1998.tb00406.x.
 ^ Along with standard statistical methods for estimating measurementerror models, one may fit a model by total least squares.
 ^ ^{a} ^{b} Cornelius Lanczos (1988). Applied analysis (Reprint of 1956 PrenticeHall ed.). Dover Publications. pp. 212–213. ISBN 048665656X. http://books.google.com/books?id=6E85hExIqHYC&pg=PA212.
 ^ 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=ix2iCQo9x4C&pg=PA69.
 ^ Gerald B Folland (20090113). "Equation 3.17". cited work. p. 69. ISBN 0821847902. http://books.google.com/books?id=ix2iCQo9x4C&pg=PA69.
 ^ 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.
 ^ Gerald B Folland (20090113). "Equation 3.22". cited work. p. 77. ISBN 0821847902. http://books.google.com/books?id=ix2iCQo9x4C&pg=PA77.
 ^ Tibshirani, R. (1996). "Regression shrinkage and selection via the lasso.". J. Royal. Statist. Soc B. 58 (1): 267–288.
References
 Å. Björck (1996). Numerical Methods for Least Squares Problems. SIAM. ISBN 9780898713602. http://www.ecsecurehost.com/SIAM/ot51.html.
 C.R. Rao, H. Toutenburg, A. Fieger, C. Heumann, T. Nittner and S. Scheid (1999). Linear Models: Least Squares and Alternatives. Springer Series in Statistics.
 T. Kariya and H. Kurata (2004). Generalized Least Squares. Wiley.
 J. Wolberg (2005). Data Analysis Using the Method of Least Squares: Extracting the Most Information from Experiments. Springer. ISBN 3540256741.
 T. Strutz. Data Fitting and Uncertainty (A practical introduction to weighted least squares and beyond). Vieweg+Teubner. ISBN 9783834810229.
External links
 Derivation of quadratic least squares (Penn State)
 Power Point Statistics Book  Excellent slides providing an introductory regression example (University of Texas at Arlington)
 MIT Lecture on Least Squares and Projection Matrices
Least squares and regression analysis Computational statistics Least squares · Linear least squares · Nonlinear least squares · Iteratively reweighted least squaresCorrelation and dependence Regression analysis Regression as a
statistical modelSimple linear regression · Ordinary least squares · Generalized least squares · Weighted least squares · General linear modelPredictor structureNonstandardNonnormal errorsDecomposition of variance Model exploration Background Mean and predicted response · Gauss–Markov theorem · Errors and residuals · Goodness of fit · Studentized residual · Minimum meansquare errorDesign of experiments Numerical approximation Applications Regression analysis category  Statistics category · Statistics portal · Statistics outline · Statistics topics Categories: Least squares
 Regression analysis
 Single equation methods (econometrics)
 Mathematical and quantitative methods (economics)
 Mathematical optimization
Wikimedia Foundation. 2010.
Look at other dictionaries:
Least squares — Least Least (l[=e]st), a. [OE. last, lest, AS. l[=ae]sast, l[=ae]sest, superl. of l[=ae]ssa less. See {Less}, a.] [Used as the superlative of little.] Smallest, either in size or degree; shortest; lowest; most unimportant; as, the least insect;… … The Collaborative International Dictionary of English
least squares — least′ squares′ n. sta a statistical method of estimating values from a set of observations by minimizing the sum of the squares of the differences between the observations and the values to be found Also called least′ squares′ meth od. Etymology … From formal English to slang
least squares — n. a statistical method used to find the curve that most closely approximates a set of data: it is based on minimizing the sum of the squares of the differences between expected and observed values of the data … English World dictionary
least squares — noun a method of fitting a curve to data points so as to minimize the sum of the squares of the distances of the points from the curve • Syn: ↑method of least squares • Topics: ↑statistics • Hypernyms: ↑statistical method, ↑statistical procedure… … Useful english dictionary
Least Squares — Die Methode der kleinsten Quadrate (bezeichnender auch: der kleinsten Fehlerquadrate; englisch: Least Squares Method) ist das mathematische Standardverfahren zur Ausgleichungsrechnung. Es ist eine Wolke aus Datenpunkten gegeben, die physikalische … Deutsch Wikipedia
Least Squares — A statistical method used to determine a line of best fit by minimizing the sum of squares created by a mathematical function. A square is determined by squaring the distance between a data point and the regression line. The least squares… … Investment dictionary
least squares — Statistics. a method of estimating values from a set of observations by minimizing the sum of the squares of the differences between the observations and the values to be found. Also called least squares method, method of least squares. [1860 65] … Universalium
least squares — noun plural Date: 1825 a method of fitting a curve to a set of points representing statistical data in such a way that the sum of the squares of the distances of the points from the curve is a minimum … New Collegiate Dictionary
least squares — noun a method of estimating a quantity or fitting a graph to data so as to minimize the sum of the squares of the differences between the observed values and the estimated values … English new terms dictionary
least squares — /list ˈskwɛəz/ (say leest skwairz) plural noun a statistical method of determining constants from observations, by minimising squares of residuals between observations and their theoretical expected values … Australian English dictionary