stan-dev / projpred

Projection predictive variable selection
https://mc-stan.org/projpred/
Other
110 stars 26 forks source link

Incompatible with brms when random effects are specified with || syntax #436

Closed hrlai closed 1 year ago

hrlai commented 1 year ago

Hi there dev, cv_varsel fails when the brms model has random group effects that are specified in the (1 || group) format. For example:

library(brms)
library(projpred)

data("df_gaussian", package = "projpred")
dat_gauss <- data.frame(y = df_gaussian$y, df_gaussian$x)
# generate groups
dat_gauss$grp <- rep(1:10, each = 10)

refm_fit <- brm(
    y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + X11 + X12 + X13 + X14 +
        X15 + X16 + X17 + X18 + X19 + X20 +
        (1 || grp),
    family = gaussian(),
    data = dat_gauss,
    ### Only for the sake of speed (not recommended in general):
    chains = 2, iter = 1000
)

cvvs_fast <- cv_varsel(
    refm_fit,
    validate_search = FALSE,
    nterms_max = 10
)

returns the following error:

Error in FUN(X[[i]], ...) : 
  Unexpected number of `|` characters in group terms. Please contact the package maintainer.

Is this something that can be generalised in projpred? I hope so because sometimes we want to do without the random covariance when the model becomes a bit too complex. Thanks!

hrlai commented 1 year ago

Opps sorry this is a duplicate of #435. I'm going to close it to avoid extra work on your side, but will hope that this gets implemented in the near future :)

fweber144 commented 1 year ago

No problem :)