I cannot seem to make varsel() work from brms

Hi,

I am trying to reproduce the example on how to use varsel and cv_varsel(), and it does not seem to work on my end. I was not sure if this was a bug or I am missing something, so I am posting here before creating an issue on Github. Thank you for your input!

I used the following example in my Rconsole (Projection Predictive Variable Selection — varsel.brmsfit • brms) but the I got the following error message.

fit <- brm(count ~ zAge + zBase * Trt,
           data = epilepsy, family = poisson())
summary(fit)

# perform variable selection without cross-validation
vs <- varsel(fit)
summary(vs)
plot(vs)

# perform variable selection with cross-validation
cv_vs <- cv_varsel(fit)
summary(cv_vs)
plot(cv_vs)

Error in init_refmodel(object = object, formula = formula, family = family, :
argument "formula" is missing, with no default
6.
stopifnot(inherits(formula, "formula"))
5.
init_refmodel(object = object, formula = formula, family = family,
extract_model_data = extract_model_data, ...)
4.
get_refmodel.default(object, ...)
3.
get_refmodel(object, ...)
2.
varsel.default(fit)
1.
varsel(fit)

I tried to supply formula, data, and other things, but it keeps me asking more things that I do not know where it comes from.

session info

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.6.2

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] projpred_2.4.0      broom.mixed_0.2.9.4 ggbeeswarm_0.7.1    gghalves_0.1.3      ggokabeito_0.1.0    patchwork_1.1.2    
 [7] tidybayes_3.0.3     bayesplot_1.10.0    brms_2.18.1         Rcpp_1.0.9          lmerTest_3.1-3      lme4_1.1-30        
[13] Matrix_1.5-1        ggrain_0.0.2        GGally_2.1.2        psych_2.2.9         here_1.0.1          forcats_0.5.2      
[19] stringr_1.5.0       dplyr_1.1.0         purrr_1.0.1         readr_2.1.3         tidyr_1.3.0         tibble_3.1.8       
[25] ggplot2_3.4.1       tidyverse_1.3.2    

loaded via a namespace (and not attached):
  [1] utf8_1.2.3             tidyselect_1.2.0       htmlwidgets_1.5.4      grid_4.1.2             munsell_0.5.0         
  [6] codetools_0.2-18       effectsize_0.7.0.5     DT_0.25                future_1.28.0          miniUI_0.1.1.1        
 [11] withr_2.5.0            Brobdingnag_1.2-9      colorspace_2.1-0       knitr_1.40             rstudioapi_0.14       
 [16] stats4_4.1.2           listenv_0.8.0          labeling_0.4.2         emmeans_1.8.1-1        rstan_2.26.13         
 [21] mnormt_2.1.1           bit64_4.0.5            farver_2.1.1           datawizard_0.6.1       bridgesampling_1.1-2  
 [26] rprojroot_2.0.3        parallelly_1.32.1      coda_0.19-4            vctrs_0.5.2            generics_0.1.3        
 [31] TH.data_1.1-1          xfun_0.33              R6_2.5.1               markdown_1.1           gamm4_0.2-6           
 [36] reshape_0.8.9          assertthat_0.2.1       vroom_1.6.0            promises_1.2.0.1       scales_1.2.1          
 [41] multcomp_1.4-20        googlesheets4_1.0.1    beeswarm_0.4.0         gtable_0.3.1           globals_0.16.1        
 [46] processx_3.7.0         sandwich_3.0-2         rlang_1.0.6            zeallot_0.1.0          sjPlot_2.8.12         
 [51] splines_4.1.2          gargle_1.2.1           broom_1.0.1            checkmate_2.1.0        inline_0.3.19         
 [56] yaml_2.3.6             reshape2_1.4.4         abind_1.4-5            modelr_0.1.9           threejs_0.3.3         
 [61] crosstalk_1.2.0        backports_1.4.1        httpuv_1.6.6           tensorA_0.36.2         tools_4.1.2           
 [66] ICC_2.4.0              ellipsis_0.3.2         posterior_1.3.1        RColorBrewer_1.1-3     plyr_1.8.7            
 [71] base64enc_0.1-3        ps_1.7.1               prettyunits_1.1.1      correlation_0.8.2      zoo_1.8-11            
 [76] haven_2.5.1            fs_1.5.2               furrr_0.3.1            magrittr_2.0.3         data.table_1.14.4     
 [81] ggdist_3.2.0           colourpicker_1.1.1     reprex_2.0.2           googledrive_2.0.0      mvtnorm_1.1-3         
 [86] sjmisc_2.8.9           matrixStats_0.62.0     hms_1.1.2              shinyjs_2.1.0          mime_0.12             
 [91] evaluate_0.16          arrayhelpers_1.1-0     xtable_1.8-4           shinystan_2.6.0        sjstats_0.18.1        
 [96] readxl_1.4.1           gridExtra_2.3          ggeffects_1.1.3        rstantools_2.2.0       compiler_4.1.2        
[101] ggstatsplot_0.9.4      V8_4.2.1               crayon_1.5.2           minqa_1.2.4            StanHeaders_2.26.13   
[106] htmltools_0.5.3        mgcv_1.8-40            later_1.3.0            tzdb_0.3.0             RcppParallel_5.1.5    
[111] lubridate_1.8.0        DBI_1.1.3              sjlabelled_1.2.0       dbplyr_2.2.1           MASS_7.3-58.1         
[116] boot_1.3-28            cli_3.6.0              parallel_4.1.2         insight_0.19.0         igraph_1.3.5          
[121] pkgconfig_2.0.3        statsExpressions_1.3.3 numDeriv_2016.8-1.1    xml2_1.3.3             paletteer_1.4.1       
[126] svUnit_1.0.6           dygraphs_1.1.1.6       vipor_0.4.5            estimability_1.4.1     ggpp_0.5.1            
[131] rvest_1.0.3            distributional_0.3.1   callr_3.7.2            digest_0.6.30          parameters_0.18.2     
[136] rmarkdown_2.16         cellranger_1.1.0       curl_4.3.3             shiny_1.7.2            gtools_3.9.3          
[141] nloptr_2.0.3           lifecycle_1.0.3.9000   nlme_3.1-159           jsonlite_1.8.2         cmdstanr_0.5.3        
[146] fansi_1.0.4            pillar_1.8.1           lattice_0.20-45        loo_2.5.1              fastmap_1.1.0         
[151] httr_1.4.4             pkgbuild_1.3.1         survival_3.4-0         glue_1.6.2             xts_0.12.2            
[156] bayestestR_0.13.0      shinythemes_1.2.0      bit_4.0.4              stringi_1.7.12         performance_0.9.2     
[161] rematch2_2.1.2     

Hi, thanks for the report. Do you call library(projpred) before the projpred-related code? If yes, could you try it with the CRAN version of brms?

Hello, thank you so much for the instruction. I already closed the session that time, so I reopened it and tried it again. It worked without changing the version brms.
Thank you for your help!

1 Like