On Aug 27, 2019, at 9:57 AM, Fox, John <jfox at mcmaster.ca> wrote:
Dear Ben, Daniel, and Julian,
A reproducible example would have been nice, but it's easy to create one:
-------- snip ---------
library("glmmTMB")
example("glmmTMB")
Loading required package: carData
lattice theme set by effectsTheme()
See ?effectsTheme for details.
ef <- Effect("sd", m0) # sd is character
plot(ef) # error
Error in UseMethod("droplevels") :
no applicable method for 'droplevels' applied to an object of class "character"
dat$sd <- as.factor(dat$sd)
mf0 <- update(m0)
ef0 <- Effect("sd", mf0)
plot(ef0) # works
And as Ben suggests, the problem isn't unique to glmmTMB models.
The temporary fix, as in the example above, is to change the character predictor to a factor. That shouldn't be necessary: Until the current version, Effect() didn't accommodate character predictors. Now that it does, plot.eff() should work with them too and it doesn't. I'll investigate the bug and fix it.
Best,
John
-------------------------------------------------
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: http::/socserv.mcmaster.ca/jfox
On Aug 27, 2019, at 9:31 AM, Ben Bolker <bbolker at gmail.com> wrote:
Yes, quite weird as effects:::plot.eff (the relevant method) appears
to check that variables are factors every time it tries to applies
droplevels(). A reproducible example would be great (although
technically maybe not this list's problem, as it's not clear it's
directly mixed-model-related?)
On 2019-08-27 8:06 a.m., Daniel L?decke wrote:
Dear Julian,
without a reproducible example, it's a bit difficult to guess how to solve
your issue. Is one of your predictors of class "character" and should
probably be coerced to factor before you fit your model?
Else, you could also try the "ggeffects" package
(https://strengejacke.github.io/ggeffects/), where you have three functions:
ggpredict(), ggeffect() and ggemmeans(), each calling the related functions
"predict()", "effects::effect()" or "emmeans::emmeans()" internally to
compute marginal effects. There is a plot() method as well, based on ggplot2
(see examples here
https://strengejacke.github.io/ggeffects/articles/introduction_plotcustomize
.html or here
https://strengejacke.github.io/ggeffects/articles/introduction_plotmethod.ht
ml).
Best
Daniel
-----Urspr?ngliche Nachricht-----
Von: R-sig-mixed-models [mailto:r-sig-mixed-models-bounces at r-project.org] Im
Auftrag von Julian Gaviria Lopez
Gesendet: Dienstag, 27. August 2019 12:01
An: r-sig-mixed-models at r-project.org
Betreff: [R-sig-ME] Plotting post-fitting inference effects in a glmmTMB
model
Hello,
I have the next model:
zipoisson2 <- glmmTMB(Observations ~ CAP * Condition + (1|ID),
contrasts=list(CAP="contr.sum",Condition="contr.sum"), data=mDATA,
ziformula=~ 1 , family=poisson)
Plotting the effects ("effects" package), I obtain:
(ae <- allEffects(zipoisson2))
model: Observations ~ CAP * Condition
CAP*Condition effect
Condition
CAP aapaff aff neu pneu
apreC3 3.222636 2.731724 2.777021 2.573694
insC5 1.406698 3.173030 2.104875 1.420336
preC1 2.883115 3.641252 2.541221 2.635991
preC5 2.184075 2.310564 3.137734 1.995430
plot(ae)
Error in UseMethod("droplevels") :
no applicable method for 'droplevels' applied to an object of class
"character"
Question 1: Has anyone encountered the same issue? Any hint to solve it?
Question 2: Maybe is there any other package works better with glmmTMB model
Thanks in advance for any hint about it.
Julian,
[[alternative HTML version deleted]]