AFAIK,分发没有封闭的形式。使用 R,获得精确分布的天真实现对我来说最多可以达到至少 12 个组大小 - 在使用 Windows7 64 位和当前 R 的 Core i5 上花费不到 1 分钟。对于 R 自己在 C 中使用的更聪明的算法中pwilcox(),可以查看源文件 src/nmath/wilcox.c
n1 <- 12 # size group 1
n2 <- 12 # size group 2
N <- n1 + n2 # total number of subjects
现在为组 1 中的行列生成所有可能的情况。这些都是(Nn1)来自数字的不同样本1,…,N大小的n1. 然后计算每个案例的秩和(= 检验统计量)。将这些秩和制表得到相对频率的概率密度函数,这些相对频率的累积和就是累积分布函数。
rankMat <- combn(1:N, n1) # all possible ranks within group 1
LnPl <- colSums(rankMat) # all possible rank sums for group 1
dWRS <- table(LnPl) / choose(N, n1) # relative frequencies of rank sums: pdf
pWRS <- cumsum(dWRS) # cumulative sums: cdf
将精确分布与渐近正确的正态分布进行比较。
muLnPl <- (n1 * (N+1)) / 2 # expected value
varLnPl <- (n1*n2 * (N+1)) / 12 # variance
plot(names(pWRS), pWRS, main="Wilcoxon RS, N=(12, 12): exact vs. asymptotic",
type="n", xlab="ln+", ylab="P(Ln+ <= ln+)", cex.lab=1.4)
curve(pnorm(x, mean=muLnPl, sd=sqrt(varLnPl)), lwd=4, n=200, add=TRUE)
points(names(pWRS), pWRS, pch=16, col="red", cex=0.7)
abline(h=0.95, col="blue")
legend(x="bottomright", legend=c("exact", "asymptotic"),
pch=c(16, NA), col=c("red", "black"), lty=c(NA, 1), lwd=c(NA, 2))
