I was trying to track down a problem in my margins ggplot branch, and came upon this behavior I did not expect. Passing a data to prediction works with lm objects but not glm ones.
library(prediction)
data(mtcars)
# `data` with lm works
mod <- lm(am ~ hp + drat, data = mtcars)
prediction(mod, data = data.frame(hp = 110, drat = 3.9))
#> Data frame with 1 predictions from
#> lm(formula = am ~ hp + drat, data = mtcars)
#> with average prediction: 0.5947
# `data` with glm doesn't work
mod <- glm(am ~ hp + drat, data = mtcars)
prediction(mod, data = data.frame(hp = 110, drat = 3.9))
#> Warning in model$family$mu.eta(predictions_link) * model_mat: longer object
#> length is not a multiple of shorter object length
#> Error in is.data.frame(x): dims [product 3] do not match the length of object [32]
Bugfix proposed here: https://github.com/leeper/prediction/pull/33
I was trying to track down a problem in my
margins ggplot
branch, and came upon this behavior I did not expect. Passing adata
toprediction
works withlm
objects but notglm
ones.Created on 2019-03-10 by the reprex package (v0.2.1)