I am running R 3.0.2 and using the PLS package to build partial least squares models. The problem I am having is that when I apply feature-scaling to my design matrix the resulting coefficient vector does not reproduce the predicted response values on my training and cross-validation samples. Here is my code:
model.train <- cppls(y ~ ., data = data.train, ncomp = 20, scale = TRUE,
validation = "none", weights = w)
yhat.train <- fitted(model.train)
B <- coef(model.train, intercept = TRUE, ncomp = 20)
yhat.cv <- predict(model.train, newdata = data.cv, ncomp = 20, type = "response")
If I then take the B vector and multiply by my design matrix, the resulting values do not equal the values generated by the fitted()
and predict()
functions; in other words, Y != BX
. However if I run the exact same code with scale = FALSE
in the cppls()
function, Y = BX
.
My question is whether the coef()
function is simply failing to re-scale the betas, or if I'm making some error in my routine. I would really like to be able to apply feature-scaling to my design matrix, but I need the correct beta vector as an output. Would greatly appreciate any advice.
X
when computingY = BX
by hand? ANyway, you've answered that with what you write later. I'm not familiar enough with Canonical PLS to know if you can just undo the scaling in the manner described in the Cross Validated post I linked to. If it is similar to PLS, then it should be ok to do this as PLS is just a linear regression at heart. Perhaps this would be best on Cross Validated. You could flag it for migration by a moderator? $\endgroup$ – Gavin Simpson Feb 24 '14 at 21:53