An error message about next version of Stan

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
1 Like

My main guess would be that the error is coming from this section:

PISA18reg %>% select(PV1READ, Female, ESCS, 
              METASUM, PERFEED, JOYREAD, MASTGOAL, 
              ADAPTIVITY, TEACHINT, SCREADDIFF,SCREADCOMP)
PISA18reg %>% mutate(Female=recode(Female, 'Male'='1', 'Female'='0'))

While you’re performing the variable selections/mutations you’re not saving the results, so the PISA18reg dataset is unchanged.

Try overwriting the dataset after each call:

PISA18reg <- PISA18reg %>% select(PV1READ, Female, ESCS, 
              METASUM, PERFEED, JOYREAD, MASTGOAL, 
              ADAPTIVITY, TEACHINT, SCREADDIFF,SCREADCOMP)
PISA18reg <- PISA18reg %>% mutate(Female=recode(Female, 'Male'='1', 'Female'='0'))

Thanks. I’m afraid that wasn’t it. Here is the code and error message again.



library(rstan)
library(loo)
library(bayesplot)
library(dplyr)



## Read in data ##


PISA18reg <- read.csv(file.choose(),header=T)
PISA18reg1 <- PISA18reg %>% select(PV1READ, Female, ESCS, 
              METASUM, PERFEED, JOYREAD, MASTGOAL, 
              ADAPTIVITY, TEACHINT, SCREADDIFF,SCREADCOMP)
PISA18reg2<- PISA18reg1 %>% mutate(Female=recode(Female, 'Male'='1', 'Female'='0'))
data.list <- with(PISA18reg2, 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(PISA18reg2)))

## 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)

Error message

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 'model6171f4887f5_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//Rtmpq34c29/file6175ac77c79.stan', reason 'No such file or directory'
failed to create the sampler; sampling not done

Looks like you’re defining female as a character vector, not as numeric. Try dropping the quotes around 1 and 0 and see if that fixes some of the errors?

1 Like