# Finding Regression Slope

This question is based on How to derive a regression formula

Start with a regression equation: $s_{ij} = \alpha + \beta \bar{s_j} + \epsilon_{ij},$

The goal is to get to this. *Update. I figured this part out. ***The remaining question is listed at the very bottom.

$\hat{\beta} = \frac{\sum_j \sum_i s_{ij} (\bar{s_j} - \bar{s})}{\sum_j n_j (\bar{s_j} - \bar{s})^2} = \frac{\sum_j (\bar{s_j} - \bar{s})(n_j \bar{s_j})}{\sum_j n_j( \bar{s_j} - \bar{s})^2} = 1$

First, get $\hat{\alpha}$:

$$argmin_{\hat{\alpha}}~~ \hat{\epsilon_{ij}^2} = argmin_{\hat{\alpha}}~ \sum_j \sum_i (s_{ij} - \hat{\alpha} - \hat{\beta} \bar{s_j})^2$$

$$\rightarrow \sum_j \sum_i (s_{ij} - \hat{\alpha} - \hat{\beta} \bar{s_j}) = 0$$

$$\rightarrow \sum_j \sum_i \hat{\alpha} = \sum_j \sum_i (s_{ij} - \bar{s_j} \hat{\beta})$$

$$\rightarrow \sum_j n_j \hat{\alpha} = \sum_j n_j \bar{s_j} - \hat{\beta} \sum_j n_j \bar{s_j}$$

$$\rightarrow \hat{\alpha} = (1 - \hat{\beta}) \frac{\sum_j n_j \bar{s_j} }{\sum_j n_j} = (1 - \hat{\beta}) \bar{s}$$

Next, get $\hat{\beta}$.

$$argmin_{\hat{\beta}}~~ \hat{\epsilon_{ij}^2} = argmin_{\hat{\beta}}~ \sum_j \sum_i (s_{ij} - \hat{\alpha} - \hat{\beta} \bar{s_j})^2$$

$$= argmin_{\hat{\beta}}~ \sum_j \sum_i (s_{ij} - (1 - \hat{\beta}) \bar{s} - \hat{\beta} \bar{s_j})^2$$

$$= argmin_{\hat{\beta}}~ \sum_j \sum_i ((s_{ij} - \bar{s}) - \hat{\beta}( \bar{s_j} - \bar{s}))^2$$

$$\rightarrow \sum_j \sum_i ((s_{ij} - \bar{s}) - \hat{\beta}( \bar{s_j} - \bar{s}))( \bar{s_j} - \bar{s})= 0$$

$$\rightarrow \sum_j \sum_i (s_{ij} - \bar{s})( \bar{s_j} - \bar{s}) = \sum_j \sum_i \hat{\beta}( \bar{s_j} - \bar{s})( \bar{s_j} - \bar{s})$$

$$\rightarrow \hat{\beta} = \frac{\sum_j \sum_i (s_{ij} - \bar{s})( \bar{s_j} - \bar{s}) } {\sum_j \sum_i ( \bar{s_j} - \bar{s})( \bar{s_j} - \bar{s})}$$

$$\rightarrow \hat{\beta} = \frac{\sum_j \sum_i (s_{ij} - \bar{s})( \bar{s_j} - \bar{s}) } {\sum_j \sum_i ( \bar{s_j} - \bar{s})^2}$$

$$\rightarrow \hat{\beta} = \frac{\sum_j \sum_i (s_{ij} - \bar{s})( \bar{s_j} - \bar{s}) } {\sum_j n_j ( \bar{s_j} - \bar{s})^2}$$

$$\rightarrow \hat{\beta} = \frac{\sum_j \sum_i (s_{ij} - \bar{s})( \bar{s_j} - \bar{s}) } {\sum_j n_j ( \bar{s_j} - \bar{s})^2}$$

$$\rightarrow \hat{\beta} = \frac{\sum_j \sum_i s_{ij}(\bar{s_j} - \bar{s}) - \sum_j \sum_i \bar{s}(\bar{s_j} - \bar{s}) } {\sum_j n_j ( \bar{s_j} - \bar{s})^2}$$

$$\rightarrow \hat{\beta} = \frac{\sum_j \sum_i s_{ij}(\bar{s_j} - \bar{s}) - \sum_j \sum_i \bar{s}(\bar{s_j} - \bar{s}) } {\sum_j n_j ( \bar{s_j} - \bar{s})^2}$$

$$\rightarrow \hat{\beta} = \frac{\sum_j \sum_i s_{ij}(\bar{s_j} - \bar{s}) - \sum_j \sum_i \bar{s}\bar{s_j} - \bar{s}^2 } {\sum_j n_j ( \bar{s_j} - \bar{s})^2}$$

$$\rightarrow \hat{\beta} = \frac{\sum_j \sum_i s_{ij}(\bar{s_j} - \bar{s}) - \bar{s}\sum_j n_j(\bar{s_j} - \bar{s}) } {\sum_j n_j ( \bar{s_j} - \bar{s})^2}$$

$$\rightarrow \hat{\beta} = \frac{\sum_j \sum_i s_{ij}(\bar{s_j} - \bar{s}) } {\sum_j n_j ( \bar{s_j} - \bar{s})^2}$$

because $\sum_j n_j(\bar{s_j} - \bar{s}) = 0$

$$\rightarrow \hat{\beta} = \frac{\sum_j (\bar{s_j} - \bar{s})(n_j \bar{s_j})}{\sum_j n_j( \bar{s_j} - \bar{s})^2}$$

Why does the last equality produce 1 in:

$$\hat{\beta} = \frac{\sum_j (\bar{s_j} - \bar{s})(n_j \bar{s_j})}{\sum_j n_j( \bar{s_j} - \bar{s})^2} = 1$$

Here are my steps (started from Line 8 of your steps finding $\hat{\beta}$). Hope there is no mistake. $$\hat{\beta} = \frac{\sum_j\sum_i (s_{ij}-\bar{s})(\bar{s}_j - \bar{s})}{\sum_j n_j (\bar{s}_j - \bar{s})^2} \\ \implies \hat{\beta} = \frac{\sum_j \left[(\bar{s}_j - \bar{s})\sum_i (s_{ij}-\bar{s})\right]}{\sum_j n_j (\bar{s}_j - \bar{s})^2}$$
$$\because \sum_i (s_{ij} - \bar{s}) = \sum_i s_{ij} - n_j \bar{s} = n_j\bar{s}_j - n_j\bar{s} = n_j (\bar{s}_j - \bar{s})$$
$$\therefore \hat{\beta} = \frac{\sum_j \left[(\bar{s}_j - \bar{s})\sum_i (s_{ij}-\bar{s})\right]}{\sum_j n_j (\bar{s}_j - \bar{s})^2} = \frac{\sum_j \left[(\bar{s}_j - \bar{s})n_j (\bar{s}_j - \bar{s})\right]}{\sum_j n_j (\bar{s}_j - \bar{s})^2} =1$$
use $\implies$ (\implies in LaTeX) (which means 'implies' in mathematics) instead of $\to$