0
$\begingroup$

I have some distribution from which I sample two datasets x1 and x2. I wanted to calculate their combined mean and variance by using these two formulas:

$$\bar X_c = \frac{n_1 \overline{X_1} + n_1 \overline{X_1}}{n_1 + n_2}$$

$${S_c}^2 = \frac{{{n_1}{S_1}^2 + {n_2}{S_2}^2 + {n_1}{{\left( {{{\overline X }_1} - {{\overline X }_c}} \right)}^2} + {n_2}{{\left( {{{\overline X }_2} - {{\overline X }_c}} \right)}^2}}}{{{n_1} + {n_2}}}$$

where $n$ is the number of samples of the dataset. The subscript $c$ indicates the combined values.

For testing purposes, I wanted to check if the formulas yield the same result as when stacking the two datasets to create $x3 = x1+x2$ and calculating the mean and variance of it. So I created a dummy dataset like this:

x1    x2

98    69
49    54
33    38
73     9
51

I calculated the means and variances just for $x1$ and $x2$, and then for the 2 combination methods. It yielded:

        x1      x2      x3      xC

mean    60.80   42.50   52.66   52.66

var     635.2   659.0   657.75  728.47

As you can see, the formula worked for the means, but fails to reproduce the correct variance (x3).

Can somebody tell me what I am doing wrong? Simple answers would be nice, as I am not a great mathematician.

Thank you!

$\endgroup$
5
  • $\begingroup$ You can get displayed equations by enclosing them in double instead of single dollar signs. Especially when you mix fractions, subscripts and superscripts, that makes them a lot easier to read. $\endgroup$
    – joriki
    Jul 31, 2018 at 11:30
  • $\begingroup$ What definition are you using for sample variance? $\frac1{n}\sum\dots$ or $\frac1{n-1}\sum\cdots$? $\endgroup$
    – drhab
    Jul 31, 2018 at 11:38
  • $\begingroup$ @drhab: I normalized with $n-1$. I also edited the question to make it more readable. $\endgroup$
    – DocDriven
    Jul 31, 2018 at 11:55
  • $\begingroup$ From where did you get the formula of $S_c^2$? It does not look okay to me. $\endgroup$
    – drhab
    Jul 31, 2018 at 12:10
  • $\begingroup$ @drhab: I got it from here: LINK. When using it with the biased variance, it produces the correct result though. $\endgroup$
    – DocDriven
    Jul 31, 2018 at 12:17

1 Answer 1

2
$\begingroup$

This formula is for the sample variances. What you wrote in the row labeled var in the table is the estimate for the population variance based on the sample variance, which differs from the sample variance due to Bessel's correction.

$\endgroup$
3
  • $\begingroup$ P.S.: The teminology section of that article says that the corrected estimate for the population variance is also sometimes called the "sample variance". I wasn't aware of that (and it seems like an extremely bad choice of terminology to me). So with that in mind, perhaps replace "sample variance" and "estimate for the population variance" by "uncorrected estimate for the population variance" and "corrected estimate for the population variance", respectively, in the above answer, to avoid ambiguity. $\endgroup$
    – joriki
    Jul 31, 2018 at 11:43
  • $\begingroup$ Thank you for the clarification. Turned out it was due to me using the unbiased variance in my calculations. Shame on me for not checking what Excel uses! $\endgroup$
    – DocDriven
    Jul 31, 2018 at 12:15
  • $\begingroup$ @DocDriven: Yes, you could also put "biased" and "unbiased" above for "uncorrected" and "corrected", respectively. $\endgroup$
    – joriki
    Jul 31, 2018 at 12:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .