A little more MathJax

I mostly use this forum to talk about mathematics with my students. If you’d like to see an actual such conversation that I had just a few weeks ago, you can check out this post.

Here’s a transcript of another such conversation that describes how to use a little bit of matrix algebra to help find the regression line of the form y=ax+b for the data

\{(-1,-1), (0,1), (2,0)\}.

This particular solution uses the so-called normal equations so it involves a fair amount of matrix manipulation. For the purposes here, it shows that a Discourse topic with a fair bit of math renders pretty quickly and that the AMS macros are supported.


To solve the problem, at any rate, I guess we gotta solve X[a\:\:b]^{\mathsf{T}}\approx \mathbf{y}, where the first column of X is formed by the x-coordinates of the points, the second column of X is all ones, and \mathbf{y} is the vector whose entries are the y-coordinates of the points. That is:

X = \begin{bmatrix} -1 & 1 \\ 0 & 1 \\ 2 & 1 \end{bmatrix} \: \: \: \text{and} \: \: \: \mathbf{y} = \begin{bmatrix} 0 \\ 1 \\ 1 \end{bmatrix}.

To do so, we’ll solve the normal equations:

X^\mathsf{T} X \begin{bmatrix}a\\b\end{bmatrix} = X^{\mathsf{T}} \mathbf{y}.

Well,

X^T X = \begin{bmatrix} -1 & 0 & 2 \\ 1 & 1 & 1 \end{bmatrix} \begin{bmatrix} -1 & 1 \\ 0 & 1 \\ 2 & 1 \end{bmatrix} = \begin{bmatrix} 5 & 1 \\ 1 & 3 \end{bmatrix}

and

X^T \mathbf{y} = \begin{bmatrix} -1 & 0 & 2 \\ 1 & 1 & 1 \end{bmatrix} \begin{bmatrix} 0 \\ 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 2 \\ 2 \end{bmatrix}.

So, we’ve got to solve

\begin{bmatrix} 5 & 1 \\ 1 & 3 \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} 2 \\ 2 \end{bmatrix}.

Doing so yields

a = \frac{2}{7} \text{ and } b = \frac{4}{7}.

Thus, the regression line is y = \frac{2}{7} x + \frac{4}{7}.