Hi all,
I received this error message when re-running a program worked once before. The only difference is that I did some variable selection using dplyr. Advice welcomed.
David
library(rstan)
library(loo)
library(bayesplot)
library(dplyr)
## Read in data ##
PISA18reg <- read.csv(file.choose(),header=T)
PISA18reg %>% select(PV1READ, Female, ESCS,
METASUM, PERFEED, JOYREAD, MASTGOAL,
ADAPTIVITY, TEACHINT, SCREADDIFF,SCREADCOMP)
PISA18reg %>% mutate(Female=recode(Female, 'Male'='1', 'Female'='0'))
data.list <- with(PISA18reg, list(readscore=PV1READ, Female=Female, ESCS=ESCS,
METASUM=METASUM, PERFEED=PERFEED, JOYREAD=JOYREAD,
ADAPTIVITY=ADAPTIVITY, TEACHINT=TEACHINT, MASTGOAL=MASTGOAL,
SCREADDIFF=SCREADDIFF, SCREADCOMP=SCREADCOMP, n = nrow(PISA18reg)))
## Begin Stan Code. Notice that Stan uses // for comments ##
modelString = "
data {
int<lower=0> n;
vector [n] readscore;
vector [n] Female; vector [n] ESCS;
vector [n] METASUM; vector [n] PERFEED;
vector [n] JOYREAD; vector [n] MASTGOAL;
vector [n] ADAPTIVITY; vector [n] TEACHINT;
vector [n] SCREADDIFF; vector [n] SCREADCOMP;
}
parameters {
real alpha;
real beta1; real beta6;
real beta2; real beta7;
real beta3; real beta8;
real beta4; real beta9;
real beta5; real beta10;
real<lower=0> sigma;
}
model {
real mu[n];
for (i in 1:n)
mu[i] = alpha + beta1*Female[i] + beta2*ESCS[i] + beta3*METASUM[i]
+ beta4*PERFEED[i] + beta5*JOYREAD[i] + beta6*MASTGOAL[i]
+ beta7*ADAPTIVITY[i] + beta8*TEACHINT[i]
+ beta9*SCREADDIFF[i] + beta10*SCREADCOMP[i] ;
// Informative Priors
alpha ~ normal(500, 5);
beta1 ~ normal(10, 2); beta6 ~ normal(0, 2);
beta2 ~ normal(30, 5); beta7 ~ normal(0, 2);
beta3 ~ normal(0, 2); beta8 ~ normal(0, 2);
beta4 ~ normal(0, 2); beta9 ~ normal(0, 2);
beta5 ~ normal(10, 5); beta10 ~ normal(0, 2);
sigma ~ cauchy(0,6);
// Likelihood
readscore ~ normal(mu, sigma);
}
// For posterior predictive checking and loo cross-validation
generated quantities {
vector[n] readscore_rep;
vector[n] log_lik;
for (i in 1:n) {
readscore_rep[i] = normal_rng(alpha + beta1*Female[i] + beta2*ESCS[i] + beta3*METASUM[i]
+ beta4*PERFEED[i] + beta5*JOYREAD[i] + beta6*MASTGOAL[i]+ beta7*ADAPTIVITY[i] + beta8*TEACHINT[i]
+ beta9*SCREADDIFF[i] + beta10*SCREADCOMP[i], sigma);
log_lik[i] = normal_lpdf(readscore[i] | alpha + beta1*Female[i] + beta2*ESCS[i] + beta3*METASUM[i]
+ beta4*PERFEED[i] + beta5*JOYREAD[i] + beta6*MASTGOAL[i]+ beta7*ADAPTIVITY[i] + beta8*TEACHINT[i]
+ beta9*SCREADDIFF[i] + beta10*SCREADCOMP[i], sigma);
}
}
"
# Start estimation
nChains = 4
nIter= 5000
thinSteps = 10
warmupSteps = floor(nIter/2)
readscore = data.list$readscore
myfit2inf = stan(data=data.list,model_code=modelString,chains=nChains,
iter=nIter,warmup=warmupSteps,thin=thinSteps)
The error message I am receiving is
sh: clang++ -mmacosx-version-min=10.13: command not found
The NEXT version of Stan will not be able to pre-process your Stan program.
Please open an issue at
https://github.com/stan-dev/stanc3/issues
if you can share or at least describe your Stan program. This will help ensure that Stan
continues to work on your Stan programs in the future. Thank you!
This message can be avoided by wrapping your function call inside suppressMessages().
Error in mod$fit_ptr() :
Exception: variable does not exist; processing stage=data initialization; variable name=Female; base type=vector_d (in 'model49610aba05a_4339c0257f86fc40131c3a03c57ec4db' at line 5)
In addition: Warning messages:
1: In system2(CXX, args = ARGS) : error in running command
2: In file.remove(c(unprocessed, processed)) :
cannot remove file '/var/folders/yj/r2np23xx471d9cnj_8myvphr0000gn/T//RtmpQVukci/file496183c17e9.stan', reason 'No such file or directory'
failed to create the sampler; sampling not done