insight icon indicating copy to clipboard operation
insight copied to clipboard

Issue with get_variance() handling of intercept-only sigma model in brms

Open matschmitz opened this issue 1 year ago • 0 comments

It appears that get_variance() in insight (v0.99.0.13) doesn’t handle brms models with an intercept-only sigma term correctly. When comparing models with and without sigma, the expected residual variance (var.residual) and distribution variance (var.distribution) should match, as both models are essentially equivalent. However, the results differ.

library(brms)
library(insight)

# Model without sigma
mdl1 <- brm(mpg ~ hp + (1 | cyl), data = mtcars, seed = 123)
get_variance(mdl1)
# Output:
# $var.fixed
# [1] 4.911032
# $var.random
# [1] 22.40697
# $var.residual
# [1] 10.93045
# $var.distribution
# [1] 10.93045

# Model with intercept-only sigma
mdl2 <- brm(bf(mpg ~ hp + (1 | cyl), sigma ~ 1), data = mtcars, seed = 123)
get_variance(mdl2)
# Output:
# $var.fixed
# [1] 4.910691
# $var.random
# [1] 23.4812
# $var.residual
# [1] 1
# $var.distribution
# [1] 1

matschmitz avatar Nov 12 '24 10:11 matschmitz