给定已知的组方差,均值和样本量,如何计算两个或多个组的合并方差?


32

假设有元素分为两组(和)。第一组的方差为,第二组的方差为。元素本身被假定为未知,但我知道均值和。+ññσ2σñ2μμñ

有一种方法来计算组合的方差σ+ñ2

方差不必是无偏的,因此分母是+ñ而不是+ñ-1个


当您说出这些组的均值和方差时,它们是参数还是样本值?如果它们是样本均值/方差,则不应使用μσ ...
Jonathan Christensen 2012年

我只是用符号来表示。否则,将很难解释我的问题。
user1809989

1
对于样本值,我们通常使用拉丁字母(例如s)。希腊字母通常保留给参数。使用“正确的”(预期)符号将帮助您更清晰地交流。ms
乔纳森·克里斯坦森

不用担心,从现在开始,我将继续关注!欢呼声
user1809989

1
@Jonathan因为这不是一个关于样品或估计问题,可以采取合法认为σ 2真正均值和一批数据的经验分布的方差,由此证明常规使用的希腊字母,而不是拉丁字母来引用它们。μσ2
ub

Answers:


36

使用均值的定义

μ1:n=1ni=1nxi

和样本方差

σ1个ñ2=1个ñ一世=1个ñX一世-μ1个ñ2=ñ-1个ñ1个ñ-1个一世=1个ñX一世-μ1个ñ2

(括号中的最后一项是通常在统计软件中默认计算的无偏方差估计量),以查找所有数据的平方和。让我们对索引i进行排序,以便i = 1 n表示第一组元素,而i = n + 1 n + m表示第二组元素。按组打破该平方和,并根据数据子集的方差和均值重新表达这两部分:xiii=1,,ni=n+1,,n+m

(m+n)(σ1:m+n2+μ1:m+n2)=i=11:n+mxi2=i=1nxi2+i=n+1n+mxi2=n(σ1:n2+μ1:n2)+m(σ1+n:m+n2+μ1+n:m+n2).

代数求解此为在其他(已知)量的产率方面σm+n2

σ1:m+n2=n(σ1:n2+μ1:n2)+m(σ1+n:m+n2+μ1+n:m+n2)m+nμ1:m+n2.

Of course, using the same approach, μ1:m+n=(nμ1:n+mμ1+n:m+n)/(m+n) can be expressed in terms of the group means, too.


An anonymous contributor points out that when the sample means are equal (so that μ1:n=μ1+n:m+n=μ1:m+n), the solution for σm+n2 is a weighted mean of the group sample variances.


4
The "homework" tag doesn't mean the question is elementary or stupid: it's used for self-study questions that can even include research-level queries. It distinguishes routine, more or less context-free questions (of the sort that might ordinarily grace the math forum) from specific applied questions.
whuber

I cannot understand your first passage: n(σ2+μ2)=(xμ)2+nμ2=?x2 In particular I get [(xμ)2+μ2]=[x22xμ] which requires μ=0 Am I missing something? Could you please explain this?
DarioP

2
@Dario
(xμ)2+nμ2=(x22μx+nμ2)+nμ2=x22nμ2+2nμ2=x2.
whuber

Oh yes, I did a stupid sign mistake in my derivation, now is clear, thanks!!
DarioP

4
I guess this can be extended to an arbitrary number of samples as long as you have the mean and variance for each. Calculating pooled (biased) standard deviation in R is simply 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.
Jonas Lindeløv

3

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):

spooled2=1n1+n21[(n11)s12+(n21)s22+n1n2n1+n2(x¯1x¯2)2].

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.)


-3

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,

n(σ2+μ2)    i=1nxi2

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

it's because you forgot the n-1 factor, e.g. try with n*(mean(x)**2+sd(x)**2/(n)*(n-1))
user603

user603, what on earth are you talking about?
Dave Burton

3
Dave, mathematics is a more reliable teacher than software. In this case 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)
whuber
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.