bbolker/broom.mixed

tidy(effects = "ran_pars") won't return Residual variance when glmmTMB model has no random effects

SchmidtPaul opened this issue · 0 comments

Hi there, great work so far!
I know this is a minor issue and I would accept the argument, that it is strictly speaking not the scope of broom.mixed, but tidy(effects = "ran_pars") does not seem to be extracting the residual variance of a glmmTMB object when no random effects are present in the model so that the model is actually not mixed, but rather a simple linear model with fixed effects only:

library(broom.mixed)
library(glmmTMB)
library(tidyverse)

dat <- agridat::mcconway.turnip %>% mutate(unit = 1:n() %>% as.factor)

# random block effect
mixed.mod <- glmmTMB(formula = yield ~ gen + (1 | block),
                     dispformula = ~ 1, # default
                     REML = TRUE, data = dat)

# fixed block effect
fixed.mod <- glmmTMB(formula = yield ~ gen + block,
                     dispformula = ~ 1, # default
                     REML = TRUE, data = dat)

# fixed block effect, but error variance forced in G-side as random unit effect
pseudomixed.mod <- glmmTMB(formula = yield ~ gen + block + (1 | unit), # mimic error variance
                           dispformula =  ~ 0, # fix original error variance to 0
                           REML = TRUE, data = dat)

mixed.mod       %>% tidy(effects = "ran_pars", scales = "vcov") # block and residual variance
#> # A tibble: 2 x 5
#>   effect   component group    term             estimate
#>   <chr>    <chr>     <chr>    <chr>               <dbl>
#> 1 ran_pars cond      block    var__(Intercept)     1.98
#> 2 ran_pars cond      Residual var__Observation    22.9

fixed.mod       %>% tidy(effects = "ran_pars", scales = "vcov") # empty tibble
#> # A tibble: 0 x 0

pseudomixed.mod %>% tidy(effects = "ran_pars", scales = "vcov") # "residual" variance
#> # A tibble: 1 x 5
#>   effect   component group term             estimate
#>   <chr>    <chr>     <chr> <chr>               <dbl>
#> 1 ran_pars cond      unit  var__(Intercept)     22.9

Created on 2020-12-08 by the reprex package (v0.3.0.9001)

broom.mixed_0.2.6
glmmTMB_1.0.2.1

Thanks in advance!