<p>Your goal is to find a line that has a best linear fit through set of observations <span class="math-container">$y,x$</span>. Every equation of a line in 2D space will have two parameters, slope <span class="math-container">$\beta$</span> and intercept <span class="math-container">$\alpha$</span>, so your problem boils down to choose <span class="math-container">$\alpha$</span> and <span class="math-container">$\beta$</span> that best fit the data.</p>
<p>It is reasonable to define the best fit as a fit that minimizes the sum of squared residuals. We want to minimizes the sum of residuals because we want errors to be as small as possible, and we square them to ensure that positive errors do not cancel with negative ones.</p>
<p>As a consequence we minimize the following objective function</p>
<p><span class="math-container">$$\min_{\alpha, \beta} \frac{1}{n} \sum \epsilon^2 =
\min_{\alpha, \beta} \frac{1}{n} \sum (y - \alpha - \beta x)^2$$</span></p>
<p>wrt <span class="math-container">$\alpha$</span> and <span class="math-container">$\beta$</span>. In order to find a minimum of a function you have to calculate first order conditions which are given at a points where first derivatives equal zero.</p>
<p><span class="math-container">$$ \frac{d\epsilon}{d\alpha}= 0 \implies -2\frac{1}{n} \sum(y - \alpha - \beta x) = 0$$</span></p>
<p><span class="math-container">$$\frac{d\epsilon}{d\beta} = 0 \implies -2\frac{1}{n} \sum (y- \alpha - \beta x) x = 0$$</span></p>
<p>where -2 and actually technically even <span class="math-container">$\frac{1}{n}$</span> can be dropped since you can just divide both sides by them and they disappear, but <span class="math-container">$\frac{1}{n}$</span> is usually left as then you can rewrite the optimum solution for <span class="math-container">$\beta$</span> in terms of variances and covariances as tdm does in his excellent answer.</p>

CC BY-SA 4.0
2021-06-19T09:25:20.877Z
2021-06-19T09:27:18.940Z
2021-06-19T09:27:18.940Z
1muflon1
<p>From <a href="https://economics.stackexchange.com/a/45496/33142">this discussion</a>, I asked @tdm about the condition of OLS but I still cannot get it, and it is not easy to answer the mathematic equation in comment part so I want to ask here.</p>
<p>One way to see this is to notice that OLS minimizes</p>
<p><span class="math-container">$$\frac{1}{n} \sum_i (y_i - \alpha - \beta x)^2$$</span></p>
<p>with respect to <span class="math-container">$\alpha$</span>  and <span class="math-container">$\beta$</span>
I do not understand clearly <strong>why it leads to the conditions</strong></p>
<p><span class="math-container">$$\frac{1}{n} \sum_i (y_i - \alpha - \beta x) = 0$$</span>
and</p>
<p><span class="math-container">$$\frac{1}{n} \sum_i (y_i - \alpha - \beta x) x = 0$$</span></p>

CC BY-SA 4.0
2021-06-19T00:08:12.033Z
This post has no question in it, please tell us what is your question
1muflon1
CC BY-SA 4.0
2021-06-19T00:12:45.700Z
Hi @1muflon1, sorry if my question is not clear to you, but the question is "why it leads to the conditions" as above. Thank you so much.
Phil Nguyen
CC BY-SA 4.0
2021-06-19T00:14:53.600Z
Ah, I will change the title to let it be as same as a question, thank you for your suggestion
Phil Nguyen
CC BY-SA 4.0
2021-06-19T06:51:57.537Z
@BeautifulMindset Do you know what an optimization problem is, and are you familiar with derivatives?
Giskard
CC BY-SA 4.0
2021-06-19T07:45:49.690Z
@Giskard I am not familiar with optimization problem, but I am familiar with derivatives
Phil Nguyen
<mathematical-economics>
How to get the condition of OLS mathematically?
Phil Nguyen
# How to get the condition of OLS mathematically?

(Asked by: username_0 on 2021-06-18)

From [this discussion](https://economics.stackexchange.com/a/45496/33142), I asked @tdm about the condition of OLS but I still cannot get it, and it is not easy to answer the mathematic equation in comment part so I want to ask here.

One way to see this is to notice that OLS minimizes

$$\frac{1}{n} \sum\_i (y\_i - \alpha - \beta x)^2$$

with respect to $\alpha$ and $\beta$
I do not understand clearly **why it leads to the conditions**

$$\frac{1}{n} \sum\_i (y\_i - \alpha - \beta x) = 0$$
and

$$\frac{1}{n} \sum\_i (y\_i - \alpha - \beta x) x = 0$$

**Tags:** mathematical-economics
> **Comments:**
> **username_1**: This post has no question in it, please tell us what is your question  
> **username_0**: Hi @1muflon1, sorry if my question is not clear to you, but the question is "why it leads to the conditions" as above. Thank you so much.  
> **username_0**: Ah, I will change the title to let it be as same as a question, thank you for your suggestion  
> **username_2**: @BeautifulMindset Do you know what an optimization problem is, and are you familiar with derivatives?  
> **username_0**: @Giskard I am not familiar with optimization problem, but I am familiar with derivatives  

---

## 1 answers

### Answer by username_1 on 2021-06-19. Score: 2 | Accepted answer

Your goal is to find a line that has a best linear fit through set of observations $y,x$. Every equation of a line in 2D space will have two parameters, slope $\beta$ and intercept $\alpha$, so your problem boils down to choose $\alpha$ and $\beta$ that best fit the data.

It is reasonable to define the best fit as a fit that minimizes the sum of squared residuals. We want to minimizes the sum of residuals because we want errors to be as small as possible, and we square them to ensure that positive errors do not cancel with negative ones.

As a consequence we minimize the following objective function

$$\min\_{\alpha, \beta} \frac{1}{n} \sum \epsilon^2 =
\min\_{\alpha, \beta} \frac{1}{n} \sum (y - \alpha - \beta x)^2$$

wrt $\alpha$ and $\beta$. In order to find a minimum of a function you have to calculate first order conditions which are given at a points where first derivatives equal zero.

$$ \frac{d\epsilon}{d\alpha}= 0 \implies -2\frac{1}{n} \sum(y - \alpha - \beta x) = 0$$

$$\frac{d\epsilon}{d\beta} = 0 \implies -2\frac{1}{n} \sum (y- \alpha - \beta x) x = 0$$

where -2 and actually technically even $\frac{1}{n}$ can be dropped since you can just divide both sides by them and they disappear, but $\frac{1}{n}$ is usually left as then you can rewrite the optimum solution for $\beta$ in terms of variances and covariances as tdm does in his excellent answer.


---

