predict function (PR#2958)
Full_Name: Murray H Smith Version: 1.6.1 OS: Windows Submission from: (NULL) (202.36.29.1) This is report is more of a matter of completeness rather than an outright bug. The predict function does not handle the prediction from the constant model appropriately. It also differs from Splus in this respect. The length of the vector (or first dimension of the matrix, if type = "terms" is used) for the output from the predict function should equal the number of rows in newdata, whether or not the model is the constant model.
predict(lm(y ~ 1, data = data.frame(y = rep(0:3, c(5,9,7,1)))),
+ newdata = data.frame(x = 1:5)) [1] 1.181818
predict(glm(y ~ 1, family = poisson, data = data.frame(y =
+ rep(0:3, c(5,9,7,1)))), newdata = data.frame(x = 1:5), type = "r")
[1] 1.181818
Since there are 5 rows in the newdata data.frame the result should be the vector
of length 5.
[1] 1.181818 1.181818 1.181818 1.181818 1.181818
.
As an aside it might also be nice to also avoid having to deal with a special
case by defaulting the model formula
~ poly(x, 0)
to
~ 1
with perhaps a warning rather than producing an error.