# janmr blog

## No-Intercept Simple Linear Regression December 19, 2023

The previous post considered the problem of finding the line that best fits a set of points in the plane, with the additional restriction that the points' center of mass was at the origin.

This post will consider points without any restrictions, but the line, however, must pass through the origin.

Let the points be given as $(x_i, y_i)$ for $i=1, \ldots, n$, where $n \geq 1$ is the number of points. We will furthermore require that not all $x_i$ are equal to zero or, equivalently, that $\sum_{i=1}^n x_i^2 > 0$.

Again, we will look for a least squares definition of best. So we seek a line $y = a x$ that minimizes the following error function:

$J = \sum_{i=1}^n (a x_i - y_i)^2.$

To find the stationary point of $J$, we set the partial derivative with respect to $a$ to zero:

\begin{align*} 0 = \tfrac{1}{2} \frac{\partial J}{\partial a} &= \sum_{i=1}^n x_i (a x_i - y_i) = a \sum_{i=1}^n x_i^2 - \sum_{i=1}^n x_i y_i \\ &= a s_{xx} - s_{xy} \; , \end{align*}

where

$s_{xy} = \sum_{i=1}^n x_i y_i \quad \text{and} \quad s_{xx} = \sum_{i=1}^n x_i^2.$

In conclusion, we have

$a = \frac{s_{xy}}{s_{xx}}.$

Note how this is the exact same slope as the case where the center of mass was at the origin.

Feel free to leave any question, correction or comment in this Mastodon thread.