### HW 7 solutions ### AHW3 ### December 3, 2007 rm(list = ls()) ############################################ ## 1 y <- matrix(c(15,9,3,25,7,13), 6,1) z <- cbind(rep(1,6), c(10, 5, 7, 19, 11, 8)) n <- nrow(y) p <- ncol(y) ## calculate beta.hat beta.hat <- solve(t(z)%*%z)%*%t(z)%*%y beta.hat ## calculate y.hat (the fitted values) y.hat <- z%*%beta.hat y.hat ## calculate epsilon.hat (the residuals) eps.hat <- y-y.hat eps.hat ## calculate the cross products of the residuals eps.hat.eps.hat <- t(eps.hat)%*%eps.hat eps.hat.eps.hat ############################################ ## 2 rm(list = ls()) y <- matrix(c(5,-3,3,-1,4,-1,2,2,1,3), 5,2, byrow=T) z <- cbind(rep(1,5), c(-2,-1,0,1,2)) n <- nrow(y) p <- ncol(y) ## calculate beta.hat beta.hat <- solve(t(z)%*%z)%*%t(z)%*%y beta.hat ## calculate y.hat (the fitted values) y.hat <- z%*%beta.hat y.hat ## calculate epsilon.hat (the residuals) eps.hat <- y-y.hat eps.hat ## calculate the cross products of the residuals eps.hat.eps.hat <- t(eps.hat)%*%eps.hat eps.hat.eps.hat