Stan_gamm4 with random effect throws c++ exception and does not contain samples

Hey all,

When I add a varying intercept to stan_gamm4, suddenly "Error in sampler$call_sampler(args_list[[i]]) : " [2] " c++ exception (unknown reason)" and Stan model 'continuous' does not contain samples.

Here’s some code to reproduce the problem on my machine (I’m aware this model doesn’t answer a real-world problem–I’m just trying to demonstrate the issue with minimal code).

library(tidyverse)
library(rstanarm)

data <- read_csv("https://projects.fivethirtyeight.com/polls-page/president_polls.csv")

#convert date to a numeric variable 
data$julian <- scale(julian(as.Date(data$end_date, format = "%m/%d/%y")))

fit <- stan_gamm4(pct ~ s(julian), random=~(1|pollster), data=data)

Even in the same R session, the model runs fine when I drop the random effect, and the brms equivalent of the model runs fine as well:

# This runs (with 1 divergent transition)
fit <- stan_gamm4(pct ~ s(julian), data=data)

# This runs too (with 82 divergent transitions)
library(brms)
fit <- brm(pct ~ s(julian) + (1|pollster), data=data)

So I wonder if this is a bug with rstanarm? I’d appreciate any trouble-shooting advice you can give.

  • Operating System: OS Catalina 10.15.3
  • rstanarm Version: 2.19.2

You have to install all the R packages related to stan from source when you are under macOS Catalina… and you have to setup your compiler adequately; please search on the forum for that info.

(we should really put this onto a wiki page)

Thank you. Ugh, I had already gone through all those posts and had things working correctly after adjusting Makevars etc. This is the only model where issue were coming up. Now I’ve just tried removing everything and reinstalling from source and I’m getting all these non-zero exit statuses with fatal error: 'stdlib.h' file not found and cp: tbb/build/lib_release/libtbb*.*: No such file or directory

I’ll go back and try again from scratch. That wiki page would be great though – as you know there are now multiple long threads on Catalina so finding and stitching together the right step-by-step instructions that should work for me is non-trivial.

it does sound weird that you had it working and then find one model where you have again trouble… did you install rstanarm from source?

It was quite some effort to find out about the technical details on macOS to make it work.

I don’t remember how I had rstanarm installed previously, but I had it working at some point post Catalina. After your response I tried removing everything and reinstalling from source twice after but got the errors above apparently related to RcppParallel. I had to go to work though so I can’t revisit this until tonight.

It is weird. Direct calls to stan() were compiling and running just fine, as were calls to stan_gamm4 without the random effect.

I just found in the commit logs of RcppParallel that there was a fix for macOS Catalina compilation. I don’t remember that I had to do that, but you could try to install RcppParallel from their source directly with devtools: https://github.com/RcppCore/RcppParallel

I’ll try that tonight thank you

Installing RcppParallel with devtools and then reinstalling rstanarm from source worked for me! Thank you so much for sleuthing that!!