Sunday, October 28, 2007

Wilcoxon's signed rank test - paired

math <- c(22,37,36,38,42,58,58,60,62,65,66,56,66,67,62)
art <- c(53,68,42,49,51,65,51,71,55,74,68,64,67,72,65)

# Rank of abolute difference
R <- rank(abs(math-art))

# sample size
n <- length(R)

# R+
Rp <- sum(R[math>art])

# Expected value and variance under H0
E0 <- n*(n+1)/4
V0 <- n*(n+1)*(2*n+1)/24

# Normal approximation (large sample only)
Z <- (Rp-E0)/sqrt(V0)

# p-value for 2-sided test
pvalue <- 2*(1-pnorm(abs(Z)))

No comments: