A mathematical procedure for finding the best fitting curve to a given set of points by minimizing the sum of the squares of the offsets (``the residuals'') of the points from the curve. The sum of the squares of the offsets is used instead of the offset absolute values because this allows the residuals to be treated as a continuous differentiable quantity. However, because squares of the offsets are used, outlying points can have a disproportionate effect on the fit, a property which may or may not be desirable depending on the problem at hand.
In practice, the vertical offsets from a line are almost always minimized instead of the perpendicular offsets. This allows uncertainties of the data points along the  and axes to be incorporated simply, and also provides a much simpler analytic form for the fitting parameters than would be obtained using a fit based on perpendicular distances. In addition, the fitting technique can be easily generalized from a bestfit line to a bestfit polynomial when sums of vertical distances are used (which is not the case using perpendicular distances). For a reasonable number of noisy data points, the difference between vertical and perpendicular fits is quite small.
The linear least squares fitting technique is the simplest and most commonly applied form of Linear Regression and provides a solution to the problem of finding the best fitting straight line through a set of points. In fact, if the functional relationship between the two quantities being graphed is known to within additive or multiplicative constants, it is common practice to transform the data in such a way that the resulting line is a straight line, say by plotting vs. instead of vs. . For this reason, standard forms for Exponential, Logarithmic, and Power laws are often explicitly computed. The formulas for linear least squares fitting were independently derived by Gauß and Legendre.
For Nonlinear Least Squares Fitting to a number of unknown parameters, linear least squares fitting may be applied iteratively to a linearized form of the function until convergence is achieved. Depending on the type of fit and initial parameters chosen, the nonlinear fit may have good or poor convergence properties. If uncertainties (in the most general case, error ellipses) are given for the points, points can be weighted differently in order to give the highquality points more weight.
The residuals of the bestfit line for a set of points using unsquared perpendicular distances of points
are given by
(1) 
(2) 
(3) 
Unfortunately, because the absolute value function does not have continuous derivatives, minimizing is not
amenable to analytic solution. However, if the square of the perpendicular distances
(4) 
(5) 
(6) 
(7) 
(8) 
But
(9) 
(10) 
(11) 
(12) 
(13) 
(14) 
(15) 
(16) 
Vertical least squares fitting proceeds by finding the sum of the squares of the vertical deviations of a set
of data points
(17) 
The condition for to be a minimum is that
(18) 
(19) 
(20) 
(21) 
(22) 
(23) 
(24) 
(25) 
(26) 
The Matrix Inverse is
(27) 
(28)  
(29)  
(30)  
(31) 
(32)  
(33)  
(34) 
(35)  
(36)  
(37) 
(38)  
(39) 
In terms of the sums of squares, the Regression Coefficient is given by
(40) 
(41) 
(42) 
The Standard Errors for and are
(43)  
(44) 
(45) 
(46) 
(47) 
(48) 
Generalizing from a straight line (i.e., first degree polynomial) to a th degree Polynomial
(49) 
(50) 
(51) 
(52) 
(53) 
(54) 
(55) 
(56) 

(57) 
(58) 
(59) 
(60) 
(61) 
In Matrix notation, the equation for a polynomial fit is given by
(62) 
(63) 
(64) 
See also Correlation Coefficient, Interpolation, Least Squares FittingExponential, Least Squares FittingLogarithmic, Least Squares FittingPower Law, MoorePenrose Generalized Matrix Inverse, Nonlinear Least Squares Fitting, Regression Coefficient, Spline
References
Acton, F. S. Analysis of StraightLine Data. New York: Dover, 1966.
Bevington, P. R. Data Reduction and Error Analysis for the Physical Sciences. New York: McGrawHill, 1969.
Gonick, L. and Smith, W. The Cartoon Guide to Statistics. New York: Harper Perennial, 1993.
Kenney, J. F. and Keeping, E. S. ``Linear Regression, Simple Correlation, and Contingency.'' Ch. 8 in Mathematics of Statistics, Pt. 2, 2nd ed. Princeton, NJ: Van Nostrand, pp. 199237, 1951.
Kenney, J. F. and Keeping, E. S. ``Linear Regression and Correlation.'' Ch. 15 in Mathematics of Statistics, Pt. 1, 3rd ed. Princeton, NJ: Van Nostrand, pp. 252285, 1962.
Lancaster, P. and Salkauskas, K. Curve and Surface Fitting: An Introduction. London: Academic Press, 1986.
Lawson, C. and Hanson, R. Solving Least Squares Problems. Englewood Cliffs, NJ: PrenticeHall, 1974.
Nash, J. C. Compact Numerical Methods for Computers: Linear Algebra and Function Minimisation, 2nd ed. Bristol, England: Adam Hilger, pp. 2124, 1990.
Press, W. H.; Flannery, B. P.; Teukolsky, S. A.; and Vetterling, W. T. ``Fitting Data to a Straight Line'' ``StraightLine Data with Errors in Both Coordinates,'' and ``General Linear Least Squares.'' §15.2, 15.3, and 15.4 in Numerical Recipes in FORTRAN: The Art of Scientific Computing, 2nd ed. Cambridge, England: Cambridge University Press, pp. 655675, 1992.
York, D. ``LeastSquare Fitting of a Straight Line.'' Canad. J. Phys. 44, 10791086, 1966.
© 19969 Eric W. Weisstein