Read the data we're looking at.

> d <- read.table("http://www.cs.utoronto.ca/~radford/csc120/lab9-data",
+                  header=TRUE)

Produce all pairwise scatterplots of variables.

> plot(d[,c("A","B","C")],pch=20)

plot of chunk unnamed-chunk-3

Define the function for displaying plots for the visual permutation test.

> perm_test <- function (u, v) {
+     par(mfrow=c(3,3))
+     for (i in 1:9) {
+         if (i == 5) 
+             plot(u,v,pch=20)
+         else
+             plot(u,sample(v),pch=20)
+     }
+ }

Produce plots for the tests of all possible pairs of variables A, B, and C.

> perm_test(d$A,d$B)

plot of chunk unnamed-chunk-5

> perm_test(d$A,d$C)

plot of chunk unnamed-chunk-5

> perm_test(d$B,d$C)

plot of chunk unnamed-chunk-5

Do it again for the subset of cases where D is “X”.

> dX <- d[d$D=="X",]
> perm_test(dX$A,dX$B)

plot of chunk unnamed-chunk-6

> perm_test(dX$A,dX$C)

plot of chunk unnamed-chunk-6

> perm_test(dX$B,dX$C)

plot of chunk unnamed-chunk-6

Do it again for the subset of cases where D is “Y”.

> dY <- d[d$D=="Y",]
> perm_test(dY$A,dY$B)

plot of chunk unnamed-chunk-7

> perm_test(dY$A,dY$C)

plot of chunk unnamed-chunk-7

> perm_test(dY$B,dY$C)

plot of chunk unnamed-chunk-7