easystats / insight

:crystal_ball: Easy access to model information for various model objects
https://easystats.github.io/insight/
GNU General Public License v3.0
404 stars 39 forks source link

`get_variance()` Triggers Model Recompilation and Returns `NULL` for `brms` Mixed Models in v0.20.3 #915

Closed matschmitz closed 3 months ago

matschmitz commented 3 months ago

When using get_variance() from insight v0.20.3, the model unexpectedly recompiles, and the function returns NULL. This behavior differs from v0.20.1, where it correctly returns the variance components without recompiling the model.

library(brms)
library(insight)

mdl <- brm(mpg ~ hp + (1 | cyl), data = mtcars)

get_variance(mdl)  # Model recompiles, returns NULL with v0.20.3
# Model recompiles
# NULL

get_variance(mdl)  # Returns expected variance components with v0.20.1
# $var.fixed
# [1] 4.90803
# 
# $var.random
# [1] 22.64787
# 
# $var.residual
# [1] 10.82719
# 
# $var.distribution
# [1] 10.82719
# 
# $var.dispersion
# [1] 0
# 
# $var.intercept
# cyl 
# 22.64787 

However, when using a model fitted with lme4::lmer, get_variance() returns the expected output, even in v0.20.3:

library(lme4)
library(insight)

mdl <- lmer(mpg ~ hp + (1 | cyl), data = mtcars)

get_variance(mdl)  # Returns expected variance components with v0.20.1
# $var.fixed
# [1] 4.363142
# 
# $var.random
# [1] 16.18444
# 
# $var.residual
# [1] 9.917004
# 
# $var.distribution
# [1] 9.917004
# 
# $var.dispersion
# [1] 0
# 
# $var.intercept
# cyl 
# 16.18444 
### Tasks