Let $v_1$, $v_2$ be two vectors of lengths $m$, $n$ of real numbers.
Let $\sigma_1$, $\sigma_2$ be their standard deviations, and assume they are already calculated.
It is possible to assume we also know the means of the vectors.
Is there a $O(1)$ formula to calculate the standard deviation of the concatenation of those two vectors?
Thanks
Let $v_1=(x_1,x_2,..x_m)$ have mean $\mu_1$ and standard deviation $\sigma_1$, and $v_2=(y_1,y_2,..y_n)$ have mean $\mu_2$ and standard deviation $\sigma_2$. We can write $$\mu_1=\frac 1m \sum_{i=1}^m x_i\\\sigma_1^2=\frac 1m\sum_{i=1}^m(x_i-\mu_1)^2$$ We rewrite the second equation as $$m\sigma_1^2=\sum_{i=1}^m(x_i^2-2x_i\mu_1+\mu_1^2)=\sum_{i=1}^mx_i^2-m\mu_1^2$$ or $$\sum_{i=1}^mx_i^2=m\mu_1^2+m\sigma_1^2$$ Similarly $$\sum_{i=1}^ny_i^2=n\mu_2^2+n\sigma_2^2$$ We can now write $$\mu=\frac{\sum_{i=1}^mx_i+\sum_{i=1}^ny_i}{m+n}=\frac{m\mu_1+n\mu_2}{m+n}$$ and for the standard deviation: $$\sigma^2=\frac1{m+n}\left(\sum_{i=1}^m(x_i^2-\mu)^2+\sum_{i=1}^n(y_i^2-\mu)^2\right)$$ Expanding the squares we get $$\sigma^2=\frac{1}{m+n}\left(\sum_{i=1}^mx_i^2-2\mu\sum_{i=1}^mx_i+m\mu^2+\sum_{i=1}^n y_i^2-2\mu\sum_{i=1}^n y_i+n\mu^2\right)\\=\frac{1}{m+n}(m\mu_1^2+m\sigma_1^2-2\mu m\mu_1+m\mu^2+n\mu_2^2+n\sigma_2^2-2\mu n\mu_2+n\mu^2)$$