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.
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.
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.
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