I have been working through Multivariable Calculus 4th Edition by James Stewart (©1999) and am currently stuck on what seems to be a stats problem on problem 51 of Chapter 15.7:
- Suppose that a scientist has reason to believe that two quantities $x$ and $y$ are related linearly, that is, $y=mx+b$, at least approximately, for some values of $m$ and $b$. The scientist performs an experiment and collects data in the form of point $(x_1,y_1),(x_2,y_2),...,(x_n,y_n)$, and then plots these points. The points don't exactly lie on a straight line, so the scientist wants to find constants $m$ and $b$ so that the line $y=mx+b$ "fits" the points as well as possible. Let $d_i=y_i-(mx_i+b)$ be the vertical derivation from the line [$mx+b]$. The method of least squares determines $m$ and $b$ so as to minimize $\sum_{i=1}^{n}d_i^2$, the sum of the squares of these derivations. Show that, according to this method, the line of best fit is obtained when$$m\sum_{i=1}^nx_i+bn=\sum_{i=1}^ny_i\\m\sum_{i=1}^nx_i^2+b\sum_{i=1}^nx_i=\sum_{i=1}^nx_iy_i$$Thus, the line is found by solving these two equations in the two unknowns $m$ and $b$.
My thinking:
Mainly going off of how this chapter has been focusing on partial derivatives, what I could do is start by setting the gradient to 0 (defining our equation for line of best fit to be $\beta_1+\beta_2x$):$$\dfrac{\partial S}{\partial\beta_j}=2\sum_id_i\dfrac{\partial d_i}{\partial\beta_j}=0,j=1,2$$but now since $d_i=y_i-(\beta_1+\beta_2x)=y_i-f(x_i,\beta)$, we have that$$-2\sum_id_i\dfrac{\partial f(x_i,\beta)}{\partial b_j}=0,j=1,2$$Now, I believe that I am likely in a position where if I could arrange our two conditions into something similar to the equation that I have gotten from setting the gradient to 0, then I can solve this.
However, it seems that no matter what I try from here, I end up writing myself into a dead end, so my question is
How do I go about showing that the line of best fit using the method of least squares is obtained when$$m\sum_{i=1}^nx_n+bn=\sum_{i=1}^ny_i\\m\sum_{i=1}^nx_i^2+b\sum_{i=1}^nx_i=\sum_{i=1}^nx_iy_i$$