# Standard deviation of the population

I have some trouble getting the standard deviation of a stratified sample.

I have a sample of 1600 individuals that are divided into three groups (strata), with their sample mean $y$, which is the groups average income, $s_k$ is the standard deviation, and $n_k$ is the number of indivdiuals in the strata/group.

What is the standard deviation of the population?

Answer is given here. Compute population mean ($\bar y$). Then
Population sample deviation = $\sqrt(\sum_k n_k s_k^2 + \sum_k n_k(\bar y_k-\bar y)^2)$.

You have 3 stratas with sizes $n_1$, $n_2$, $n_3$. Suppose, observations $y_1, \dots, y_{n_1}$ belong to the first strata, observations $y_{n_1 + 1}, \dots, y_{n_2}$ belong to the second strata, observations $y_{n_2 + 1}, \dots, y_{n_3}$ belong to the third strata. Mean values of stratas are $\overline{y}_1, \overline{y}_2, \overline{y}_3$ correspondingly, in the same way we define $n_1, n_2, n_3$ and $s_1, s_2, s_3$. Also, $n = n_1 + n_2 + n_3$

To get the standard deviation we need to evaluate $\frac{1}{n} \sum_{i = 1}^{n} (y_i - \overline{y})^2$.

Given $n_i$, $\overline{y}_i$ it is easy to calculate $\overline{y} = \frac{1}{n} \sum_{i = 1}^n y_i = \frac{1}{n} \sum_{i = 1}^3 n_i \overline{y}_i$. Now let us calculate a part of the sum up to the $n_1$-th term $\sum_{i = 1}^{n_1} (y_i - \overline{y})^2$: $$\sum_{i = 1}^{n_1} (y_i - \overline{y})^2 = \sum_{i = 1}^{n_1} (y_i - \overline{y}_1 + \overline{y}_1 - \overline{y})^2 = \\ \sum_{i = 1}^{n_1} (y_i - \overline{y}_1)^2 + n_1 (\overline{y}_1 - \overline{y})^2 + 2 \sum_{i = 1}^{n_1} (y_i - \overline{y}_1) (\overline{y}_1 - \overline{y}) = \\ \sum_{i = 1}^{n_1} (y_i - \overline{y}_1)^2 + n_1 (\overline{y}_1 - \overline{y})^2 = n_1 s_1^2 + n_1 (\overline{y}_1 - \overline{y})^2.$$

For other terms in the sum we do the same thing and get the final answer.

The key idea here is to add a term $0 = (\overline{y}_1 - \overline{y}_1)$ and then open the parenthesis.