General question about predictions in PLS, using the chemometrics
package in R
here for an example. The standard example for pls1_nipals
is
data(PAC)
res <- pls1_nipals(PAC$X,PAC$y,a=5)
This returns the coefficient vector res$b
. Now lets assume the first 200
of 209
objects (rows) of PAC$X,PAC$y
are used for calibration and the rest is used for validation.
res <- pls1_nipals(PAC$X[1:200,],PAC$y[1:200],a=5)
cbind(PAC$X[201:209,]%*%res$b,PAC$y[201:209])
leads to
[,1] [,2]
470103.8 486.81
457944.5 488.18
491483.9 495.01
487573.0 495.45
499962.8 497.66
487223.3 500.00
656960.3 501.32
661962.2 503.89
635861.9 503.91
The reason for the extreme difference is, that X
and Y
were centered. The centering of Y
can be eliminated bei adding mean(PAC$[1:200])
to PAC$X[201:209,]%*%res$b
. But how to correct the centering of X
? First I thought by using colMeans(PAC$X[1:200,])
, but it didn't work.
cbind((PAC$X[201:209,]
-matrix(rep(colMeans(PAC$X[1:200,]),9),ncol=467,nrow=9,byrow=TRUE))
%*%res$b+mean(PAC$y[1:200]),
PAC$y[201:209])
Any ideas? Thanks.
pls::plsr
models. I suspect you may have found a bug (in the normalization of the inner relation coefficients), and I emailed the package maintainer about it. I'll write an answer once I know more. $\endgroup$ – cbeleites unhappy with SX Aug 2 '16 at 14:38