vdw.test <- function(x, y)
{
n <- (n1 <- length(x))+(n2 <- length(y))
z <- qnorm(rank(z <- c(x, y))/(n+1))
S <- abs(sum(z[1:n1]))
V <- n1*n2/(n^2-n)*sum(z^2)
Z = S/sqrt(V)
result <- c(S, V, Z, pnorm(Z, lower=F)*2)
names(result) <- c("Statistics", "Variance", "Z value", "P value")
result
}
# 例
vdw.test(c(1.2, 1.9, 2.5, 6.7), c(1.5, 3.1, 10.5))
# 結果
# Statistics Variance Z value P value
# 0.7944990 1.0741550 0.7665842 0.4433288
# インターフェースのヴァリエーション
# data データ行列
# d 測定値のある列番号
# f 群識別値のある列番号
# g1 第一群を表す値
# g2 第二群を表す値
vdw.test2 <- function(data, d, f, g1, g2)
{
x <- data[,d][data[,f] == g1]
y <- data[,d][data[,f] == g2]
vdw.test(x,y)
}
# 使用例(1列目:測定値,2列目:群番号)
# ファイルから読んでも良い
data <- matrix(c(
1.2, 1,
1.9, 1,
2.5, 1,
6.7, 1,
1.5, 2,
3.1, 2,
10.5, 2
), ncol=2, byrow=TRUE)
vdw.test2(data, 1, 2, 1, 2)