# Visual significance tests (due to Andreas Buha). # Look at the nrow by ncol array of scatterplots, visually order them by # decreasing strength of relationship, then see the position (row, col) # of the true scatterplot by typing .Last.value. If the true plot shows # the i'th strongest relationship, the p-value is 1/(nrow*ncol). # Test whether real-valued x and y are related. scram.test.xy <- function (x, y, nrow=4, ncol=5) { row.true <- sample(1:nrow,1) col.true <- sample(1:ncol,1) par (mfrow=c(nrow,ncol), mar=c(2,2,1,1), mgp=c(1,0.6,0)) for (row in 1:nrow) { for (col in 1:ncol) { if (row==row.true && col==col.true) { py <- y } else { py <- y[sample(1:length(y),length(y))] # can be done as py <- sample(y) } plot (x, py, xlab="", ylab="", pch=20) } } invisible(c(row.true,col.true)) } # Test whether real-valued (x,y) and categorical c are related. Here, c # should be a vector of colours, or a vector of positive integers. scram.test.xyc <- function (x, y, c, nrow=4, ncol=5) { row.true <- sample(1:nrow,1) col.true <- sample(1:ncol,1) par (mfrow=c(nrow,ncol), mar=c(2,2,1,1), mgp=c(1,0.6,0)) for (row in 1:nrow) { for (col in 1:ncol) { if (row==row.true && col==col.true) { pc <- c } else { pc <- c[sample(1:length(c),length(c))] # can be done as pc <- sample(c) } plot (x, y, col=pc, xlab="", ylab="", pch=20) } } invisible(c(row.true,col.true)) }