stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
138 stars 44 forks source link

[BUG] Reporting example where new compiler failed #1370

Closed sj-perry closed 8 months ago

sj-perry commented 8 months ago

I was running a model that I was fitting for teaching purposes when I got the message quoted below. I've pasted the code that generated the data together with the model call in brms that produced the error:

When you compile models, you are also contributing to development of the NEXT Stan compiler. In this version of rstan, we compile your model as usual, but also test our new compiler on your syntactically correct model. In this case, the new compiler did not work like we hoped. By filing an issue at https://github.com/stan-dev/stanc3/issues with your model or a minimal example that shows this warning you will be contributing valuable information to Stan and ensuring your models continue working. Thank you!

library(fabricatr)

set.seed(20231012)
d <- fabricate(
  PartID = add_level(N = 30, 
                     age_yrs = round(runif(N, min = 18, max = 40)),
                     age_of_onset = round(age_yrs - (1+rexp(N, rate = 0.6))),
                     part_offset = round(rnorm(N, 0, 1), digits = 2)),
  ItemID = add_level(N = 100, 
                     log_frequency = round(runif(N, 1, 6), digits = 1),
                     item_offset = round(rnorm(N, 0, 0.6), digits = 2),
                     nest = FALSE),
  obs = cross_levels(
    by = join_using(PartID, ItemID)
  )
)

d$LOE <- d$age_yrs-d$age_of_onset

Int <- 0.75
d$ACC <- rbinom(3000, 1, plogis(Int + 0.3*d$LOE + 0.4*d$log_frequency + d$item_offset + d$part_offset))

When I fit the following model, it works in the current version of brms, but throws the message above:

library(brms)
fit<- brm(ACC ~ LOE * log_frequency + (1|PartID) + (1|ItemID),
             data = d,
             family = bernoulli(),
             prior = c(
               prior(normal(0, 1.5), class = "Intercept"),
               prior(normal(0, 1), class = "b"),
               prior(exponential(1), class = "sd")
             ))
sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252    LC_MONETARY=English_Canada.1252
[4] LC_NUMERIC=C                    LC_TIME=English_Canada.1252    

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

other attached packages:
[1] brms_2.18.0     Rcpp_1.0.10     sjPlot_2.8.14   lme4_1.1-29     Matrix_1.5-3    fabricatr_1.0.0

loaded via a namespace (and not attached):
  [1] TH.data_1.0-10       minqa_1.2.4          colorspace_2.0-2     ellipsis_0.3.2       ggridges_0.5.3      
  [6] rsconnect_0.8.24     sjlabelled_1.1.8     estimability_1.3     snakecase_0.11.0     markdown_1.1        
 [11] parameters_0.14.0    base64enc_0.1-3      rstudioapi_0.13      rstan_2.21.2         farver_2.1.0        
 [16] DT_0.19              fansi_0.5.0          mvtnorm_1.1-2        bridgesampling_1.1-2 codetools_0.2-18    
 [21] splines_4.1.1        knitr_1.39           shinythemes_1.2.0    sjmisc_2.8.7         projpred_2.0.2      
 [26] bayesplot_1.8.1      jsonlite_1.7.2       nloptr_1.2.2.2       ggeffects_1.1.1      broom_1.0.3         
 [31] effectsize_0.4.5     shiny_1.6.0          compiler_4.1.1       sjstats_0.18.1       emmeans_1.6.3       
 [36] backports_1.2.1      fastmap_1.1.0        cli_3.6.1            later_1.3.0          prettyunits_1.1.1   
 [41] htmltools_0.5.2      tools_4.1.1          igraph_1.2.6         coda_0.19-4          gtable_0.3.0        
 [46] glue_1.6.2           reshape2_1.4.4       dplyr_1.1.2          posterior_1.2.1      V8_3.4.2            
 [51] vctrs_0.6.3          nlme_3.1-152         crosstalk_1.1.1      insight_0.19.1       tensorA_0.36.2      
 [56] xfun_0.31            stringr_1.5.0        ps_1.6.0             mime_0.11            miniUI_0.1.1.1      
 [61] lifecycle_1.0.3      gtools_3.9.2         MASS_7.3-54          zoo_1.8-9            scales_1.2.1        
 [66] colourpicker_1.1.0   promises_1.2.0.1     Brobdingnag_1.2-6    parallel_4.1.1       sandwich_3.0-1      
 [71] inline_0.3.19        shinystan_2.5.0      RColorBrewer_1.1-2   gamm4_0.2-6          curl_4.3.2          
 [76] gridExtra_2.3        ggplot2_3.4.1        StanHeaders_2.21.0-7 loo_2.4.1            stringi_1.6.2       
 [81] bayestestR_0.11.0    dygraphs_1.1.1.6     checkmate_2.0.0      pkgbuild_1.2.0       boot_1.3-28         
 [86] rlang_1.1.1          pkgconfig_2.0.3      matrixStats_0.60.1   distributional_0.2.2 lattice_0.20-44     
 [91] purrr_1.0.2          rstantools_2.1.1     htmlwidgets_1.5.3    labeling_0.4.2       processx_3.5.2      
 [96] tidyselect_1.2.0     plyr_1.8.6           magrittr_2.0.3       R6_2.5.1             generics_0.1.0      
[101] multcomp_1.4-17      mgcv_1.8-36          pillar_1.9.0         withr_2.5.0          xts_0.12.1          
[106] survival_3.2-11      datawizard_0.2.0.1   abind_1.4-5          tibble_3.2.1         performance_0.7.3   
[111] crayon_1.4.1         modelr_0.1.8         utf8_1.2.2           grid_4.1.1           callr_3.7.0         
[116] threejs_0.3.3        digest_0.6.27        xtable_1.8-4         tidyr_1.3.0          httpuv_1.6.2        
[121] RcppParallel_5.1.4   stats4_4.1.1         munsell_0.5.0        shinyjs_2.0.0     
andrjohns commented 8 months ago

Your versions of R and RStan are out of date, once you update you will no longer see this