为了估计置信区间,当我们将一半的平均值放在一端,另一半放在另一端时,我们可以使用平均值的最大差异分布的模拟。
例如,它看起来像这样。

然后根据一些观察到的范围,您可以计算与该范围相关的边界,并确定您的置信区间。
在示例图像中,演示了观察到的学生化范围为 4 的情况,绿线对应于 95% 置信区间的估计值。这条线在红线之间,给出了样本的上限和下限 2.5%。
还需要做一些事情:
- 当所有组都在最远的边缘时,我们仅使用范围并计算范围分布的最坏情况。这不会使用所有信息。当只有两个均值非常远而其余均在中间时,这与许多均值位于边缘时的情况不同。
- 我们使用了模拟,但如果使用一些表达式会很好。这并不容易。所有均值均等情况的情况是学生化范围分布。这已经很难计算,现在您需要对其进行概括。
图像的计算机代码
### nu = number in sample
### nl = number of samples in each left side
### d = distance between means
### nr = number of samples in right side
### m = number of samples in the middle
### d2 = position of the middle samples
simdif = function(nu, nl, d, nr = nl, m = 0, d2 = d/2) {
### means of the different groups
mean = c(rep(0,nl),rep(d2,m),rep(d,nr))
### compute samples
x = matrix(rnorm(nu*(nl+m+nr),mean = mean), nu, byrow = 1)
### compute sample means
mu = colMeans(x)
### compute pooled sample variance
RSS = sum((x - rep(1,nu) %*% t(as.matrix(mu)))^2)
sig = sqrt(RSS/(nu*(nl+m+nr)-nu))
### studentized range
range = (max(mu)-min(mu))/sig
return(range)
}
### compute for different distances
dv = seq(0,5,0.1)
### smp contains the simulation
smp = c()
### pct975 stores the upper 97.5-th quantile
### pct025 stores the lower 2.5-th quantile
pct975 = c()
pct025 = c()
### do the sampling
nrep = 10^3
set.seed(1)
for (di in dv) {
sample = replicate(nrep, simdif(5,4,di))
perc = quantile(sample, probs = c(0.025,0.975))
smp = cbind(smp,sample)
pct975 = c(pct975,perc[2])
pct025 = c(pct025,perc[1])
}
dcor = rep(1,nrep) %*% t(as.matrix(dv))
### plot experimental distribution with confidence boundaries
plot(dcor, smp, pch = 21, col = rgb(0,0,0,0.05), bg = rgb(0,0,0,0.05), cex = 0.7,
main = "simulation for 8 groups of size 5",
ylab = "observed studentized range",
xlab = "true difference in sigma")
lines(dv,pct975, col = 2)
lines(dv,pct025, col = 2)
### example confidence interval
c1 = which.min(abs(pct975-4))
c2 = which.min(abs(pct025-4))
lines(dv[c(c1,c2)], c(4,4), col = 3, lwd = 4, lty = 2)
编辑:
我注意到我的方法有问题。我查看了 8 组在两端分成 2 次 4 组的情况。这提供了比其他配置更大的范围。但这仅适用于计算上限,并且适用于单边置信区间。对于下边界,我们不应该看最坏的情况,而至少应该看最坏的情况。也就是说,8 组中只有 2 组在远端,其余的正好在中间。
上面的代码已经预料到了计算最坏情况的可能性。使用上面的代码,我们将使用simdif(5,1,di,1,6)(将 1 组均值放在下端,1 组均值放在上端,另外 6 组放在中间)而不是simdif(5,4,di,4,0). 然后我们将看到范围的较低值和置信区间边界向右移动(较高值)。
因此,使用这种方法,我们需要组合这些间隔。这有点像复合零假设的诅咒。我们需要涵盖与原假设相对应的多种情况。

当我们比较更多组均值时,不同配置的效果会变得更加极端。在下图中,我们查看了 100 个组均值范围的分布。在左图中,计算了两次 50 组的分布,两端均值。在右图中,一组只有两次均值在末尾,其余在中间。在左图中,范围要大得多。置信区间的界限彼此相距甚远。这意味着合并更多数据而不仅仅是范围是有用的,我不应该忽略其他 98 个组的分布。
