3
$\begingroup$

Suppose two data arrays of length $n$ with variance $\sigma^2$ and mean $\mu$.

Is the pooled variance $\sigma_P^2 = \frac{(n_1-1)\sigma_1^2 + (n_2-1)\sigma_2^2}{(n_1-1) + (n_2-1)}$ equal to the variance of the centered concatenated data $ \textrm{Var}(x_{1,1}-\mu_1, ..., x_{1,n_1}-\mu_1,\,x_{2,1}-\mu_2, ..., x_{2,n_2}-\mu_2)$?

I've tested this in python as follows:

import math
from random import gauss
import numpy as np

var1 = 3
var2 = 10

mean1 = 3
mean2 = 50

n1 = 500
n2 = 1000

x1 = [gauss(mean1, math.sqrt(var1)) for i in range(n1)]
x2 = [gauss(mean2, math.sqrt(var2)) for i in range(n2)]

pooled = ((len(x1)-1)*np.var(x1, ddof=1) + (len(x2)-1)*np.var(x2, ddof=1)) / ((len(x1)-1) + (len(x2)-1)) # 7.007545276099887 

concd = np.var(np.concatenate((x1-np.mean(x1), x2-np.mean(x2)))) # 6.998201882398422

For both approaches the variance is approximately 7.

$\endgroup$

1 Answer 1

2
$\begingroup$

Only if you estimate the concatenated variance with degrees of freedom equals to $2$:

np.var(np.concatenate((x1-np.mean(x1), x2-np.mean(x2))), ddof=2)

Because, $(n_i-1)S_i^2=\sum_{n=1}^{n_i} (x_{i,n}-\hat\mu_i)^2$ and when summed over $i$, this is going to be equal to the unnormalized variance of the concatenated array. And you need to normalize it with $n_1+n_2-2$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.