Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SchmidtPaul opened this issue Jun 12, 2020 · 0 comments

Comments

@SchmidtPaul
Copy link

SchmidtPaul commented Jun 12, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant