Four Points, Three Regressions
You observe four points in the plane, , , and . Find the single straight line that best fits these points.
Before reading on: which line would you choose, and how are you measuring the distance from a point to that line?
A tempting answer is . But is it the only correct one?
The hidden assumption
A line of best fit is defined by a loss function. Three natural choices give three different answers:
| Fitting rule | What gets squared | Optimum |
|---|---|---|
| OLS, predicting from | Vertical distances | , uniquely |
| OLS, predicting from | Horizontal distances | , uniquely |
| Orthogonal regression (TLS) | Perpendicular distances | Any line through |
The points are unchanged. Only the definition of “error” changes.
1. Vertical errors: ordinary least squares
Suppose is the dependent variable and we fit
OLS minimises the sum of squared vertical residuals:
Inserting the four points,
Both squared terms are non-negative, so the minimum is at and :
The line is horizontal. Two observations lie exactly on it; the other two are one unit above and below it.
2. Horizontal errors: reverse the regression
Now make the dependent variable and fit
which minimises the squared horizontal residuals:
The minimum is at :
The best-fitting line is now vertical, with exactly the same data.
3. Perpendicular errors: total least squares
Instead of treating one variable as the response, allow errors in both coordinates. Write the line in general form,
The condition makes a unit normal vector, so the squared perpendicular distance from to the line is simply . The total orthogonal loss is
It is minimised by , whatever the direction :
Every line through the origin is optimal: , , , and any other orientation. In Figure 1, the perpendicular total stays at for every angle.
4. No Preferred Direction
The sample is centred at the origin and has the same spread along both axes. Stacking the observations as the rows of a matrix ,
The two eigenvalues are equal. Principal component analysis, which gives the direction of the orthogonal least-squares fit, therefore has no unique leading direction.
This is more precise than saying “the covariance is zero”: zero covariance alone does not produce infinitely many TLS solutions. The degeneracy comes from the variances also being equal.
In practice this is a useful warning: an optimiser may still return a direction even when the data do not identify one. A result can be numerically valid without being uniquely determined by the data.
Takeaway
The first question in regression is not “which solver should I use?” It is:
With these four points:
- Predict from with vertical-error OLS: .
- Predict from with horizontal-error OLS: .
- Minimise perpendicular errors: every line through the origin is equally optimal.
Follow-up. Move the point slightly to the right. What happens to the OLS and orthogonal solutions, and which method becomes more sensitive to that small change?
Check it in Python
The script computes both OLS fits and the orthogonal loss at several angles. It requires numpy.
"""Four-point regression: reproduce vertical OLS, horizontal OLS and TLS losses.
Run: python regression_demo.py
Requires: pip install numpy
"""
import numpy as np
P = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]], dtype=float)
x, y = P[:, 0], P[:, 1]
# OLS that predicts y: vertical residuals.
m, c = np.linalg.lstsq(np.column_stack((x, np.ones(len(x)))), y, rcond=None)[0]
vertical_sse = np.sum((y - (m * x + c)) ** 2)
# OLS that predicts x: horizontal residuals.
a, b = np.linalg.lstsq(np.column_stack((y, np.ones(len(y)))), x, rcond=None)[0]
horizontal_sse = np.sum((x - (a * y + b)) ** 2)
print(f"Vertical OLS: y = {m:.1f}x + {c:.1f}; SSE = {vertical_sse:.1f}")
print(f"Horizontal OLS: x = {a:.1f}y + {b:.1f}; SSE = {horizontal_sse:.1f}")
for degrees in [0, 30, 45, 60, 90]:
theta = np.deg2rad(degrees)
normal = np.array([-np.sin(theta), np.cos(theta)])
tls_sse = np.sum((P @ normal) ** 2)
print(f"Orthogonal: angle = {degrees:>2}°, SSE = {tls_sse:.1f}")
assert np.isclose(tls_sse, 2)
print("P^T P =")
print(P.T @ P)
assert np.allclose(P.T @ P, 2 * np.eye(2))
Expected output:
Vertical OLS: y = 0.0x + 0.0; SSE = 2.0
Horizontal OLS: x = 0.0y + 0.0; SSE = 2.0
Orthogonal: angle = 0°, SSE = 2.0
Orthogonal: angle = 30°, SSE = 2.0
Orthogonal: angle = 45°, SSE = 2.0
Orthogonal: angle = 60°, SSE = 2.0
Orthogonal: angle = 90°, SSE = 2.0
P^T P =
[[2. 0.]
[0. 2.]]