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

Infinite loop in icc() for some brms models #905

Closed bwiernik closed 4 months ago

bwiernik commented 4 months ago
a <- seq(from = 0, to = 30)
b1 <- rbeta(length(a), 3, 1)
b2 <- rbeta(length(a), 3, 1)

d <- data.frame(id = c(a,a),
                value = c(b1, b2))

mod_bayes <- suppressMessages(suppressWarnings(brms::brm(value ~ 1 + (1 | id),
                 data = d,
                 family = brms::Beta)))

icc(mod_bayes)

The sequence of internal function to compute distribution and residual variance loops back into .compute_variances() seemingly endlessly. (Maybe not endlessly, but we are re-estimating the same updated models to get "null" models and "sigma" variance many many times as the functions loop back through the parent compute_variances() function.) We should adjust this function to ensure we only resample each updated model 1 time.

bwiernik commented 4 months ago

One possible quick fix here would be to pass already-computed distributions as a list to each internal all, so that we re-estimate them only conditionally

strengejacke commented 4 months ago

Where is the model refit multiple times? I think, the null-model is only computed once and pass as argument inside .compute_variances() (at least for the latest insight version).

bwiernik commented 4 months ago

Did you try running the example? When it starts to compute .variance_distributional(), get_sigma() drops it back into the a new iteration of compute_variance(), which computes the null model again. I stopped the function, but it refits something at least 30 times before I stopped it.

bwiernik commented 4 months ago

Thanks!