假设有元素分为两组(和)。第一组的方差为,第二组的方差为。元素本身被假定为未知,但我知道均值和。
有一种方法来计算组合的方差?
方差不必是无偏的,因此分母是而不是。
假设有元素分为两组(和)。第一组的方差为,第二组的方差为。元素本身被假定为未知,但我知道均值和。
有一种方法来计算组合的方差?
方差不必是无偏的,因此分母是而不是。
Answers:
使用均值的定义
和样本方差
(括号中的最后一项是通常在统计软件中默认计算的无偏方差估计量),以查找所有数据的平方和。让我们对索引i进行排序,以便i = 1 ,… ,n表示第一组元素,而i = n + 1 ,… ,n + m表示第二组元素。按组打破该平方和,并根据数据子集的方差和均值重新表达这两部分:
代数求解此为在其他(已知)量的产率方面
Of course, using the same approach, can be expressed in terms of the group means, too.
An anonymous contributor points out that when the sample means are equal (so that ), the solution for is a weighted mean of the group sample variances.
sqrt(weighted.mean(u^2 + rho^2, n) - weighted.mean(u, n)^2)
where n
, u
and rho
are equal-length vectors. E.g. n=c(10, 14, 9)
for three samples.
I'm going to use standard notation for sample means and sample variances in this answer, rather than the notation used in the question. Using standard notation, another formula for the pooled sample variance of two groups can be found in O'Neill (2014) (Result 1):
This formula works directly with the underlying sample means and sample variances of the two subgroups, and does not require intermediate calculation of the pooled sample mean. (Proof of result in linked paper.)
Yes, given the mean, sample count, and variance or standard deviation of each of two or more groups of samples, you can exactly calculate the variance or standard deviation of the combined group.
This web page describes how to do it, and why it works; it also includes source code in Perl: http://www.burtonsys.com/climate/composite_standard_deviations.html
BTW, contrary to the answer given above,
See for yourself, e.g., in R:
> x = rnorm(10,5,2) > x [1] 6.515139 8.273285 2.879483 3.624233 6.199610 3.683164 4.921028 8.084591 [9] 2.974520 6.049962 > mean(x) [1] 5.320502 > sd(x) [1] 2.007519 > sum(x**2) [1] 319.3486 > 10 * (mean(x)**2 + sd(x)**2) [1] 323.3787
R
computes the unbiased estimate of the standard deviation rather than the standard deviation of the set of numbers. For instance, sd(c(-1,1))
returns 1.414214
rather than 1
. Your example needs to use sqrt(9/10)*sd(x)
in place of sd(x)
. Interpreting "" as the SD of the data and "" as the mean of the data, your BTW remark is wrong. A program demonstrating this is n <- 10; x <- rnorm(n,5,2); m <- mean(x); s <- sd(x) * sqrt((n-1)/n); m2 <- sum(x^2); c(lhs=n * (m^2 + s^2), rhs=m2)