← All algorithms

Regression

Orthogonal Regression & Geometric Mean Regression

2023-12-14

In ordinary linear regression, it is assumed that there is only an error in the dependent variable (y) while the independent variable (x) has no error. This assumption holds true when there is no measurement error in the independent variable, such as when x represents the order, time, or dependent variable in a simulation. The regression equation introduces the linear regression coefficients β0 and β1 such as:

\(y_i=\beta _0+\beta _1x_i+\epsilon _i\)​​

here, if the error

\(\epsilon_i\sim N(0,\sigma^2)\)

is assumed that a random variable follows a normal distribution with a mean of 0 and a variance of σ2, then through Maximum Likelihood Estimation (MLE) or Least Squares Estimation (LSE), we can determine the coefficients.


MLE (Maximum Likelihood Estimation)

The conditional probability P, also known as likelihood, of Y is,

\(P(Y|X,\beta _0,\beta _1,\sigma ^2)=\Pi _ip(y_i|x_i,\beta _0,\beta _1,\sigma ^2)=\Pi _i\dfrac{1}{(2\pi )^{1/2}(\sigma ^2)^{1/2}}\exp \begin{pmatrix}-\dfrac{(y_i-(\beta _0+\beta _1x_i))^2}{2\sigma ^2}\end{pmatrix}\)

\(=\dfrac{1}{(2\pi )^{1/2}(\sigma ^2)^{1/2}}\exp \begin{pmatrix}-\dfrac{(y_1-(\beta _0+\beta _1x_1))^2}{2\sigma^2}\end{pmatrix}* \dfrac{1}{(2\pi )^{1/2}(\sigma ^2)^{1/2}}\exp \begin{pmatrix}-\dfrac{(y_2-(\beta _0+\beta _1x_2))^2}{2\sigma ^2}\end{pmatrix}*\dots*\dfrac{1}{(2\pi )^{1/2}(\sigma ^2)^{1/2}}\exp \begin{pmatrix}-\dfrac{(y_n-(\beta _0+\beta _1x_n))^2}{2\sigma ^2}\end{pmatrix}\)

\(=(2\pi )^{-n/2}\sigma ^{-n}\exp \begin{pmatrix}-\dfrac{\sum _i^{\ }(y_i-(\beta _0+\beta _1x_i))^2}{2\sigma ^2}\end{pmatrix}\)

By taking the logarithm and using the property of log(ab) = log(a) + log(b),

\(\text{loglikelihood, }L(\beta _0,\beta _1,\sigma ^2)=-\dfrac{n}{2}\log (2\pi )-\dfrac{n}{2}\log (\sigma ^2)-\dfrac{1}{2}\dfrac{\sum _i^{\ }(y_i-(\beta _0+\beta _1x_i))^2}{\sigma ^2}\)

The parameter that needs to be optimized is the maximum likelihood or the maximum log-likelihood value. In other words, maximizing a negative value is equivalent to minimizing a positive value.

\(\arg \max _{\beta _0,\beta _1,\sigma ^2}^{ }\begin{Bmatrix}-\dfrac{n}{2}\log (\sigma ^2)-\dfrac{1}{2}\dfrac{\sum _i^{\ }(y_i-(\beta _0+\beta _1x_i))^2}{\sigma ^2}\end{Bmatrix}\)

\(=\arg \min _{\beta _0,\beta _1,\sigma ^2}^{ }\begin{Bmatrix}\dfrac{n}{2}\log (\sigma ^2)+\dfrac{1}{2}\dfrac{\sum _i^{\ }(y_i-(\beta _0+\beta _1x_i))^2}{\sigma ^2}\end{Bmatrix}\)

The coefficients that satisfy the minimum value can be obtained by taking the partial derivatives.

From \(\partial L/\partial \beta _0=0, \sum _i^{\ }(y_i-(\beta _0+\beta _1x_i))=0\rightarrow \beta _0=\overline {y}-\beta _1\overline {x}\)​

From \(\partial L/\partial \beta _1=0, \beta _1=\dfrac{\sum _{\ }^{\ }(x-\overline {x})(y-\overline {y})}{\sum _{\ }^{\ }(x-\overline {x})(x-\overline {x})}=S_{xy}/S_{xx}\)​​

From \(\partial L/\partial \sigma ^2=0, \sigma ^2=\dfrac{1}{n}\sum _i^{\ }(y_i-(\beta _0+\beta _1x_i))^2\)

If x and y are measured values in general (for example, tool-to-tool matching, comparing experimental results, etc.), we can assume that the independent variable (x) and dependent variable (y) include measurement errors ε and δ, and they follow the following normal distributions:

\(\epsilon _i\sim N(0,\sigma _{\epsilon }^2)\)

\(\delta _i\sim N(0,\sigma _{\delta }^2)\)

\(y_i=\eta _i+\epsilon _i\sim N(\eta _i,\sigma _{\epsilon }^2)\)

\(x_i=\xi _i+\delta _i\sim N(\xi _i,\sigma _{\delta }^2)\)

Here, ξ and η represent unobserved true independent variable (ξ) and true dependent variable (η) respectively, and the following linear regression equation holds.

\(\eta _i=\beta _0+\beta _1\xi _i\)​​

From these definitions,

\(y_i=\beta _0+\beta _1\xi _i+\epsilon _i=\beta_0+\beta_1(x_i-\delta_i)+\epsilon_i=\beta_0+\beta_1x_i+(\epsilon_i-\beta_1\delta_i)\)

Here we use the following normal distribution relationships to find the distribution of yi

\(A\sim N(a,\sigma_A^2)\)

\(B\sim N(b,\sigma_B^2)\)

\(A+B\sim N(a+b,\sigma_A^2+\sigma_B^2)\)

\(\alpha\cdot A\sim N(\alpha\cdot a,\alpha^2\cdot\sigma_A^2)\)

\(y_i \sim N(\beta_0+\beta_1\xi_i,\sigma_\epsilon^2)=N(\beta_0+\beta_1x_i,\sigma_\epsilon^2+\beta_1^2\sigma_\delta^2)\)

​

For the given dataset (x,y)

\((x,y) = (x_1,y_1),(x_2,y_2),\dots,(x_n,y_n)\)

their likelihood function, L becomes

\(L(\beta_0,\beta_1,\xi_i,\sigma_\epsilon^2,\sigma_\delta^2|(x,y))=(2\pi )^{-n}(\sigma_\epsilon^2\sigma_\delta^2)^{-n/2}\exp (-\dfrac{\sum _i^{\ }(x_i-\xi_i)^2}{2\sigma_\delta^2})\exp (-\dfrac{\sum _i^{\ }(y_i-\beta_0-\beta_1\xi_i)^2}{2\sigma_\epsilon^2})\)

If the measurement errors of x and y (ϵi , δi ), themselves are not known but their respective ratio λ=σϵ2/σδ2 is known, the likelihood function becomes

\(L(\beta_0,\beta_1,\xi_i,\sigma_\delta^2|(x,y))=(2\pi )^{-n}\lambda^{-n/2}\sigma_\delta^{-2n}\exp (-\dfrac{\sum _{\ }^{\ }\lbrace (x_i-\xi_i)^2+(y_i-(\beta_0+\beta_1\xi_i))^2/\lambda}{2\sigma_\delta^2}\rbrace\)

To find the value of ξi that maximizes the likelihood, we only need to consider values of below because all others are constant. 

\(\min \sum _{\ }^{\ }\lbrace \lambda(x_i-\xi_i)^2+(y_i-(\beta_0+\beta_1\xi_i))^2\rbrace\)

\(\partial/\partial\xi_i=0=\sum _{\ }^{\ }\lbrace -2\lambda(x_i-\xi_i)-2\beta_1(y_i-(\beta_0+\beta_1\xi_i))\rbrace\)

The optimal ξi can be derived as

\(\xi_i^*=(\lambda x_i+\beta_1(y_i-\beta_0))/(\lambda+\beta_1^2)\)

If substitute the value into the original formula,

\(\sum _{\ }^{\ }\lbrace (x_i-\xi_i)^2+\dfrac{1}{\lambda}(y_i-(\beta_0+\beta_1\xi_i))^2\rbrace =\dfrac{\sum _{\ }^{\ }(y_i-(\beta_0+\beta_1x_i))^2}{\lambda+\beta_1^2}\)

(refer the Node 1 below for the derivation procedure)

​

The final likelihood function, L becomes

\(L(\beta_0,\beta_1,\sigma_\delta^2|(x,y))=(2\pi )^{-n}\lambda ^{-n/2}\sigma_\delta^{-2n}\exp -\dfrac{\sum _{\ }^{\ }(y_i-(\beta_0+\beta_1x_i))^2}{2\sigma_\delta^2(\lambda +\beta_1^2)}\)

The coefficients (β0, β1) which produce the maximum value of the likelihood also fulfill the maximum of log likelihood, and log likelihood is much convenient to deal with, we take log of L,

\(\log L(\beta_0,\beta_1,\sigma_\delta^2|(x,y))=-n\log 2\pi -\dfrac{n}{2}\log \lambda -n\log \sigma_\delta^2-\dfrac{\sum _{\ }^{\ }(y_i-(\beta_0+\beta_1x_i))^2}{2\sigma_\delta^2(\lambda +\beta_1^2)}\)

Now find argmax of the log likelihood in term of (β0, β1) which is same to find argmin of the negative log likelihood:

\(\arg \max _{\beta_0,\beta_1,\delta^2}^{ }\begin{Bmatrix}-\dfrac{n}{2}\log \lambda -n\log \sigma_\delta^2-\dfrac{\sum _{\ }^{\ }(y_i-(\beta_0+\beta_1x_i))^2}{2\sigma_\delta^2(\lambda +\beta_1^2)}\end{Bmatrix}\)

\(=\arg \min _{\beta_0,\beta_1,\sigma^2}^{ }\begin{Bmatrix}\dfrac{n}{2}\log \lambda +n\log \sigma_\delta^2+\dfrac{\sum _{\ }^{\ }(y_i-(\beta_0+\beta_1x_i))^2}{2\sigma_\delta^2(\lambda +\beta_1^2)}\end{Bmatrix}\)

From ∂L/∂β0 = 0,

\(\beta_0=\overline {y}-\beta_1\overline {x}\)

From ∂L/∂β1 = 0,

\(S_{xy}\beta_1^2-(S_{yy}-\lambda S_{xx})\beta_1-\lambda S_{xy}=0\)

The roots of the above quadratic equation β1 become

\(\beta_1=\dfrac{S_{yy}-\lambda S_{xx}+\sqrt{(S_{yy}-\lambda S_{xx})2+4\lambda S_{xy}^2)}}{2S_{xy}}\)​​​

(refer the Note 2 below for the detail derivation procedure)

From \(\partial L/\partial\sigma_\delta^2=0\)

\(\sigma_\delta^2=\dfrac{\sum _{\ }^{\ }(y_i-(\beta_0+\beta_1x_i))^2}{2n(\lambda+\beta_1^2)}\)

If the proportion of variance, λ=1, the regression is called orthogonal regression, whose coefficients minimize the shortest distance between the data and the regression equation. If λ = Syy/Sxx, β1 becomes sqrt(Syy/Sxx) and the regression is called geometric mean regression. In particular, the geometric mean satisfies X = - b0/b1 + 1/b1Y, derived from Y = b0 + b1X. In other words, the geometric mean regression takes the midpoint between the regression line Y = b0 + b1X and the regression line X = a0 + a1Y.

​

Following table shows the comparison of the coefficients among three regression algorithms.

In the attached Excel worksheet, one (x, y) set of the random numbers was generated for η=ξ using σ=5, τ=5, and shown the comparison of the least square regression, the orthogonal regression, and the geometric mean regression as shown in the two charts below.

X = 1:50+NORM.INV(RAND(),0,5)

Y = 1:50+NORM.INV(RAND(),0,5)

Sxx=SUMSQ(X-AVERAGE(X))

Sxy=SUMPRODUCT(X-AVERAGE(X),Y-AVERAGE(Y))

Syy=SUMSQ(Y-AVERAGE(Y))

​

(Note 1) Derivation of the formula to find ξi* 

\(\sum _{\ }^{\ }\begin{Bmatrix}(x_i-\xi _i)^2+\dfrac{1}{\lambda }(y_i-(\beta _0+\beta _1\xi _i))^2\end{Bmatrix}\)

\(=\sum _{\ }^{\ }\begin{Bmatrix}(x_i-\dfrac{\lambda x_i+\beta _1(y_i-\beta _0)}{\lambda +\beta _1^2})^2+\dfrac{1}{\lambda }(y_i-(\beta _0+\beta _1\dfrac{\lambda x_i+\beta _1(y_i-\beta _0)}{\lambda +\beta _1^2}))^2\end{Bmatrix}\)

\(=\sum _{\ }^{\ }\begin{Bmatrix}(\dfrac{x_i(\lambda +\beta _1^2)-\lambda x_i+\beta _1(y_i-\beta _0)}{\lambda +\beta _1^2})^2+\dfrac{1}{\lambda }(\dfrac{y_i-\beta _0)(\lambda +\beta _1^2)-\beta _1\lambda x_i-\beta _1^2(y_i-\beta _0)}{\lambda +\beta _1^2}))^2\end{Bmatrix}\)

\(=\sum _{\ }^{\ }\begin{Bmatrix}(\dfrac{-\beta _1(y_i-\beta _0-\beta _1x_i)}{\lambda +\beta _1^2})^2+(\dfrac{y_i-\beta _0-\beta _1x_i}{\lambda +\beta _1^2})^2\end{Bmatrix}\)

\(=\sum _{\ }^{\ }\begin{Bmatrix}(\dfrac{(y_i-\beta _0-\beta _1x_i)}{\lambda +\beta _1^2})^2(\lambda +\beta _1^2)\end{Bmatrix}\)

\(=\dfrac{1}{\lambda +\beta _1^2}\sum _{\ }^{\ }(y_i-\beta _0-\beta _1x_i)^2\)

(Note 2) Derivation of the formula to find ∂L/∂β1 = 0


\(\dfrac{(y-\beta _1x)^T(-x)(\lambda +\beta _1^2)\sigma _{\delta }^2-(y-\beta _1x)^T(y-\beta _1x)\beta _1\sigma _{\delta }^2}{((\lambda +\beta _1^2)\sigma _{\delta }^2)^2}=0\)

\(\longrightarrow (y-\beta _1x)^T(-x)(\lambda +\beta _1^2)\sigma _{\delta }^2-(y-\beta _1x)^T(y-\beta _1x)\beta _1\sigma _{\delta }^2=0\)

\((y-\beta _1x)^T(-x)(\lambda +\beta _1^2)\sigma _{\delta }^2-(y-\beta _1x)^T(y-\beta _1x)\beta _1=0\)

\(-\lambda y^Tx+\lambda \beta _1x^Tx-\beta _1^2y^Tx+\beta _1^3x^Tx-\beta _1y^Ty+2\beta _1^2x^Ty-\beta _1^3x^Tx=0\)

\(\xrightarrow {x^Ty=S_{xy},x^Tx=S_{xx},y^Ty=S_{yy}}{-}\lambda S_{xy}+\lambda \beta _1S_{xx}-\beta _1^2S_{xy}+\beta _1^3S_{xx}-\beta _1S_{yy}+2\beta _1^2S_{xy}-\beta _1^3S_{xx}=0\)

\(-\lambda S_{xy}-\beta _1(S_{yy}-\lambda S_{xx})+S_{xy}\beta _1^2=0\)

​