# Adding two (or more) means and calculating the new standard deviation

There are a load of discussions online about adding means and recalculating the standard deviation, but on none have I found answer to this question.

I have two sub groups with mean $x_1$ and $x_2$, and $s_1$ and $s_2$. I want to add the two means to create $x_1 + x_2 = x_3$. How do I calculate $s_3$. The two sub groups are additive.

The exact data I have is on herbicide and fungicide use on crops on four different farms, where herbicide + fungicide = pesticide.

Herbicide (kg): $2, 3, 1, 2$ Fungicide (kg): $4, 7, 3, 1$ Pesticide (kg): $6, 10, 4, 3$

Herbicide $x_1 = 2.0$; $s_1 = 0.8$ Fungicide $x_2 = 3.8$; $s_2 = 2.5$ Pesticide $x_3 = 5.8$; $s_3 = 3.1$

Unfortunately I don't have any of the underlying data. I have only been provided with herbicide and fungicide means and standard deviations, $x_1$, $x_2$, $s_1$ and $s_2$. Is calculating this possible?

Thank you!

• It may be true in your case that pesticide = herbicide + fungicide, but that depends on physical additivity. That's not the same question as in statistical discussions on combining means or SDs of different samples. In general, if you have two samples both measuring the same thing, the combined mean will be somewhere between the two means, not their sum. So if combining heights of men and women, the mean height for (men and women) is certainly not the mean height of mean PLUS the mean height of women. Oct 3, 2014 at 12:50
• @NickCox In the case you mention, we're talking about subgroup means, not means of different variables. Oct 3, 2014 at 13:44
• @abaumann Agreed; that's what I said: "both measuring the same thing". Oct 3, 2014 at 14:02
• Are you conflating population notation with samples? The Greek letters are conventionally used with population quantities. Oct 3, 2014 at 16:31
• @NickCox - thank you for clarifying - yes - this adding two subgroup means. Oct 20, 2014 at 13:01

The mean $E(X+Y)$ is equal to the sum of the means $E(X)$ and $E(Y)$, i.e., in your case $2+3.8=5.8$.

The standard deviation is the square root of the variance $Var(X+Y) = Var(X)+Var(Y)+2Cov(X,Y)$.

If you assume that the use of herbicide and fungicide are independent - a bold assertion, although I don't know much about agriculture - then this simplifies to $Var(X+Y)=Var(X)+Var(Y)$ and allows you to calculate the standard deviation by observing that

$Var(X)=0.82^2=0.6724$

$Var(Y)=2.5^2=6.25$

Which leads us to find that $\sigma_3=\sqrt{0.6724+6.25} \approx 2.631$

The standard deviation is calculated differently if your sample correspond to the whole population or not.

In the first case (i.e. your study is conducted only on four farms), abaumann is right and the standard deviation of your pesticide sample $s_3$ is 2.68, calculated with the formula $$s = \sqrt{\frac{1}{n} \sum_{i=1}^n (x_i-\bar{x})^2}$$

If instead the four farms are a random sample of a wider population (i.e. you are trying to estimate the pesticide consumption in your country using only four farms) you have to use the corrected sample standard deviation: $$s_{corr} = \sqrt{\frac{1}{n-1} \sum_{i=1}^n (x_i-\bar{x})^2}$$ which gives $s_3=3.10$, as you mentioned in your question. The use of the term $n-1$ is called Bessel's correction.

To calculate $s_3$ you can either take $\sqrt{s_1^2+s_2^2}$, as correctly explained by abaumann, or use one of the two equation above (depends on your case) with the pesticide sample.

Let's recapitulate:

You have three sets of observation data: Herbicide, Fungicide and Pesticide, each with four elements. The P set is the result of the sum of H and F, so the three sets are not independent. Depending if they are the whole population or a sub-set of a bigger population, you will want to calculate the standard deviation of the sample $s$ or the corrected sample standard deviation $\sigma$ (please note these symbols are just to make things easier to follow and they are not a standard convention). Let's consider now only the first two sets, H and F. Their means and standard deviations are $$x_1 = 2.00 \quad s_1=0.71 \quad \sigma_1=0.82 \\ x_2 = 3.75 \quad s_2=2.17 \quad \sigma_2=2.50$$ The sum of the means $x_3$ have standard deviations $s_3$ and $\sigma_3$ as follows: $$x_3 = x_1 + x_2 = 2.00 + 3.75 = 5.75\\ s_3 = \sqrt {s_1^2 + s_2^2} = \sqrt {0.71^2 + 2.17^2} = 2.28\\ \sigma_3 = \sqrt {\sigma_1^2 + \sigma_2^2} = \sqrt {0.82^2 + 2.50^2} = 2.63$$ and that's the correct answer.

What you are doing is calculating the mean and standard deviations of a set (the P set resulting from the sum element by element of H and F) treating it as a third, independent set. If you were given the P set without explanation, that would be the best you could do and you would get $$x_3 = 5.75\\ s_3 = 2.68\\ \sigma_3 = 3.10.$$ But in fact you know that P is the result of eight observation and not only four, so you can leverage this and get a lower standard deviation. The mean is independent of the number of observations hence it stays the same. In short, the two methods are not giving the same results because they are indeed calculated on different sets.

• @joseph-darimathea Thank you for contributing on this. abaumanns answer is 2.63 not 2.68, and I think its just coincidence that these numbers are close. Can you calculate the correct $s_3$ of 3.10 without the underlying data by your approach (i.e. just using $x_1$, $x_2$, $s_1$ and $s_2$)? It is definitely not $\sqrt{0.8^2+2.5^2}$. Oct 20, 2014 at 22:59
• @GlobalSprawl I expanded the answer. In short, you can't get 3.10 from only $x_{1,2}$ and $s_{1,2}$. Oct 21, 2014 at 10:48
• @NickCox Indeed I haven't been clear, thanks for the correction. Oct 21, 2014 at 13:05

For combining groups, the following picture is for your reference.

• This is a more correct general answer for anyone wanting it. The other two answers assume that the groups are the same size which may not be the case in general. Sep 8, 2022 at 21:18

For a generalised approach with any number of groups and group sizes you can use the following, adapted from code at https://www.statstodo.com/CombineMeansSDs.php.

suppressMessages(library(dplyr))

## Create raw dataframe with unequal group sizes
set.seed(644)
dat_raw <- tibble(
group = c(rep("A", 10), rep("B",20), rep("C",30)),
x     = rnorm(60)
)

## Overall summary
dat_total <- dat_raw %>%
summarise(
n    = n(),
mean = mean(x),
sd   = sd(x)
)

dat_total
#> # A tibble: 1 × 3
#>       n   mean    sd
#>   <int>  <dbl> <dbl>
#> 1    60 0.0542 0.873

## Summary by group
dat_grouped <- dat_raw %>%
group_by(group) %>%
summarise(
n    = n(),
mean = mean(x),
sd   = sd(x)
)

dat_grouped
#> # A tibble: 3 × 4
#>   group     n    mean    sd
#>   <chr> <int>   <dbl> <dbl>
#> 1 A        10  0.203  0.923
#> 2 B        20  0.0917 0.997
#> 3 C        30 -0.0204 0.788

## Calculating overall summary from grouped data
dat_total_grouped <- dat_grouped %>%
mutate(
ex  = n * mean,
exx = sd^2 * (n-1) + ex^2 / n
) %>%
summarise(across(c(n, ex, exx), sum)) %>%
mutate(
mean = ex/n,
sd   = sqrt((exx - ex^2/n)/(n-1))
) %>%
select(n, mean, sd)

dat_total_grouped
#> # A tibble: 1 × 3
#>       n   mean    sd
#>   <int>  <dbl> <dbl>
#> 1    60 0.0542 0.873

## Overall summary from ungroued and grouped data are equal
all.equal(dat_total, dat_total_grouped)
#> [1] TRUE


Created on 2023-09-06 with reprex v2.0.2

• This would be a better answer if you explained a bit more what you're doing in this code. I realize you have some comments, but you should also explain in English what's going on. Sep 6, 2023 at 0:05