Skip to content
Prev 274495 / 398506 Next

non-parametric permutation and signed paired-difference distributions

On 10/14/2011 4:10 PM, Bert Gunter wrote:
That's beautiful, Bert.  Thanks!  Here is my fleshed-out example

mean(ZeaMays$diff)
# complete permutation distribution of diff, for all 2^15 ways of assigning
# one value to cross and the other to self
allmeans <- as.matrix(expand.grid(as.data.frame(matrix(rep(c(-1,1),15), 
nr =2)))) %*% abs(ZeaMays$diff) / 15

# upper-tail p-value
sum(allmeans > mean(ZeaMays$diff)) / 2^15
# two-tailed p-value
sum(abs(allmeans) > mean(ZeaMays$diff)) / 2^15

hist(allmeans, breaks=64, xlab="Mean difference, cross-self",
     main="Histogram of all mean differences")
abline(v=mean(ZeaMays$diff), col="red", lwd=2)
abline(v=-mean(ZeaMays$diff), col="red", lwd=2, lty=2)