# Vectors.R # change path data <- read.table("C:/Documents and Settings/steeleb/My Documents/Math 543/BrainWeight.txt",sep=",",header=TRUE) brain <- scale(log(data$brain)) body <- scale(log(data$body)) species <- data$species plot(brain~body,xlab="Log(body)",ylab="Log(brain)") abline(a=0,b=1) primates.index <- 6:24 points(body[primates.index],brain[primates.index],col=2,pch=16) identify(brain~body,labels=species) n <- length(brain) axis.1 <- rep(1,2)/sqrt(2) x <- rep(0,n) y <- rep(0,n) for (i in 1:n) { v <- c(brain[i],body[i]) length.v <- sqrt(t(v)%*%v) cos.theta <- t(v)%*%axis.1/length.v x[i] <- t(v)%*%axis.1 theta <- acos(cos.theta) if (v[1] < v[2]) y[i] <- -length.v*sin(theta) else y[i] <- length.v*sin(theta) } plot(y~x) abline(a=0,b=0) points(x[primates.index],y[primates.index],col=2,pch=16) identify(y~x,labels=species) s