The most common case that I see that error is when someone fits their
model using syntax like:
fit <- lm( mydata$y ~ mydata$x )
instead of the preferred method:
fit <- lm( y ~ x, data=mydata )
The fix (if this is what you did and why you are getting the error) is
to not use the first way and in
This can happen if your newdata data.frame does not include
all the predictors required by the formula in the model. In that
case predict will look in the current evaluation environment to
find the missing predictors, and those will generally not match
what is in your newdata. E.g.,
> x1 <- 1:6
> Of course I can extend the new dataframe with a few thousands
> NAs, but is there a more elegant solution?
That should not be necessary: predict.lm should work on any number of newdata
rows, whether longer or shorter than the original data set.
However, the help page for predict.lm says (among
3 matches
Mail list logo