Read the data we're looking at.

``````> d <- read.table("http://www.cs.utoronto.ca/~radford/csc120/lab9-data",
``````

Produce all pairwise scatterplots of variables.

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

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)
``````

``````> perm_test(d\$A,d\$C)
``````

``````> perm_test(d\$B,d\$C)
``````

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

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

``````> perm_test(dX\$A,dX\$C)
``````

``````> perm_test(dX\$B,dX\$C)
``````

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

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

``````> perm_test(dY\$A,dY\$C)
``````

``````> perm_test(dY\$B,dY\$C)
``````