Notes on R for Assignment 2: You can find the maximum likelihood estimates for a logistic regression model (with intercept) as follows: > x [,1] [,2] [1,] 3 8 [2,] 4 8 [3,] 9 7 [4,] 8 3 [5,] 2 3 > y [1] 0 1 0 0 1 > coef(glm(y~x,family=binomial)) (Intercept) x1 x2 4.6371776 -0.7887676 -0.2378624 You can find the eigenvalues and eigenvectors of a matrix as follows (I use t(X)%*%X as an example since it will be positive definite, as is the case for covariance matrices): > X [,1] [,2] [,3] [1,] 4 3 2 [2,] 2 3 1 [3,] 1 5 5 [4,] 9 8 4 > e <- eigen(t(X)%*%X) > e$values [1] 235.7886409 18.3285997 0.8827595 > e$vectors [,1] [,2] [,3] [1,] 0.6270711 0.7081222 0.3245688 [2,] 0.6679452 -0.2744200 -0.6917679 [3,] 0.4007880 -0.6505818 0.6450677 The eigenvalues are in e$values. The (right) eigenvectors are the columns of e$vectors. The eigenvectors are chosen to have length one, but that leaves an arbitrary sign (since negating everything doesn't change the direction). You can make scatterplots with classes in different colours with commands like this: > plot(x.train[,1],x.train[,2],pch=20,col=c("blue","red")[1+y.train])