m-clark / mixedup

An R package for extracting results from mixed models that are easy to use and viable for presentation.
http://m-clark.github.io/mixedup
MIT License
64 stars 2 forks source link

empty zi for glmmTMB with extract_vc #25

Closed m-clark closed 3 years ago

m-clark commented 3 years ago

If a tmb model component doesn't have a random effect, extract_vc will fail, and subsequently summarize_model(..., component = 'zi'). It should return an empty result with a message, allowing the fixed effects to still be displayed.

library(glmmTMB)
library(mixedup)

(m1 <- glmmTMB(
  count ~ mined + (1 | site),
  zi =  ~ mined,
  family = poisson,
  data = Salamanders
))
#> Warning in Matrix::sparseMatrix(dims = c(0, 0), i = integer(0), j =
#> integer(0), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you

#> Warning in Matrix::sparseMatrix(dims = c(0, 0), i = integer(0), j =
#> integer(0), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you

#> Warning in Matrix::sparseMatrix(dims = c(0, 0), i = integer(0), j =
#> integer(0), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
#> Formula:          count ~ mined + (1 | site)
#> Zero inflation:         ~mined
#> Data: Salamanders
#>       AIC       BIC    logLik  df.resid 
#> 1908.4695 1930.8080 -949.2348       639 
#> Random-effects (co)variances:
#> 
#> Conditional model:
#>  Groups Name        Std.Dev.
#>  site   (Intercept) 0.28    
#> 
#> Number of obs: 644 / Conditional model: site, 23
#> 
#> Fixed Effects:
#> 
#> Conditional model:
#> (Intercept)      minedno  
#>      0.0879       1.1419  
#> 
#> Zero-inflation model:
#> (Intercept)      minedno  
#>       1.139       -1.736

summarize_model(m1, component = 'zi')
#> Error in sqrt(variance$variance): non-numeric argument to mathematical function

Created on 2021-04-14 by the reprex package (v2.0.0)