Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
Careless mistake in the simultaneous equation got me. –  Jim_CS Apr 19 '12 at 23:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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