Closed MarcRieraDominguez closed 1 year ago
This is due to the fact that some models have multiple portions and the coefficient names are typically prefixed or wrapped. In this case, we have:
> coef(mixmod.tmb.avg)
cond((Int)) cond(FoodTreatmentSatiated)
1.7410094 -1.8463991
cond(poly(BroodSize, 2, raw = TRUE)1) cond(poly(BroodSize, 2, raw = TRUE)2)
-0.5129341 0.1280694
cond(SexParentMale)
0.4261344
i.e., the coefficient names are wrapped with cond()
. This is provided for via the optional subset
argument -- see the [documentation]
(https://cran.r-project.org/web/packages/emmeans/vignettes/models.html#I) for the models vignette for averaging
objects. Using this we have
> emmeans(mixmod.tmb.avg, specs = pairwise ~ SexParent, adjust = "Tukey", regrid = "response", data = Owls,
+ subset = "wrap:cond")
$emmeans
SexParent prob SE df lower.CL upper.CL
Female 0.701 0.0506 593 0.601 0.800
Male 0.749 0.0418 593 0.667 0.832
Results are averaged over the levels of: FoodTreatment
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Female - Male -0.0489 0.0483 593 -1.014 0.3112
Results are averaged over the levels of: FoodTreatment
That said, there was a glitch in the subset
code, so if using version 1.8.9 or earlier, you need to install emmeans from GitHub.
Hello! You are right. I just downloaded version 1.8.9-900001 from GitHub, and emmeans()
and emtrends()
work fine with the subset
argument you provided. I'll be closing this.
Thank you very much!
Hello Russell! Thank you for maintaining the package!
Describe the bug
emmeans::emmeans()
won't work with a model-averaged binomial GLMM (classaveraging
,MuMIn
package), when fitted withglmmTMB::glmmTMB()
:Error in ME[, nms, drop = FALSE] : subscript out of bounds
I suspect it has to do with trouble accessing the data, perhaps due to shifting variable names. Unfortunately, don't know how to fix it.
The problem appears to be specific to model-averaged
glmmTMB
: a model-averaged binomial GLM fitted withglmmTMB
throws the same error; but model-averagedlme4::glmer()
(binomial GLMM) andstats::glm()
(binomial GLM) work fine. I'd rather stay withglmmTMB
because it allows parallelization (my data has > 61000 rows, which I have not shared. Instead, I've prepared a reprex that throws the same error).Expected behavior
The common output of
emmeans::emmeans()
: estimated marginal means, with their standard errors, and Tukey contrats.Additional context
I ran into this issue with a model-averaged binomial GLMM that related a proportion to: categorical factors (unordered), numerical variables with second-order polynomials (
poly(x, 2, raw = TRUE)
), and numerical variables without polynomials. My dataset is large (around 62000 rows, and not yet published), so I've devised a reprex that throws the same error message.To reproduce
Created on 2023-11-14 with reprex v2.0.2
Many thanks in advance!