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?

$\endgroup$
2
$\begingroup$

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)$?

$\endgroup$
  • $\begingroup$ Careless mistake in the simultaneous equation got me. $\endgroup$ – Jim_CS Apr 19 '12 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.