leeper / prediction

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

lme4 support #7

Closed puterleat closed 7 years ago

puterleat commented 7 years ago

I'm not sure what sort of shape the lme4 support is supposed to be in, but I've hit a bug which I thought I'd share... apologies if this is premature.

install_github("leeper/prediction")
install_github("leeper/margins", branch="master", force=T)
library('margins')
library('prediction')
library('lme4')

m <- lmer(Reaction~Days+(1|Subject), data=sleepstudy)
margins(m)

produces: this error:

Error in `[[<-`(`*tmp*`, "model", value = NULL) : 
  [[<- defined for objects of type "S4" only for subclasses of environment

Poking around a little:

build_margins(m, 
  build_datalist(sleepstudy, at=list(Days=1:9)))

produces:

Error in rep(NA_real_, nrow(data)) : invalid 'times' argument
In addition: Warning messages:
1: In marginal_effects.merMod(model = model, data = data, type = type,  :
  factor variables are not handled as factor for models of class 'merMod'
2: In dydx.default(X[[i]], ...) :
  Class of variable, factor(Days), is unrecognized. Returning NA.
puterleat commented 7 years ago

Switching this issue to margins repo where it belongs.