easystats / insight

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

`insight::find_variables()`: error with `brms` and `mm()` #859

Closed vincentarelbundock closed 3 months ago

vincentarelbundock commented 3 months ago

mm() is used for multi-membership grouping terms in brms models. insight::find_variables() sometimes fails with models that include this specification.

Example:

library(brms)
library(insight)

mtcars$w <- 1
fit <- brm(mpg  ~ 1 + hp  + (1|cyl)  +
                (1|carb:am :hp ) +
                (1|mm(carb, am , weights = cbind(w, w), scale=FALSE)) +
                (1|mm(carb:cyl, am :cyl, weights = cbind(w, w), scale=FALSE)),
              data = mtcars, family = gaussian, chains = 4,
              iter = 100, control = list(adapt_delta = 0.99, max_treedepth = 15),
              cores = 4, seed = 12345,
              backend = "cmdstanr")

find_variables(fit)
Error in if (grepl("gr\\((.*)\\)", re)) {: the condition has length > 1
strengejacke commented 3 months ago

Thanks for reporting. If you search for "multimembership", you find some fixme and Todo comments in the code: https://github.com/search?q=repo%3Aeasystats%2Finsight%20membership%20&type=code

This issue could be related to this, in particular since we have weights.

Let me see if it's easy to fix meanwhile.

strengejacke commented 3 months ago
library(insight)
load("c:/Users/DL/Desktop/fit.RData")
find_variables(fit)
#> $response
#> [1] "mpg"
#> 
#> $conditional
#> [1] "hp"
#> 
#> $random
#> [1] "cyl"  "carb" "am"   "hp"   "w"

Created on 2024-03-20 with reprex v2.1.0

sometimes, all.vars() is just magic ;-) Unfortunately, I cannot use it for clean_names() in general, because it splits interaction terms, which is not desired.

vincentarelbundock commented 3 months ago

base R for the win (yet again)!

Thanks!

strengejacke commented 3 months ago

Unfortunately, this issue just missed the recent submission (three or four days ago), so this patch won't be on CRAN very soon.

vincentarelbundock commented 3 months ago

No rush at all. As always, thanks for your great work!

strengejacke commented 3 months ago

(p.s. you don't need to close these issues, they'll be closed automatically once I merge the PR 😉)

strengejacke commented 3 months ago

Managing GitHub completely from VScode is really amazing

vincentarelbundock commented 3 months ago

that's convenient!