Orthogonal Distance Fit

When both axes are affected by error (noise as a function of distance), the cost function $S$ that maximizes the likelihood is called the orthogonal least-squares line fit. The error can be expressed as the distance between the point and the line, according to Equation (1.67). Regression using this metric, also called perpendicular regression or total least squares (see Section 4.2.2), is appropriate when both coordinates are affected by error, that is, when both are random variables. The noise levels in the two components are assumed to be equal (for the more general case, see the discussion in Section 2.4). The error function $S$ to be minimized is the distance between the point and the line:

\begin{displaymath}
S = \frac{1}{2n}\sum_{i=1}^{n} { \frac{(a x_i + b y_i + c)^2}{a^2 + b^2} }
\end{displaymath} (4.103)

The minimum is found at $\nabla S = 0$. Note that in the case of perpendicular distance, both a minimum and a maximum exist as solutions, and therefore two lines, orthogonal to each other, solve the system.

The partial derivative $\frac{ \partial S}{\partial c}=0$ shows that the regression line passes through the centroid $(\bar{x},\bar{y})$ of the distribution, that is,

\begin{displaymath}
c = - a \bar{x} - b \bar{y}
\end{displaymath} (4.104)

where $\bar{x}$ and $\bar{y}$ are the means of the samples $x_i$ and $y_i$, respectively.

Using the relationship (4.104), the error function (4.103) can be written as:

\begin{displaymath}
S = \frac{a^2 \left(\bar{x^2} - \bar{x}^2 \right) + 2 ab \le...
... \right) + b^2 \left(\bar{y^2} - \bar{y}^2 \right)}{a^2 + b^2}
\end{displaymath} (4.105)

or, after suitable substitutions $S_{xx} = \text{var}(x)$, $S_{yy} = \text{var}(y)$, and $S_{xy} = \text{cov}(x,y)$:
\begin{displaymath}
S = \frac{a^2 S_{xx} + 2 ab S_{xy} + b^2 S_{yy} }{a^2 + b^2}
\end{displaymath} (4.106)

which is easier to differentiate. The error expression (4.106) is not general; it holds only for lines passing through the centroid of the distribution. Since it is a homogeneous form, it is defined only up to a multiplicative factor. Thus, there is not a unique solution but rather a relationship between the parameters. Excluding the cases $a=0$, $b=0$, which must be treated separately, the condition for finding the minimum or maximum has the form
\begin{displaymath}
(a^2 -b^{2}) S_{xy} + a b (S_{yy} - S_{xx}) = 0
\end{displaymath} (4.107)

which solves the problem.

Finally, note that the same result can be obtained much more simply by applying singular value decomposition (SVD) to the centered point matrix. The resulting line coincides with the orthogonal regression line (total least squares) and therefore minimizes the geometric error defined as the orthogonal distance of the points from the line.

Paolo medici
2026-10-19