"Stella Sim" <[EMAIL PROTECTED]> writes:

> I want to calculate SPE (squared prediction error) in x-space, can
> someone help?
>
> Here are my codes:
>
> fit.pls<-
> plsr(Y~X,data=DAT,ncomp=3,scale=T,method='oscorespls',validation="CV",x=
> T) 
> actual<-fit.pls$model$X

(The x = TRUE is not needed as long as model = TRUE (default).  x=TRUE
returns the predictors as fit.pls$x, and is included for "compatibility"
with lm().)

> pred<-fit.pls$scores %*% t(fit.pls$loadings)
> SPE.x<-rowSums((actual-pred)^2)
>
> Am I missing something here? 

You are missing the mean X spectrum.  See
matplot(t(pred), type = "l", lty = 1) vs. matplot(t(actual), type = "l", lty = 
1)

The Xmeans compontent of fit.pls contains this, so

pred <- sweep(fit.pls$scores %*% t(fit.pls$loadings), 2, fit.pls$Xmeans, "+")

would give you what you want.

Note, however, that this will calculate the _fitted_ SPE, not the
cross-validated SPE.  The crossvalidation implemented in the pls package
does not save the cross-validated scores/loadings -- that would consume
too much memory.  (Calculation of SPE withing the cross-validation
routines could have been implemented, but was not.)

-- 
Regards,
Bjørn-Helge Mevik

______________________________________________
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.

Reply via email to