leeper / prediction

Tidy, Type-Safe 'prediction()' Methods
https://cran.r-project.org/package=prediction
Other
89 stars 14 forks source link

`data` argument breaks with `glm` but works with `lm` #32

Closed vincentarelbundock closed 5 years ago

vincentarelbundock commented 5 years ago

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 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]

Created on 2019-03-10 by the reprex package (v0.2.1)

vincentarelbundock commented 5 years ago

This issue is fixed in https://github.com/leeper/prediction/pull/33