Hi All,
I want to produce scores from X using $projection. When I predict, I cannot
match the predicted scores and scores using x%*%projection.
Below is a very simple example,
set.seed(seed=1)
y <- c(1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0)
x <- matrix(runif(200),nrow=20)
data <- data.frame(cbind(y,x))
colnames(data) <-
c("out","x1","x2","x3","x4","x5","x6","x7","x8","x9","x10")
data.cpls <- plsr(out~x1+x2+x3+x4+x5+x6+x7+x8+x9+x10,2,data=data)
x.new <- matrix(runif(50),nrow=5)
x.new.centered <- x.new
for (i in 1:ncol(x.new)) {
x.mean <- mean(x.new[,i])
x.new.centered[,i] <- (x.new[,i]-x.mean)
}
## 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?
Thanks,
Annie
[[alternative HTML version deleted]]