Ok, yes, I can match them now. Thank you very much!



On Tue, Jun 24, 2014 at 3:58 AM, Bjørn-Helge Mevik <b.h.mevik@usit.uio.no>
wrote:

> annie Zhang <annie.zhang2010@gmail.com> writes:
>
> > ## the predicted scores from the model
> > (pred <- predict(data.cpls,n.comp=1:2,newdata=x.new,type="score"))
> > ## the predicted scores using x%*%projection
> >
> cbind(x.new.centered%*%data.cpls$projection[,1],x.new.centered%*%data.cpls$projection[,2])
> >
> > Can someone please tell me why the two predicted scores don't match?
>
> If you look at the code that does the prediction:
>
> > pls:::predict.mvr
> function (object, newdata, ncomp = 1:object$ncomp, comps, type =
> c("response",
>     "scores"), na.action = na.pass, ...)
> {
> [...]
>            TT <- (newX - rep(object$Xmeans, each = nobs)) %*%
>                 object$projection[, comps]
>
> you will see that it subtracts the _old X_ coloumn means from the new X
> matrix, not the _new X_ coloumn means.  So
>
> sweep(x.new, 2, data.cpls$Xmeans, "-") %*% data.cpls$projection[,1:2]
>
> will reproduce the values from predict().
>
> --
> 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.
>

	[[alternative HTML version deleted]]

