New user struggling to get rstanarm running

Hello! I’m new to rstanarm, and even simple calls to stan_glm are failing with somewhat cryptic errors. For example, if I call the first example in the stan_glm vignette:

mtcars$mpg10 <- mtcars$mpg / 10
fit <- stan_glm(
  mpg10 ~ wt + cyl + am,            
  data = mtcars, 
  QR = TRUE,
  # for speed of example only (default is "sampling")
  algorithm = "fullrank",
  refresh = 0 
 ) 

I get the error:

Error in sampler$call_sampler(c(args, dotlist)) : 
  empty_nested() must be true before calling recover_memory()

Given that this fails, it’s not surprising that I also get errors trying to fit a simple hierarchical model on the Gelman and Hill radon data:

> hierbayes <- stan_lmer(log_radon ~  floor + (1|county), data=radon, 
                        prior = normal(), prior_intercept = normal())

SAMPLING FOR MODEL 'continuous' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000212 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 2.12 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] "  c++ exception (unknown reason)"                
error occurred during calling the sampler; sampling not done
Error in check_stanfit(stanfit) : 
  Invalid stanfit object produced please report bug
Error in dimnamesGets(x, value) : 
  invalid dimnames given for “dgCMatrix” object

Does anyone have any idea what’s going on? Nothing seems to be working for me.

  • Operating System: Mac OSX 10.15.3
  • rstanarm Version: 2.19.2
1 Like

You have a Catalina problem. If you have not done so already, follow

and then to install the C++ toolchain and then in a fresh R session do

install.packages("rstanarm", type = "source")

Thanks for your response!

Unfortunately, after installing the C++ toolchain and attempting to install rstanarm in a fresh session, compilation failed reading the math.h header:

In file included from /usr/local/clang7/include/c++/v1/cmath:305:
**/usr/local/clang7/include/c++/v1/math.h:301:15:** **fatal error:** **'math.h' file not found**
#include_next <math.h>
**^~~~~~~~**

1 error generated.
make: *** [stan_files/bernoulli.o] Error 1
rm stan_files/bernoulli.cc
ERROR: compilation failed for package ‘rstanarm’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rstanarm’
* restoring previous
‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rstanarm’

As the error suggests, there is a file at /usr/local/clang7/include/c++/v1/math.h that attempts to include another file called math.h on line 301.

Are there more include flags I need to add to my ~/.R/Makevars? Running the c++ toolchain modified the Makevars, so I hoped it would point to all the directories it needs for compilation.

Yeah, it fails in different ways for different people somehow. Try executing

xcode-select --install

in the Terminal application or the Terminal emulation Window of RStudio.

Ah, that did the trick, thank you!