Total least squares
Part of a series on 
Regression analysis 

Models 
Estimation 
Background 

In applied statistics, total least squares is a type of errorsinvariables regression, a least squares data modeling technique in which observational errors on both dependent and independent variables are taken into account. It is a generalization of Deming regression and also of orthogonal regression, and can be applied to both linear and nonlinear models.
The total least squares approximation of the data is generically equivalent to the best, in the Frobenius norm, lowrank approximation of the data matrix.^{[1]}
Linear model
Background
In the least squares method of data modeling, the objective function, S,
 [math]\displaystyle{ S=\mathbf{r^TWr}, }[/math]
is minimized, where r is the vector of residuals and W is a weighting matrix. In linear least squares the model contains equations which are linear in the parameters appearing in the parameter vector [math]\displaystyle{ \boldsymbol\beta }[/math], so the residuals are given by
 [math]\displaystyle{ \mathbf{r=yX\boldsymbol\beta}. }[/math]
There are m observations in y and n parameters in β with m>n. X is a m×n matrix whose elements are either constants or functions of the independent variables, x. The weight matrix W is, ideally, the inverse of the variancecovariance matrix [math]\displaystyle{ \mathbf M_y }[/math] of the observations y. The independent variables are assumed to be errorfree. The parameter estimates are found by setting the gradient equations to zero, which results in the normal equations ^{[note 1]}
 [math]\displaystyle{ \mathbf{X^TWX\boldsymbol\beta=X^T Wy}. }[/math]
Allowing observation errors in all variables
Now, suppose that both x and y are observed subject to error, with variancecovariance matrices [math]\displaystyle{ \mathbf M_x }[/math] and [math]\displaystyle{ \mathbf M_y }[/math] respectively. In this case the objective function can be written as
 [math]\displaystyle{ S=\mathbf{r_x^TM_x^{1}r_x+r_y^TM_y^{1}r_y}, }[/math]
where [math]\displaystyle{ \mathbf r_x }[/math] and [math]\displaystyle{ \mathbf r_y }[/math] are the residuals in x and y respectively. Clearly^{[further explanation needed]} these residuals cannot be independent of each other, but they must be constrained by some kind of relationship. Writing the model function as [math]\displaystyle{ \mathbf{f(r_x,r_y,\boldsymbol\beta)} }[/math], the constraints are expressed by m condition equations.^{[2]}
 [math]\displaystyle{ \mathbf{F=\Delta y \frac{\partial f}{\partial r_x} r_x\frac{\partial f}{\partial r_y} r_y X\Delta\boldsymbol\beta=0}. }[/math]
Thus, the problem is to minimize the objective function subject to the m constraints. It is solved by the use of Lagrange multipliers. After some algebraic manipulations,^{[3]} the result is obtained.
 [math]\displaystyle{ \mathbf{X^TM^{1}X\Delta \boldsymbol\beta=X^T M^{1} \Delta y}, }[/math]
or alternatively [math]\displaystyle{ \mathbf{X^TM^{1}X \boldsymbol\beta=X^T M^{1} y}, }[/math] where M is the variancecovariance matrix relative to both independent and dependent variables.
 [math]\displaystyle{ \mathbf{M=K_xM_xK_x^T+K_yM_yK_y^T;\ K_x=\frac{\partial f}{\partial r_x},\ K_y=\frac{\partial f}{\partial r_y}}. }[/math]
Example
When the data errors are uncorrelated, all matrices M and W are diagonal. Then, take the example of straight line fitting.
 [math]\displaystyle{ f(x_i,\beta)=\alpha + \beta x_i }[/math]
in this case
 [math]\displaystyle{ M_{ii}=\sigma^2_{y,i}+\beta^2 \sigma^2_{x,i} }[/math]
showing how the variance at the ith point is determined by the variances of both independent and dependent variables and by the model being used to fit the data. The expression may be generalized by noting that the parameter [math]\displaystyle{ \beta }[/math] is the slope of the line.
 [math]\displaystyle{ M_{ii}=\sigma^2_{y,i}+\left(\frac{dy}{dx}\right)^2_i \sigma^2_{x,i} }[/math]
An expression of this type is used in fitting pH titration data where a small error on x translates to a large error on y when the slope is large.
Algebraic point of view
As was shown in 1980 by Golub and Van Loan, the TLS problem does not have a solution in general.^{[4]} The following considers the simple case where a unique solution exists without making any particular assumptions.
The computation of the TLS using singular value decomposition (SVD) is described in standard texts.^{[5]} We can solve the equation
 [math]\displaystyle{ XB \approx Y }[/math]
for B where X is mbyn and Y is mbyk. ^{[note 2]}
That is, we seek to find B that minimizes error matrices E and F for X and Y respectively. That is,
 [math]\displaystyle{ \mathrm{argmin}_{B,E,F} \ [E\; F] \_F, \qquad (X+E) B = Y+F }[/math]
where [math]\displaystyle{ [E\; F] }[/math] is the augmented matrix with E and F side by side and [math]\displaystyle{ \\cdot\_F }[/math] is the Frobenius norm, the square root of the sum of the squares of all entries in a matrix and so equivalently the square root of the sum of squares of the lengths of the rows or columns of the matrix.
This can be rewritten as
 [math]\displaystyle{ [(X+E) \; (Y+F)] \begin{bmatrix} B\\ I_k\end{bmatrix} = 0. }[/math]
where [math]\displaystyle{ I_k }[/math] is the [math]\displaystyle{ k\times k }[/math] identity matrix. The goal is then to find [math]\displaystyle{ [E\; F] }[/math] that reduces the rank of [math]\displaystyle{ [X\; Y] }[/math] by k. Define [math]\displaystyle{ [U] [\Sigma] [V]^* }[/math] to be the singular value decomposition of the augmented matrix [math]\displaystyle{ [X\; Y] }[/math].
 [math]\displaystyle{ [X\; Y] = [U_X\; U_Y] \begin{bmatrix}\Sigma_X &0 \\ 0 & \Sigma_Y\end{bmatrix}\begin{bmatrix}V_{XX} & V_{XY} \\ V_{YX} & V_{YY}\end{bmatrix}^* = [U_X\; U_Y] \begin{bmatrix}\Sigma_X &0 \\ 0 & \Sigma_Y\end{bmatrix} \begin{bmatrix} V_{XX}^* & V_{YX}^* \\ V_{XY}^* & V_{YY}^*\end{bmatrix} }[/math]
where V is partitioned into blocks corresponding to the shape of X and Y.
Using the Eckart–Young theorem, the approximation minimising the norm of the error is such that matrices [math]\displaystyle{ U }[/math] and [math]\displaystyle{ V }[/math] are unchanged, while the smallest [math]\displaystyle{ k }[/math] singular values are replaced with zeroes. That is, we want
 [math]\displaystyle{ [(X+E)\; (Y+F)] = [U_X\; U_Y] \begin{bmatrix}\Sigma_X &0 \\ 0 & 0_{k\times k}\end{bmatrix}\begin{bmatrix}V_{XX} & V_{XY} \\ V_{YX} & V_{YY}\end{bmatrix}^* }[/math]
so by linearity,
 [math]\displaystyle{ [E\; F] = [U_X\; U_Y] \begin{bmatrix}0_{n\times n} &0 \\ 0 & \Sigma_Y\end{bmatrix}\begin{bmatrix}V_{XX} & V_{XY} \\ V_{YX} & V_{YY}\end{bmatrix}^*. }[/math]
We can then remove blocks from the U and Σ matrices, simplifying to
 [math]\displaystyle{ [E\; F] = U_Y\Sigma_Y \begin{bmatrix}V_{XY}\\V_{YY}\end{bmatrix}^*= [X\; Y] \begin{bmatrix}V_{XY}\\V_{YY}\end{bmatrix}\begin{bmatrix}V_{XY}\\ V_{YY}\end{bmatrix}^*. }[/math]
This provides E and F so that
 [math]\displaystyle{ [(X+E) \; (Y+F)] \begin{bmatrix}V_{XY}\\ V_{YY}\end{bmatrix} = 0. }[/math]
Now if [math]\displaystyle{ V_{YY} }[/math] is nonsingular, which is not always the case (note that the behavior of TLS when [math]\displaystyle{ V_{YY} }[/math] is singular is not well understood yet), we can then right multiply both sides by [math]\displaystyle{ V_{YY}^{1} }[/math] to bring the bottom block of the right matrix to the negative identity, giving^{[6]}
 [math]\displaystyle{ [(X+E) \; (Y+F)] \begin{bmatrix} V_{XY} V_{YY}^{1} \\ V_{YY} V_{YY}^{1}\end{bmatrix} = [(X+E) \; (Y+F)] \begin{bmatrix} B\\ I_k\end{bmatrix} = 0 , }[/math]
and so
 [math]\displaystyle{ B=V_{XY} V_{YY}^{1}. }[/math]
A naive GNU Octave implementation of this is:
function B = tls(X, Y) [m n] = size(X); % n is the width of X (X is m by n) Z = [X Y]; % Z is X augmented with Y. [U S V] = svd(Z, 0); % find the SVD of Z. VXY = V(1:n, 1+n:end); % Take the block of V consisting of the first n rows and the n+1 to last column VYY = V(1+n:end, 1+n:end); % Take the bottomright block of V. B = VXY / VYY; end
The way described above of solving the problem, which requires that the matrix [math]\displaystyle{ V_{YY} }[/math] is nonsingular, can be slightly extended by the socalled classical TLS algorithm.^{[7]}
Computation
The standard implementation of classical TLS algorithm is available through Netlib, see also.^{[8]}^{[9]} All modern implementations based, for example, on solving a sequence of ordinary least squares problems, approximate the matrix [math]\displaystyle{ B }[/math] (denoted [math]\displaystyle{ X }[/math] in the literature), as introduced by Van Huffel and Vandewalle. It is worth noting, that this [math]\displaystyle{ B }[/math] is, however, not the TLS solution in many cases.^{[10]}^{[11]}
Nonlinear model
For nonlinear systems similar reasoning shows that the normal equations for an iteration cycle can be written as
 [math]\displaystyle{ \mathbf{J^TM^{1}J\Delta \boldsymbol\beta=J^T M^{1} \Delta y}, }[/math]
where [math]\displaystyle{ \mathbf{J} }[/math] is the Jacobian matrix.
Geometrical interpretation
When the independent variable is errorfree a residual represents the "vertical" distance between the observed data point and the fitted curve (or surface). In total least squares a residual represents the distance between a data point and the fitted curve measured along some direction. In fact, if both variables are measured in the same units and the errors on both variables are the same, then the residual represents the shortest distance between the data point and the fitted curve, that is, the residual vector is perpendicular to the tangent of the curve. For this reason, this type of regression is sometimes called two dimensional Euclidean regression (Stein, 1983)^{[12]} or orthogonal regression.
Scale invariant methods
A serious difficulty arises if the variables are not measured in the same units. First consider measuring distance between a data point and the line: what are the measurement units for this distance? If we consider measuring distance based on Pythagoras' Theorem then it is clear that we shall be adding quantities measured in different units, which is meaningless. Secondly, if we rescale one of the variables e.g., measure in grams rather than kilograms, then we shall end up with different results (a different line). To avoid these problems it is sometimes suggested that we convert to dimensionless variables—this may be called normalization or standardization. However, there are various ways of doing this, and these lead to fitted models which are not equivalent to each other. One approach is to normalize by known (or estimated) measurement precision thereby minimizing the Mahalanobis distance from the points to the line, providing a maximumlikelihood solution;^{[citation needed]} the unknown precisions could be found via analysis of variance.
In short, total least squares does not have the property of unitsinvariance—i.e. it is not scale invariant. For a meaningful model we require this property to hold. A way forward is to realise that residuals (distances) measured in different units can be combined if multiplication is used instead of addition. Consider fitting a line: for each data point the product of the vertical and horizontal residuals equals twice the area of the triangle formed by the residual lines and the fitted line. We choose the line which minimizes the sum of these areas. Nobel laureate Paul Samuelson proved in 1942 that, in two dimensions, it is the only line expressible solely in terms of the ratios of standard deviations and the correlation coefficient which (1) fits the correct equation when the observations fall on a straight line, (2) exhibits scale invariance, and (3) exhibits invariance under interchange of variables.^{[13]} This solution has been rediscovered in different disciplines and is variously known as standardised major axis (Ricker 1975, Warton et al., 2006),^{[14]}^{[15]} the reduced major axis, the geometric mean functional relationship (Draper and Smith, 1998),^{[16]} least products regression, diagonal regression, line of organic correlation, and the least areas line (Tofallis, 2002).^{[17]}
Tofallis (2015, 2023) ^{[18]} ^{[19]} has extended this approach to deal with multiple variables. The calculations are simpler than for total least squares as they only require knowledge of covariances, and can be computed using standard spreadsheet functions.
See also
 Regression dilution
 Deming regression, a special case with two predictors and independent errors.
 Errorsinvariables model
 GaussHelmert model
 Linear regression
 Least squares
 Principal component analysis
 Principal component regression
Notes
 ↑ An alternative form is [math]\displaystyle{ \mathbf{X^TWX\boldsymbol\Delta \boldsymbol\beta=X^T W \boldsymbol\Delta y} }[/math], where [math]\displaystyle{ \boldsymbol\Delta \boldsymbol\beta }[/math] is the parameter shift from some starting estimate of [math]\displaystyle{ \boldsymbol\beta }[/math] and [math]\displaystyle{ \boldsymbol\Delta \mathbf y }[/math] is the difference between y and the value calculated using the starting value of [math]\displaystyle{ \boldsymbol\beta }[/math]
 ↑ The notation XB ≈ Y is used here to reflect the notation used in the earlier part of the article. In the computational literature the problem has been more commonly presented as AX ≈ B, i.e. with the letter X used for the nbyk matrix of unknown regression coefficients.
References
 ↑ I. Markovsky and S. Van Huffel, Overview of total least squares methods. Signal Processing, vol. 87, pp. 2283–2302, 2007. preprint
 ↑ W.E. Deming, Statistical Adjustment of Data, Wiley, 1943
 ↑ Gans, Peter (1992). Data Fitting in the Chemical Sciences. Wiley. ISBN 9780471934127. http://www.wiley.com/WileyCDA/WileyTitle/productCd0471934127.html. Retrieved 4 December 2012.
 ↑ G. H. Golub and C. F. Van Loan, An analysis of the total least squares problem. Numer. Anal., 17, 1980, pp. 883–893.
 ↑ Matrix Computations (3rd ed.). The Johns Hopkins University Press. 1996. pp 596.
 ↑ Bjõrck, Ake (1996) Numerical Methods for Least Squares Problems, Society for Industrial and Applied Mathematics. ISBN:9780898713602^{[page needed]}
 ↑ S. Van Huffel and J. Vandewalle (1991) The Total Least Squares Problems: Computational Aspects and Analysis. SIAM Publications, Philadelphia PA.
 ↑ S. Van Huffel, Documented Fortran 77 programs of the extended classical total least squares algorithm, the partial singular value decomposition algorithm and the partial total least squares algorithm, Internal Report ESATKUL 88/1, ESAT Lab., Dept. of Electrical Engineering, Katholieke Universiteit Leuven, 1988.
 ↑ S. Van Huffel, The extended classical total least squares algorithm, J. Comput. Appl. Math., 25, pp. 111–119, 1989.
 ↑ M. Plešinger, The Total Least Squares Problem and Reduction of Data in AX ≈ B. Doctoral Thesis, TU of Liberec and Institute of Computer Science, AS CR Prague, 2008. Ph.D. Thesis
 ↑ I. Hnětynková, M. Plešinger, D. M. Sima, Z. Strakoš, and S. Van Huffel, The total least squares problem in AX ≈ B. A new classification with the relationship to the classical works. SIMAX vol. 32 issue 3 (2011), pp. 748–770.
 ↑ Stein, Yaakov J.. Two Dimensional Euclidean Regression. http://www.dspcsp.com/pubs/euclreg.pdf.
 ↑ Samuelson, Paul A. (1942). "A Note on Alternative Regressions". Econometrica 10 (1): 80–83. doi:10.2307/1907024.
 ↑ Ricker, W. E. (1975). "A note concerning Professor Jolicoeur's Comments". Journal of the Fisheries Research Board of Canada 32 (8): 1494–1498. doi:10.1139/f75172.
 ↑ Warton, David I.; Wright, Ian J.; Falster, Daniel S.; Westoby, Mark (2006). "Bivariate linefitting methods for allometry". Biological Reviews 81 (2): 259–291. doi:10.1017/S1464793106007007. PMID 16573844.
 ↑ Draper, NR and Smith, H. Applied Regression Analysis, 3rd edition, pp. 92–96. 1998
 ↑ Tofallis, Chris (2002). "Model Fitting for Multiple Variables by Minimising the Geometric Mean Deviation". in Van Huffel, Sabine; Lemmerling, P.. Total Least Squares and ErrorsinVariables Modeling: Analysis, Algorithms and Applications. Dordrecht: Kluwer Academic Publ.. ISBN 9781402004766.
 ↑ Template:Cite SSRN
 ↑ Tofallis, C. (2023). Fitting an Equation to Data Impartially. Mathematics, 11(18), 3957. https://ssrn.com/abstract=4556739 https://doi.org/10.3390/math11183957
Others
 I. Hnětynková, M. Plešinger, D. M. Sima, Z. Strakoš, and S. Van Huffel, The total least squares problem in AX ≈ B. A new classification with the relationship to the classical works. SIMAX vol. 32 issue 3 (2011), pp. 748–770. Available as a preprint.
 M. Plešinger, The Total Least Squares Problem and Reduction of Data in AX ≈ B. Doctoral Thesis, TU of Liberec and Institute of Computer Science, AS CR Prague, 2008. Ph.D. Thesis
 C. C. Paige, Z. Strakoš, Core problems in linear algebraic systems. SIAM J. Matrix Anal. Appl. 27, 2006, pp. 861–875. doi:10.1137/040616991
 S. Van Huffel and P. Lemmerling, Total Least Squares and ErrorsinVariables Modeling: Analysis, Algorithms and Applications. Dordrecht, The Netherlands: Kluwer Academic Publishers, 2002.
 S. Jo and S. W. Kim, Consistent normalized least mean square filtering with noisy data matrix. IEEE Trans. Signal Process., vol. 53, no. 6, pp. 2112–2123, Jun. 2005.
 R. D. DeGroat and E. M. Dowling, The data least squares problem and channel equalization. IEEE Trans. Signal Process., vol. 41, no. 1, pp. 407–411, Jan. 1993.
 S. Van Huffel and J. Vandewalle, The Total Least Squares Problems: Computational Aspects and Analysis. SIAM Publications, Philadelphia PA, 1991. doi:10.1137/1.9781611971002
 T. Abatzoglou and J. Mendel, Constrained total least squares, in Proc. IEEE Int. Conf. Acoust., Speech, Signal Process. (ICASSP’87), Apr. 1987, vol. 12, pp. 1485–1488.
 P. de Groen An introduction to total least squares, in Nieuw Archief voor Wiskunde, Vierde serie, deel 14, 1996, pp. 237–253 arxiv.org.
 G. H. Golub and C. F. Van Loan, An analysis of the total least squares problem. SIAM J. on Numer. Anal., 17, 1980, pp. 883–893. doi:10.1137/0717073
 Perpendicular Regression Of A Line at MathPages
 A. R. AmiriSimkooei and S. Jazaeri Weighted total least squares formulated by standard least squares theory,in Journal of Geodetic Science, 2 (2): 113–124, 2012 [1].
Original source: https://en.wikipedia.org/wiki/Total least squares.
Read more 