richard — Jun 10, 2014, 6:26 PM
ad <- read.csv("http://www.math.leidenuniv.nl/~gill/AliceDirections.csv") # Alice directions file
head(ad)
i x y
1 1 0.9609 0.27679
2 2 0.6448 -0.76431
3 3 0.9676 -0.25256
4 4 -0.8331 -0.55305
5 5 0.9777 0.20980
6 6 -0.9988 -0.04982
u <- rbind(ad$x, ad$y) # just the x and y coordinates as a 2xN matrix
rownames(u) <- c("x", "y")
bd <- read.csv("http://www.math.leidenuniv.nl/~gill/BobDirections.csv") # Bob directions file
head(bd)
i x y
1 1 -0.9609 -0.27679
2 2 -0.6448 0.76431
3 3 -0.9676 0.25256
4 4 0.8331 0.55305
5 5 -0.9777 -0.20980
6 6 0.9988 0.04982
nrow(ad) == nrow(bd) # both files same length?
[1] TRUE
v <- rbind(bd$x, bd$y) # just the x and y coordinates as a 2xN matrix
rownames(v) <- c("x", "y")
## The data came "row-wise" (each observation a different row)
## But for technical reasons I wanted it column-wise.
## The function "t" transposes a matrix
head(t(u)) # the first few directions in u
x y
[1,] 0.9609 0.27679
[2,] 0.6448 -0.76431
[3,] 0.9676 -0.25256
[4,] -0.8331 -0.55305
[5,] 0.9777 0.20980
[6,] -0.9988 -0.04982
tail(t(u)) # the last few directions in u
x y
[7065,] -0.9993 0.03809
[7066,] -0.8874 -0.46096
[7067,] -0.9077 0.41971
[7068,] -0.9912 0.13251
[7069,] 0.9680 0.25077
[7070,] -0.6009 0.79932
head(t(v)) # the first few directions in v
x y
[1,] -0.9609 -0.27679
[2,] -0.6448 0.76431
[3,] -0.9676 0.25256
[4,] 0.8331 0.55305
[5,] -0.9777 -0.20980
[6,] 0.9988 0.04982
tail(t(v)) # the last few directions in v
x y
[7065,] 0.9993 -0.03809
[7066,] 0.8874 0.46096
[7067,] 0.9077 -0.41971
[7068,] 0.9912 -0.13251
[7069,] -0.9680 -0.25077
[7070,] 0.6009 -0.79932
# E(0, 45)
alpha <- 0 * pi / 180
beta <- 45 * pi / 180
a <- c(cos(alpha), sin(alpha))
b <- c(cos(beta), sin(beta))
rho11 <- mean(sign(colSums(a*u))*sign(colSums(b*v))) # E(0, 45)
rho11 # E(0, 45)
[1] -0.624
# E(0, 135)
alpha <- 0 * pi / 180
beta <- 135 * pi / 180
a <- c(cos(alpha), sin(alpha))
b <- c(cos(beta), sin(beta))
rho12 <- mean(sign(colSums(a*u))*sign(colSums(b*v)))
rho12 # E(0, 135)
[1] 0.632
# E(90, 45)
alpha <- 90 * pi / 180
beta <- 45 * pi / 180
a <- c(cos(alpha), sin(alpha))
b <- c(cos(beta), sin(beta))
rho21 <- mean(sign(colSums(a*u))*sign(colSums(b*v)))
rho21 # E(90, 45)
[1] -0.355
# E(90, 135)
alpha <- 90 * pi / 180
beta <- 135 * pi / 180
a <- c(cos(alpha), sin(alpha))
b <- c(cos(beta), sin(beta))
rho22 <- mean(sign(colSums(a*u))*sign(colSums(b*v)))
rho22 # E(90, 135)
[1] -0.389
### To summarize, here are the four correlations:
corrs <- c(rho11, rho12, rho21, rho22)
names(corrs) <- c("E(0, 45)", "E(0, 135)", "E(90, 45)", "E(90, 135)")
corrs
E(0, 45) E(0, 135) E(90, 45) E(90, 135)
-0.624 0.632 -0.355 -0.389