[R] Problem with predict.lm()

Martin Spindler
Wed, 29 Apr 2015 14:21:16 -0000

Dear all,
?
the following example somehow uses the "old data" (X) to make the
predictions, but not the new data Xnew as intended.
?
y <- rnorm(100)
X <- matrix(rnorm(100*10), ncol=10)
lm <- lm(y~X)
Xnew <- matrix(rnorm(100*20), ncol=10)
ynew <- predict(lm, newdata=as.data.frame(Xnew)) #prediction in not made for
Xnew
?
How can I foce predict.lm to use use the new data?
?
Thank you very much for your efforts in advance!
?
Best,
?
Martin