1
$\begingroup$

I have four data points $(1,2), (2,4), (3,5), (5,7)$ and Im looking for the least squares regression line that best fits them.

I use the normal equation

$A^tAx=A^tb$

in this form -

$\begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & 2 & 3 & 4 \end{bmatrix}\begin{bmatrix} 1 & 1 \\ 1 & 2 \\ 1 & 3 \\ 1 & 4 \\ \end{bmatrix}\begin{bmatrix} c \\ m \end{bmatrix} = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 1 & 2 & 3 & 4 \end{bmatrix}\begin{bmatrix} 2 \\ 4 \\ 5 \\ 7 \\ \end{bmatrix}$

this gives -

$\begin{bmatrix} 4 & 10 \\ 10 & 30 \end{bmatrix}\begin{bmatrix} c \\ m \end{bmatrix} = \begin{bmatrix} 18 \\ 53 \end{bmatrix}$

I solved this system and got

$m = 1.3, c = 1.25$

so

$y = 1.3x + 1.25$

But if I put "linear fit {1,2},{2,4},{3,5},{4,7}" into wolfram alpha it gives $1.6x + 0.5$

So have I got it wrong?

1 Answers 1

2

Everything looks good until $\begin{bmatrix} 4 & 10 \\ 10 & 30 \end{bmatrix}\begin{bmatrix} c \\ m \end{bmatrix} = \begin{bmatrix} 18 \\ 53 \end{bmatrix}$, but then you have got bad solutions and wolframalpha is right. Also you should check last data point, is it $(4,7)$ or $(5,7)$?

  • 0
    Careless mistake in the simultaneous equation got me.2012-04-19