pbreheny / visreg

Visualization of regression functions
http://pbreheny.github.io/visreg/
61 stars 18 forks source link

Transformed predictors with lme4 mixed models #80

Closed GillesSanMartin closed 4 years ago

GillesSanMartin commented 4 years ago

visreg seems to have some trouble when you use transformation on the predictors within mixed models fitted with lme4 (with last visreg version from the CRAN : visreg_2.6-0 and lme4_1.1-21, R version 3.6.2)

The two following models return an error message
Error in FUN(X[[i]], ...) : objet 'Time' introuvable

library(lme4)
data(Milk, package="nlme")

fit <- lmer(protein ~ Diet + log(Time) + (log(Time)|Cow), Milk, 
            control = lmerControl(optimizer ="Nelder_Mead"))
visreg(fit)

fit <- lmer(protein ~ Diet + log(Time) + (1|Cow), Milk)
visreg(fit)

The same models fitted with nlme work fine :

fit <- nlme::lme(protein ~ Diet + log(Time), random = ~1|Cow, Milk)
visreg(fit)

fit <- nlme::lme(protein ~ Diet + log(Time), random = ~log(Time)|Cow, Milk)
visreg(fit)

And the following models fitted with lme4 "work"

# This works
fit <- lmer(protein ~ Diet + Time + (1|Cow), Milk)
visreg(fit)

# This works
fit <- lmer(protein ~ Diet + Time + (Time|Cow), Milk, 
            control = lmerControl(optimizer ="Nelder_Mead"))
visreg(fit)

# This works even is the model is rather stange...
fit <- lmer(protein ~ Diet + log(Time) + (Time|Cow), Milk, 
            control = lmerControl(optimizer ="Nelder_Mead"))
visreg(fit)
pbreheny commented 4 years ago

This should be fixed now in the GitHub version of visreg, as of commit 6d6d9d2d848e908eece0ad3d0d65bbb52b2cb808. If you still encounter this bug, please let me know (and re-open the issue).

Thank you for pointing this out, and sorry for not responding to this sooner! Was busy with other things....

GillesSanMartin commented 4 years ago

Yes it works with the new github version ! Thanks for the fix and thanks for such a great package !