没有单个值的加权平均值(sd)

时间:2014-06-12 16:10:32

标签: r standard-deviation weighted-average

我有两个样本,我有手段(sd)和尺寸。

i.e. 
6.27 +/- 5.9 (size 34)
5.91 +/- 4.9 (size 6)

如何连接两个样本并具有均值和SD?

TY提前。

1 个答案:

答案 0 :(得分:1)

以这种方式:

mean_1 <- 6.27
sd_1 <- 5.9

mean_2 <- 5.91
sd_2 <- 4.9

n_1 <- 34
n_2 <- 6

# the combined mean
mean_combined <- weighted.mean(c(mean_1, mean_2), c(n_1, n_2))
# [1] 6.216

# the combined standard deviation (if the samples are not correlated)
sd_combined <- sqrt(sd_1^2 + sd_2^2)
# [1] 7.66942

# the pooled standard deviation 
# (under the assumption that both samples are from the same population)
sd_pooled <- sqrt((n_1 * sd_1^2 + n_2 * sd_2^2 + 
                     n_1 * (mean_1 - mean_combined) + 
                     n_2 * (mean_2 - mean_combined)) / (n_1 + n_2))
# [1] 5.761076