Rstan fails to create sampler without much indication why


#1

I have a model that is working on simulated and real data. Today I tried to give the same model a new dataset. Rstan is choking on the new data and failing to create the sampler, but without much indication why.

Here is all I get from the verbose output:

TRANSLATING MODEL 'HP3_Combined05_4occ' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model 'HP3_Combined05_4occ'.

CHECKING DATA AND PREPROCESSING FOR MODEL 'HP3_Combined05_4occ' NOW.

COMPILING MODEL 'HP3_Combined05_4occ' NOW.

STARTING SAMPLER FOR MODEL 'HP3_Combined05_4occ' NOW.
trying deprecated constructor; please alert package maintainer
Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  no valid constructor available for the argument list
failed to create the sampler; sampling not done



sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

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

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

other attached packages:
 [1] bindrcpp_0.2       loo_1.1.0          rstan_2.17.2       StanHeaders_2.17.1 lubridate_1.7.1    magrittr_1.5       forcats_0.2.0     
 [8] stringr_1.2.0      dplyr_0.7.4        purrr_0.2.4        readr_1.1.1        tidyr_0.7.2        tibble_1.4.1       ggplot2_2.2.1     
[15] tidyverse_1.2.1   

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.3   reshape2_1.4.3     haven_1.1.0        lattice_0.20-35    colorspace_1.3-2   stats4_3.4.2       yaml_2.1.16       
 [8] utf8_1.1.2         rlang_0.1.6        pillar_1.0.1       foreign_0.8-69     glue_1.2.0         modelr_0.1.1       readxl_1.0.0      
[15] matrixStats_0.52.2 bindr_0.1          plyr_1.8.4         munsell_0.4.3      gtable_0.2.0       cellranger_1.1.0   rvest_0.3.2       
[22] codetools_0.2-15   psych_1.7.8        labeling_0.3       inline_0.3.14      parallel_3.4.2     broom_0.4.3        Rcpp_0.12.14      
[29] scales_0.5.0       jsonlite_1.5       gridExtra_2.3      mnormt_1.5-5       digest_0.6.13      hms_0.4.0          stringi_1.1.6     
[36] cowplot_0.9.2      grid_3.4.2         cli_1.0.0          tools_3.4.2        lazyeval_0.2.1     crayon_1.3.4       pkgconfig_2.0.1   
[43] xml2_1.1.1         assertthat_0.2.0   httr_1.3.1         rstudioapi_0.7     R6_2.2.2           nlme_3.1-131       compiler_3.4.2  

Output of writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”))):

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function

CXXFLAGS += -Wno-ignored-attributes -Wno-deprecated-declarations

#2

This is smells like a bug. It would be helpful for the library maintainers if you could provide a reproducible example: STAN code + dataset. Thanks!


#3

STARTING SAMPLER FOR MODEL ‘HP3_Combined05_4occ’ NOW.
trying deprecated constructor; please alert package maintainer
Error in new_CppObject_xp(fields$.module, fields$.pointer, …) :
no valid constructor available for the argument list
failed to create the sampler; sampling not done

I had the same problem, unless I figured out a constraint in the data section
of my program was not satisfied. After correcting my data, restarting the
R session and recompiling, the error vanished.

I did not check, if this kind
of error message is specific to all constraints or kind of boundary.
My data was out of bounds. foo[1] = 9, eg.

int<lower=0, upper=8> foo[N];


#4

Definitely a bug. We don’t intend to just quit and not say why!

The issue appears to still be open:


#5

I would like to do that, but this model is something we’re working on with the intent of publishing as a new method. It’s not something we want to let into the wild quite yet.

It is a large multi-state mark-recapture model (think the Cormack-Jolly-Seber model, but much larger) of the where we integrate over unobserved discrete parameters through matrix multiplication.

Making this reproducible with an example that is not my real data would be tricky since I have it working on simulated data and on real data. All that has changed that is causing this error is in trying to supply new data that is much larger than the simulated data or the three cases of real data that I do have working. If I knew what was causing the error I could make a reproducible example that is not my real data, but then I would also know how to fix the problem.

The only thing I can think is that I am passing in lists of matrices that contain data that is used in regression equations within the model. Because we’ve coded the model to be general, these lists can hold any number of matrices, but each matrix in the list must be of the same dimension. I’ve verified the dimensions are the same for each matrix in each list I pass in.


#6

Thank you @andre.pfeuffer! This was the issue. I had a value that exceeded the constraint. I fixed the constraint and now the sampler will start.

Recommendation: when a value exceeds a constraint print out an error message mentioning which data variable it is and what constraint is exceeded.