Search code examples
rggplot2broomggallyglmmtmb

ggcoef_model error when two random intercepts


When trying to graph the conditional fixed effects of a glmmTMB model with two random intercepts in GGally I get the error:

There was an error calling "tidy_fun()". Most likely, this is because the function supplied in "tidy_fun=" was misspelled, does not exist, is not compatible with your object, or was missing necessary arguments (e.g. "conf.level=" or "conf.int="). See error message below. Error: Error in "stop_vctrs()": ! Can't recycle "..1" (size 3) to match "..2" (size 2).`

I have tinkered with figuring out the issue and it seems to be related to the two random intercepts included in the model. I have also tried extracting the coefficient and standard error information separately through broom.mixed::tidy and then feeding the data frame into GGally:ggcoef() with no avail. Any suggestions?

# Example with built-in randu data set
data(randu)
randu$A <- factor(rep(c(1,2), 200))
randu$B <- factor(rep(c(1,2,3,4), 100))

# Model
test <- glmmTMB(y ~ x + z + (0 +x|A) + (1|B), family="gaussian", data=randu)

# A few of my attempts at graphing--works fine when only one random effects term is in model
ggcoef_model(test)

ggcoef_model(test, tidy_fun = broom.mixed::tidy)

ggcoef_model(test, tidy_fun = broom.mixed::tidy, conf.int = T, intercept=F)

ggcoef_model(test, tidy_fun = broom.mixed::tidy(test, effects="fixed", component = "cond", conf.int = TRUE))


Solution

  • There are some (old!) bugs that have recently been fixed (here, here) that would make confidence interval reporting on RE parameters break for any model with multiple random terms (I think). I believe that if you are able to install updated versions of both glmmTMB and broom.mixed:

    remotes::install_github("glmmTMB/glmmTMB/glmmTMB@ci_tweaks")
    remotes::install_github("bbolker/broom.mixed")
    

    then ggcoef_model(test) will work.

    enter image description here