[R] lm.ridge {MASS} ridge regression calculation question

Jimmy Purnell jpurnell7 at gmail.com
Tue Nov 17 19:20:36 CET 2009


Why do I get different coefficients for each of these methods?

Y <- matrix(c(136,144,145,169,176),byrow=F,5,1)
X1 <- matrix(c(91,105,109,130,146),byrow=F,5,1)
X2 <- matrix(c(11,13,17,19,23),byrow=F,5,1)
cY <- scale(Y, scale=FALSE)
sX1 <- scale(X1)
sX2 <- scale(X2)
library(MASS)
lm.ridge(cY ~ sX1 + sX2, lambda = 100)

This yields different coefficients than what I get from this, which I
thought should be identical (if I set the lambdas to 0 rather than 100
I get identical results):

Xmat <- cbind(sX1, sX2)
Ymat <- cbind(cY)
XXI <- solve(t(Xmat)%*%Xmat + 100*diag(2))
XY <- t(Xmat)%*%Ymat
(ridge.coef <- XXI%*%XY)

Thanks,
Jim




More information about the R-help mailing list