Skip to content

Instantly share code, notes, and snippets.

@tslumley
Created December 3, 2017 20:58
Show Gist options
  • Save tslumley/71d617bce5e52279ebecc092c2b4e6b7 to your computer and use it in GitHub Desktop.
Save tslumley/71d617bce5e52279ebecc092c2b4e6b7 to your computer and use it in GitHub Desktop.
Non-transitive dice

An example of the non-transitivity of the Wilcoxon test, using Efron's non-transitive dice.

refron() generates numbers from a set of four non-transitive dice, so that a beats b beats c beats d beats a two-thirds of the time, with optional Gaussian smoothing.

example.R does Wilcoxon rank-sum tests to show that a > b > c > d > a

dd<-efron(1000,s=0.2)
wilcox.test(dd[,1],dd[,2],alternative="greater")
wilcox.test(dd[,2],dd[,3],alternative="greater")
wilcox.test(dd[,3],dd[,4],alternative="greater")
wilcox.test(dd[,4],dd[,1],alternative="greater")
refron<-function(n,which=c("a","b", "c", "d"), smooth=0){
M<-matrix(nrow=n,ncol=4)
colnames(M)<-c("a","b", "c", "d")
M[,1]<-sample(c(0,0,4,4,4,4),n,replace=TRUE)
M[,2]<-sample(c(3,3,3,3,3,3),n,replace=TRUE)
M[,3]<-sample(c(2,2,2,2,6,6),n,replace=TRUE)
M[,4]<-sample(c(1,1,1,5,5,5),n,replace=TRUE)
if (smooth>0) M<-M+rnorm(length(M),s=smooth)
M[,which]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment