bbolker/broom.mixed

Dimension problems when using broom.mixed on model with fixed correlation value

Opened this issue · 2 comments

Hi Ben,

Thank you for the great packages (both broom.mixed and glmmTMB)!

I've been running into problems when fixing some of the parameter values in glmmTMB. While using the map argument in glmmTMB appears to fix most of my problems, I'm still stuck with broom.mixed. In particular, I'm running into problems when trying to get the confidence intervals when I fix one of the parameters associated with the random effects. Here is a set of examples, starting with two models that work.

M1: Model where we estimate everything works well. There are convergence problems and NAs, but broom.mixed::tidy returns a table.

library(glmmTMB)
library(broom.mixed)

data("Salamanders")

m1 <- glmmTMB(
  count ~ cover  + (1 + cover | site),
  family = poisson,
  data = Salamanders)

broom.mixed::tidy(m1, conf.int = TRUE)

M2: model where we fix the intercept value works well.

m2 <- glmmTMB(
  count ~ cover  + (1 + cover | site),
  family = poisson,
  data = Salamanders, 
  map=list(beta = factor(c(NA, 1))),
  start = list(beta = c(0, 0)))


broom.mixed::tidy(m2, conf.int = TRUE)

M3: Model where we fix the correlation between random effects does not work with broom.mixed::tidy.

m3 <- glmmTMB(
  count ~ cover  + (1 + cover | site),
  family = poisson,
  data = Salamanders, 
  map=list(theta = factor(c(1, 2, NA))),
  start = list(theta = c(0, 0, 0)))

broom.mixed::tidy(m3, conf.int = TRUE)

This returns:

Error in bind_cols():
! Can't recycle ..1 (size 3) to match ..2 (size 2).
Run rlang::last_trace() to see where the error occurred.

M4: model where the sd of the random effect associated with the intercept is fixed also does not work.

m4 <- glmmTMB(
  count ~ cover  + (1 + cover | site),
  family = poisson,
  data = Salamanders, 
  map=list(theta = factor(c(NA, 1, 2))),
  start = list(theta = c(log(1), 0, 0)))


broom.mixed::tidy(m4, conf.int = TRUE)

In this case again, broom.mixed returns:

Error in bind_cols():
! Can't recycle ..1 (size 3) to match ..2 (size 2).
Run rlang::last_trace() to see where the error occurred.
Warning messages:
1: In sqrt(diag(vv)) : NaNs produced
2: In sqrt(diag(object$cov.fixed)) : NaNs produced
3: In sqrt(diag(vv)) : NaNs produced
4: In sqrt(diag(object$cov.fixed)) : NaNs produced

Hopefully, I'm not missing something obvious.

Thanks!

I doubt you're missing anything obvious. Getting all the details of mapped parameters right is tedious ... I definitely appreciate the example and will take a look.

Hmm. This seems to work now, I can't tell whether it's due to updates in glmmTMB or broom.mixed. Not excited about doing the archaeology to see where it changed; can you check and see whether it works for you with up-to-date versions of both packages?