nevermind... I forgot the column of 1's for the intercept term
chuck.01 wrote > > Hi, > I was playing around with something else and I noticed this matrix code > for residuals in a linear model doesn't say what lm() says. Please tell > me if I am completely misguided here. > > data(mtcars) > Y <- as.matrix(mtcars[,1]) > X <- as.matrix(mtcars[,c(2:11)]) > > # shouldnt this: > H <- X %*% solve(t(X) %*% X) %*% t(X) > (diag(dim(H)[1]) - H) %*% Y > > # be equal to this: > residuals(lm(Y~X)) > > # ??? > # thanks > -- View this message in context: http://r.789695.n4.nabble.com/residuals-from-lm-tp4635155p4635183.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.