I’m working through Statistical rethinking right now in order to learn Stan, and having issues where fitting most MCMC models crash my R session. In some cases they’ll fit and the session crashes after running a few more code blocks, in some it crashes when fitting. I assume this is a memory issue, but I can’t imagine straightforward models would crash my session like this. I’m using a 2015 dual-core 8gb macbook pro. Is this common?

This is a persisting problem, but the most recent example is model 14.1:

```
m14.1 <- ulam(
alist(
wait ~ normal( mu , sigma ),
mu <- a_cafe[cafe] + b_cafe[cafe]*afternoon,
c(a_cafe,b_cafe)[cafe] ~ multi_normal( c(a,b) , Rho , sigma_cafe ),
a ~ normal(5,2),
b ~ normal(-1,0.5),
sigma_cafe ~ exponential(1),
sigma ~ exponential(1),
Rho ~ lkj_corr(2)
) , data=d , chains=2 , cores=1)
```

This crashes the session on fitting. I also tried fitting with pure Stan, not the ulam overlay:

```
```{r}
try01 <- as.character("
data{
vector[200] wait;
int afternoon[200];
int cafe[200];
}
parameters{
vector[20] b_cafe;
vector[20] a_cafe;
real a;
real b;
vector<lower=0>[2] sigma_cafe;
real<lower=0> sigma;
corr_matrix[2] Rho;
}
model{
vector[200] mu;
Rho ~ lkj_corr( 2 );
sigma ~ exponential( 1 );
sigma_cafe ~ exponential( 1 );
b ~ normal( -1 , 0.5 );
a ~ normal( 5 , 2 );
{
vector[2] YY[20];
vector[2] MU;
MU = [ a , b ]';
for ( j in 1:20 ) YY[j] = [ a_cafe[j] , b_cafe[j] ]';
YY ~ multi_normal( MU , quad_form_diag(Rho , sigma_cafe) );
}
for ( i in 1:200 ) {
mu[i] = a_cafe[cafe[i]] + b_cafe[cafe[i]] * afternoon[i];
}
wait ~ normal( mu , sigma );
}
")
m14.1 <- stan( model_code = try01, data=d, chains=2)
```

which also crashes for me. I’ve tried running from Rstudio and from command line. Full disclosure, I’m doing it within the context of an Rmarkdown script, so I’m running as:

```
Rscript -e "rmarkdown::render('ch14.Rmd', clean=TRUE)
```

Relevant session info:

```
version R version 4.0.1 (2020-06-06)
os macOS Catalina 10.15.4
system x86_64, darwin19.5.0
ui RStudio
rethinking_2.01
rstan * 2.21.2 2020-07-27 [1] CRAN (R 4.0.1)
```