Help interpreting zero inflated poisson model error

I’m looking for some insight on what may be causing this error when fitting a zero inflated poisson model. This is a model I have run successfully in the past, but I just introduced a single row of data that is now triggering the error. The values for this new data point are on the edge of some of the predictor distributions but still within the same order of magnitude of the other values in the dataset.

The dataset is not publicly available, but I can share it directly to someone, if helpful.

formula <- bf(n_amr_events ~ ln_livestock_consumption_kg_per_capita * ln_gdp_per_capita +
                     ln_migrant_pop_per_capita + ln_tourism_inbound_per_capita + 
                     ln_ab_export_per_capita + health_expend_perc + human_consumption_ddd + english_spoken +
                     ln_pubcrawl_per_capita + ln_promed_mentions_per_capita  + offset(ln_population),
                   zi ~ ln_pubcrawl_per_capita + ln_promed_mentions_per_capita  + ln_gdp_per_capita + ln_population + english_spoken)
brm(formula, data = amr, family = zero_inflated_poisson(), prior = set_prior("student_t(3,0,10)", class = "b"))

Compiling Stan program...
make cmd is
  make -f '/usr/local/lib/R/etc/Makeconf' -f '/usr/local/lib/R/etc/Makevars.site' -f '/usr/local/lib/R/share/make/shlib.mk' -f '/home/emmamendelsohn/.R/Makevars' CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB='file1a4aa146a8ed1.so' OBJECTS='file1a4aa146a8ed1.o'

make would use
g++ -std=gnu++14 -I"/usr/local/lib/R/include" -DNDEBUG   -I"/home/emmamendelsohn/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include/"  -I"/home/emmamendelsohn/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/"  -I"/home/emmamendelsohn/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/unsupported"  -I"/usr/local/lib/R/site-library/BH/include" -I"/usr/local/lib/R/site-library/StanHeaders/include/src/"  -I"/usr/local/lib/R/site-library/StanHeaders/include/"  -I"/usr/local/lib/R/site-library/RcppParallel/include/"  -I"/usr/local/lib/R/site-library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fpic  -O3 -march=native -mtune=native -fPIC -DSTAN_THREADS -pthread -c file1a4aa146a8ed1.cpp -o file1a4aa146a8ed1.o
if test  "zfile1a4aa146a8ed1.o" != "z"; then \
  echo  g++ -std=gnu++14 -shared -L"/usr/local/lib/R/lib" -L/usr/local/lib -o file1a4aa146a8ed1.so file1a4aa146a8ed1.o  '/usr/local/lib/R/site-library/rstan/lib//libStanServices.a' -L'/usr/local/lib/R/site-library/StanHeaders/lib/' -lStanHeaders -L'/usr/local/lib/R/site-library/RcppParallel/lib/' -ltbb  -L"/usr/local/lib/R/lib" -lR; \
   g++ -std=gnu++14 -shared -L"/usr/local/lib/R/lib" -L/usr/local/lib -o file1a4aa146a8ed1.so file1a4aa146a8ed1.o  '/usr/local/lib/R/site-library/rstan/lib//libStanServices.a' -L'/usr/local/lib/R/site-library/StanHeaders/lib/' -lStanHeaders -L'/usr/local/lib/R/site-library/RcppParallel/lib/' -ltbb  -L"/usr/local/lib/R/lib" -lR; \
fi
Error in compileCode(f, code, language = language, verbose = verbose) : 
  /usr/local/lib/R/site-library/StanHeaders/include/stan/math/rev/mat/fun/multiply.hpp:629:9:   required from ‘Eigen::Matrix<stan::math::var, Ra, Cb> stan::math::multiply(const Eigen::Matrix<T, R, C>&, const Eigen::Matrix<Tb, Ca, Cb>&) [with Ta = double; int Ra = -1; int Ca = -1; Tb = stan::math::var; int Cb = 1; <template-parameter-1-6> = void]’file1a4aa146a8ed1.cpp:680:66:   required from ‘T__ model1a4aa34f48aa6_5cbb13ae0fbe3a5b622c79602acdc5c8_namespace::model1a4aa34f48aa6_5cbb13ae0fbe3a5b622c79602acdc5c8::log_prob(std::vector<T_l>&, std::vector<int>&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T__ = stan::math::var; std::ostream = std::basic_ostream<char>]’/usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/model_base_crtp.hpp:153:29:   required from ‘stan::math::var stan::model::model_base_crtp<M>::log_prob(std::vector<stan::math::var>&, std::vector<int>&, std::ostream*) const [with M = model1a4aa34f48aa6_5cbb13ae0fbe3
Error in sink(type = "output") : invalid connection
Backtrace:
  1. brms::brm(...)
  2. brms::do_call(compile_model, compile_args)
  3. brms:::eval2(call, envir = args, enclos = parent.frame())
  4. [ base::eval(...) ] with 1 more call
  6. brms:::.fun(model = .x1, backend = .x2, threads = .x3)
     ...
  9. brms:::eval2(call, envir = args, enclos = parent.frame())
 10. [ base::eval(...) ] with 1 more call
 12. rstan:::.fun(model_code = .x1)
 13. rstan:::cxxfunctionplus(...)
 14. base::sink(type = "output")

Please let me know if there’s any other information I can provide. Thank you!

─ Session info ─

setting value
version R version 4.0.2 (2020-06-22)
os Ubuntu 20.04.1 LTS
system x86_64, linux-gnu
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Etc/UTC
date 2021-02-11

─ Packages ─

package * version date lib source
abind 1.4-5 2016-07-21 [2] RSPM (R 4.0.0)
assertthat 0.2.1 2019-03-21 [2] RSPM (R 4.0.0)
backports 1.1.9 2020-08-24 [1] RSPM (R 4.0.2)
base64enc 0.1-3 2015-07-28 [2] RSPM (R 4.0.0)
base64url 1.4 2018-05-14 [1] RSPM (R 4.0.0)
bayesplot 1.7.2 2020-05-28 [2] RSPM (R 4.0.0)
blob 1.2.1 2020-01-20 [2] RSPM (R 4.0.0)
boot 1.3-25 2020-04-26 [3] CRAN (R 4.0.2)
bridgesampling 1.0-0 2020-02-26 [2] RSPM (R 4.0.0)
brms * 2.14.4 2020-11-03 [1] RSPM (R 4.0.3)
Brobdingnag 1.2-6 2018-08-13 [2] RSPM (R 4.0.0)
broom 0.7.3 2020-12-16 [1] RSPM (R 4.0.3)
callr 3.4.4 2020-09-07 [1] RSPM (R 4.0.2)
cellranger 1.1.0 2016-07-27 [2] RSPM (R 4.0.0)
cli 2.2.0 2020-11-20 [1] RSPM (R 4.0.3)
coda 0.19-4 2020-09-30 [2] RSPM (R 4.0.2)
codetools 0.2-16 2018-12-24 [3] CRAN (R 4.0.2)
colorspace 1.4-1 2019-03-18 [2] RSPM (R 4.0.0)
colourpicker 1.1.0 2020-09-14 [2] RSPM (R 4.0.2)
crayon 1.3.4 2017-09-16 [2] RSPM (R 4.0.0)
crosstalk 1.1.0.1 2020-03-13 [2] RSPM (R 4.0.0)
curl 4.3 2019-12-02 [2] RSPM (R 4.0.0)
DBI 1.1.0 2019-12-15 [2] RSPM (R 4.0.0)
dbplyr 1.4.4 2020-05-27 [2] RSPM (R 4.0.0)
digest 0.6.27 2020-10-24 [1] RSPM (R 4.0.3)
dplyr * 1.0.2 2020-08-18 [1] RSPM (R 4.0.2)
drake 7.12.4 2020-06-29 [1] RSPM (R 4.0.2)
DT 0.15 2020-08-05 [1] RSPM (R 4.0.2)
dygraphs 1.1.1.6 2018-07-11 [2] RSPM (R 4.0.0)
ellipsis 0.3.1 2020-05-15 [2] RSPM (R 4.0.0)
emmeans 1.4.8 2020-06-26 [1] RSPM (R 4.0.2)
estimability 1.3 2018-02-11 [1] RSPM (R 4.0.0)
fansi 0.4.1 2020-01-08 [2] RSPM (R 4.0.0)
farver 2.0.3 2020-01-16 [2] RSPM (R 4.0.0)
fastmap 1.0.1 2019-10-08 [2] RSPM (R 4.0.0)
filelock 1.0.2 2018-10-05 [1] RSPM (R 4.0.0)
forcats * 0.5.0 2020-03-01 [2] RSPM (R 4.0.0)
fs 1.5.0 2020-07-31 [1] RSPM (R 4.0.2)
furrr 0.1.0 2018-05-16 [2] RSPM (R 4.0.0)
future 1.19.1 2020-09-22 [2] RSPM (R 4.0.2)
gamm4 0.2-6 2020-04-03 [1] RSPM (R 4.0.0)
generics 0.1.0 2020-10-31 [1] RSPM (R 4.0.3)
ggplot2 * 3.3.2 2020-06-19 [2] RSPM (R 4.0.1)
ggridges 0.5.2 2020-01-12 [2] RSPM (R 4.0.0)
globals 0.14.0 2020-11-22 [1] RSPM (R 4.0.3)
glue 1.4.2 2020-08-27 [1] RSPM (R 4.0.2)
gridExtra 2.3 2017-09-09 [2] RSPM (R 4.0.0)
gtable 0.3.0 2019-03-25 [2] RSPM (R 4.0.0)
gtools 3.8.2 2020-03-31 [2] RSPM (R 4.0.0)
haven 2.3.1 2020-06-01 [2] RSPM (R 4.0.2)
hms 0.5.3 2020-01-08 [2] RSPM (R 4.0.0)
htmltools 0.5.0 2020-06-16 [2] RSPM (R 4.0.1)
htmlwidgets 1.5.2 2020-10-03 [2] RSPM (R 4.0.2)
httpuv 1.5.4 2020-06-06 [2] RSPM (R 4.0.2)
httr 1.4.2 2020-07-20 [2] RSPM (R 4.0.2)
igraph 1.2.6 2020-10-06 [2] RSPM (R 4.0.2)
inline 0.3.16 2020-09-06 [2] RSPM (R 4.0.2)
jsonlite 1.7.1 2020-09-07 [1] RSPM (R 4.0.2)
labeling 0.3 2014-08-23 [2] RSPM (R 4.0.0)
later 1.1.0.1 2020-06-05 [2] RSPM (R 4.0.2)
lattice 0.20-41 2020-04-02 [3] CRAN (R 4.0.2)
lifecycle 0.2.0 2020-03-06 [2] RSPM (R 4.0.0)
listenv 0.8.0 2019-12-05 [2] RSPM (R 4.0.0)
lme4 1.1-26 2020-12-01 [1] RSPM (R 4.0.3)
loo 2.3.1 2020-07-14 [2] RSPM (R 4.0.2)
lubridate 1.7.9 2020-06-08 [1] CRAN (R 4.0.2)
magrittr 2.0.1 2020-11-17 [1] RSPM (R 4.0.3)
markdown 1.1 2019-08-07 [2] RSPM (R 4.0.0)
MASS 7.3-51.6 2020-04-26 [3] CRAN (R 4.0.2)
Matrix 1.2-18 2019-11-27 [3] CRAN (R 4.0.2)
matrixStats 0.57.0 2020-09-25 [2] RSPM (R 4.0.2)
mgcv 1.8-31 2019-11-09 [3] CRAN (R 4.0.2)
mice 3.9.0 2020-05-14 [1] RSPM (R 4.0.0)
mime 0.9 2020-02-04 [2] RSPM (R 4.0.0)
miniUI 0.1.1.1 2018-05-18 [2] RSPM (R 4.0.0)
minqa 1.2.4 2014-10-09 [2] RSPM (R 4.0.2)
modelr 0.1.8 2020-05-19 [2] RSPM (R 4.0.0)
munsell 0.5.0 2018-06-12 [2] RSPM (R 4.0.0)
mvtnorm 1.1-1 2020-06-09 [2] RSPM (R 4.0.0)
nlme 3.1-148 2020-05-24 [3] CRAN (R 4.0.2)
nloptr 1.2.2.2 2020-07-02 [1] RSPM (R 4.0.2)
pillar 1.4.7 2020-11-20 [1] RSPM (R 4.0.3)
pkgbuild 1.1.0 2020-07-13 [2] RSPM (R 4.0.2)
pkgconfig 2.0.3 2019-09-22 [2] RSPM (R 4.0.0)
plyr 1.8.6 2020-03-03 [2] RSPM (R 4.0.2)
prettyunits 1.1.1 2020-01-24 [2] RSPM (R 4.0.0)
processx 3.4.4 2020-09-03 [1] RSPM (R 4.0.2)
progress 1.2.2 2019-05-16 [2] RSPM (R 4.0.0)
projpred 2.0.2 2020-10-28 [1] RSPM (R 4.0.3)
promises 1.1.1 2020-06-09 [2] RSPM (R 4.0.2)
ps 1.3.4 2020-08-11 [1] RSPM (R 4.0.2)
purrr * 0.3.4 2020-04-17 [2] RSPM (R 4.0.0)
R6 2.5.0 2020-10-28 [1] RSPM (R 4.0.3)
Rcpp * 1.0.5 2020-07-06 [1] CRAN (R 4.0.2)
RcppParallel 5.0.2 2020-06-24 [2] RSPM (R 4.0.2)
readr * 1.4.0 2020-10-05 [2] RSPM (R 4.0.2)
readxl 1.3.1 2019-03-13 [2] RSPM (R 4.0.2)
reprex 0.3.0 2019-05-16 [2] RSPM (R 4.0.0)
reshape2 1.4.4 2020-04-09 [2] RSPM (R 4.0.2)
RhpcBLASctl * 0.20-137 2020-05-17 [1] RSPM (R 4.0.0)
rlang 0.4.10 2020-12-30 [1] RSPM (R 4.0.3)
rsconnect 0.8.16 2019-12-13 [2] RSPM (R 4.0.0)
rstan 2.21.2 2020-07-27 [2] RSPM (R 4.0.2)
rstantools 2.1.1 2020-07-06 [2] RSPM (R 4.0.2)
rstudioapi 0.13 2020-11-12 [1] RSPM (R 4.0.3)
rvest 0.3.6 2020-07-25 [2] RSPM (R 4.0.2)
scales 1.1.1 2020-05-11 [2] RSPM (R 4.0.0)
sessioninfo 1.1.1 2018-11-05 [2] RSPM (R 4.0.0)
shiny 1.5.0 2020-06-23 [2] RSPM (R 4.0.2)
shinyjs 2.0.0 2020-09-09 [2] RSPM (R 4.0.2)
shinystan 2.5.0 2018-05-01 [2] RSPM (R 4.0.0)
shinythemes 1.1.2 2018-11-06 [2] RSPM (R 4.0.0)
StanHeaders 2.21.0-6 2020-08-16 [2] RSPM (R 4.0.2)
statmod 1.4.35 2020-10-19 [1] RSPM (R 4.0.3)
storr 1.2.1 2018-10-18 [1] CRAN (R 4.0.2)
stringi 1.5.3 2020-09-09 [1] RSPM (R 4.0.2)
stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
threejs 0.3.3 2020-01-21 [2] RSPM (R 4.0.0)
tibble * 3.0.4 2020-10-12 [1] RSPM (R 4.0.2)
tidyr * 1.1.2 2020-08-27 [1] RSPM (R 4.0.2)
tidyselect 1.1.0 2020-05-11 [2] RSPM (R 4.0.0)
tidyverse * 1.3.0 2019-11-21 [2] RSPM (R 4.0.0)
txtq 0.2.3 2020-06-23 [1] RSPM (R 4.0.2)
unixtools 0.1-1 2020-10-08 [2] Github (s-u/unixtools@ba71937)
V8 3.2.0 2020-06-19 [2] RSPM (R 4.0.2)
vctrs 0.3.6 2020-12-17 [1] RSPM (R 4.0.3)
withr 2.3.0 2020-09-22 [2] RSPM (R 4.0.2)
xml2 1.3.2 2020-04-23 [2] RSPM (R 4.0.0)
xtable 1.8-4 2019-04-21 [2] RSPM (R 4.0.0)
xts 0.12.1 2020-09-09 [2] RSPM (R 4.0.2)
zoo 1.8-8 2020-05-02 [2] RSPM (R 4.0.0)

[1] /home/emmamendelsohn/R/x86_64-pc-linux-gnu-library/4.0
[2] /usr/local/lib/R/site-library
[3] /usr/local/lib/R/library

Does the model still run without that row of data added? Or possibly remove some data (or perhaps a predictor) and try again?

This looks like some sort of C++ error:

 /usr/local/lib/R/site-library/StanHeaders/include/stan/math/rev/mat/fun/multiply.hpp:629:9:
required from ‘Eigen::Matrix<stan::math::var, Ra, Cb>
stan::math::multiply(const Eigen::Matrix<T, R, C>&, const Eigen::Matrix<Tb, Ca, Cb>&)
[with Ta = double; int Ra = -1; int Ca = -1;
Tb = stan::math::var; int Cb = 1; <template-parameter-1-6> = void]
...

I think these are mostly issues with the compiler toolchain, but first I’m curious if the old model still runs/removing data causes a failure.

Thanks for your reply @bbbales2. Interestingly, the errors seems to be somewhat version dependent. With the current CRAN brms (2.14.4), the model fails with and without the new row of data. It also fails when I remove a couple of the predictors. With version 2.13.5, which I had been using up until making this post, it fails with the new row of data included, but runs as expected without the new data.

Ooo, that is interesting. Can you generate some fake data and reproduce with that? That will make it much easier to figure out what is going on since you can’t share the data you have.

With the new install, is there a condition where it works?

Did you recently upgrade to R 4.0 by any chance? There’s been a lot of clearing out old R Makevars settings the last few months. Do you have an ~/R/Makevars and if so what is in it?

Turns out I needed to update to the latest rstan version, and things are running smoothly again. Thanks so much for your help @bbbales2!

1 Like