# linear Regression Simplification

I am trying to use a linear regression with four data points to calculate only the slope $b$. I am not interested in the point $a$ where the y-axis is crossed.

I have the following equation for the linear least square method:

$S(a,b) = \sum_{i=1}^{4} (y_i - a - bx_i)^2$

Setting the partial derivates to zero gives the following equation system

1: $\frac{\partial S}{\partial a} = \sum_{i=1}^{4} (2a + 2bx_i - 2y_i) := 0$

2: $\frac{\partial S}{\partial b} = \sum_{i=1}^{4} (2ax_i + 2bx_i^2 - 2x_iy_i) := 0$

Until now I think everything is correct.

But my assumption proved to be wrong: I thought I could just get rid of equation 1 and only use equation 2 by setting $a := const = 0$. To my understanding this fitts the line to a line going through the origin with a wrong slope.

Can I simplify the problem in any way or should I implement a standard linear regression, calculating $a$ and $b$ and then just discard $a$?

Edit: What got me really confused is when I tried to verify my (wrong) solution with four test points $(1,1)$, $(2,2)$, $(3,3)$ and $(4,4)$. My solution was:

3: $\frac{\partial S}{\partial b} = \sum_{i=1}^{4} (2bx_i^2 -2x_iy_i)$

4: $b = \frac{\sum_{i=1}^{4}x_iy_i}{\sum_{i=1}^{4}x_i^2} = \frac{1+4+9+16}{1+2+3+4} = 3$

It got me confused since this should give the correct result of $b = 1$ since $a = 0$ anyway.

Edit: Corrected mistake. Still my assumption that I can just set $a = 0$ and use the same data points with equation 4 is wrong. I checked with $(1,2)$, $(2,3)$, $(3,4)$ and $(4,5)$. But if I subtract the vector (x_1, y_1) from each data point I shift the coordinate system to a resulting line through the origin. I think?

• You made a mistake $b = \frac{\sum_{i=1}^{4}x_iy_i}{\sum_{i=1}^{4}x_i^2}$ Apr 28, 2016 at 10:24
• @Claude: Thanks a lot for the correction. Apr 28, 2016 at 10:35

$b = \frac{\sum_{i=1}^4 (x_i - x_1)(y_i - y1)}{\sum_{i=1}^4 (x_i - x_1)^2} = \frac{\sum_{i=2}^4 (x_i - x_1)(y_i - y1)}{\sum_{i=2}^4 (x_i - x_1)^2}$