stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 269 forks source link

Stan errors and "The NEXT version of Stan will not be able to pre-process your Stan program." #809

Closed c0nfusedc0der closed 4 years ago

c0nfusedc0der commented 4 years ago

I am attempting to run Rstan code on a mac and received the following error:

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: model6c072e2f00f_air001_stancode_namespace::model6c072e2f00f_air001_stancode: Y[i_0__] is -0.0570965, but must be greater than or equal to 0  (in 'model6c072e2f00f_air001_stancode' at line 7)

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/9_/y248j5rj1rb82kfhskt4pm680000gn/T//Rtmp6T5T01/file6c03dae0a71.stan', reason 'No such file or directory'
failed to create the sampler; sampling not done

My code is the following:

data{
    int  J;               //  number of items
    int  I;               //  number of individuals
    int  n_obs;           //  number of observed responses
  int  item[n_obs];     //  item id
  int  id[n_obs];       //  person id 
  real<lower=0> Y[n_obs];        //  vector of log of response times 
  int di[n_obs];       // vector of dichotmous items
    vector[3] mu_tau;     // vector of means for random effects
}

parameters {

    vector[J] beta;       //item specific time intensity parameter
      real mu_beta;               // mean of beta
      real<lower=0> sigma_beta;   // sd of beta

    vector [J]  alpha;  // item specific residual standard deviation,
      real mu_alpha;    // mean of alpha 
      real<lower=0> sigma_alpha; // sd of alpha

      vector[I]  theta; // ability

        vector[J] delta;               //item specific item difficulty
      real mu_delta;               // mean of delta
      real<lower=0> sigma_delta;   // sd of delta

        vector <lower=0>[J]  discrim;  // item discrim

    vector[3] tau[I];                   // I x 3 matrix for random effects
    vector<lower=0>[3] sigma;           // vector of standard deviations for random effects
    cholesky_factor_corr[3] rho;        // correlation matrix among random effects

}

model{

    mu_beta     ~ normal(0,5); // time intensity parameter
    sigma_beta   ~ cauchy(0,2.5);
    beta     ~ normal(mu_beta,sigma_beta);

    mu_alpha     ~ normal(0,5); //time discrimination parameter
    sigma_alpha  ~ cauchy(0,2.5);
    alpha       ~ normal(mu_alpha,sigma_alpha);

  theta ~ normal(0,1); //ability

  delta ~ normal(0,1); //item difficulty
   mu_delta ~ normal(0,4);
  sigma_delta ~ cauchy(0,2.5);   

  discrim ~ normal(0, 1); //item discrimination

    sigma  ~ cauchy(0,2.5);
  rho    ~ lkj_corr_cholesky(1);
    tau      ~ multi_normal_cholesky(mu_tau,diag_pre_multiply(sigma,rho)); 

    for (i in 1:n_obs) {        

   real md = bernoulli_logit_lpmf(id| discrim[i]*(theta[i]-delta[i])) ;
   real p = beta[item[i]] + tau[id[i],2]*(item[i]-1) + md*(item[i]-1)*tau[id[i],3]; 

        Y[i] ~ normal(p,1/(alpha[item[i]]^2));
    }
}
SteveBronder commented 4 years ago

Thanks for submitting an issue! It looks like the clang error is related to #774

For the error Y[i_0__] is -0.0570965, but must be greater than or equal to 0

It looks like you are setting Y as real<lower=0>. When you bring in Y are all values greater than zero? Else that lower=0 will cause an exception to occur.

c0nfusedc0der commented 4 years ago

I tried the code from the other forum:

remotes::install_github("stan-dev/rstan", ref = "develop", subdir =
"rstan/rstan")

I removed the limits but this was the error/warning:

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().
hash mismatch so recompiling; make sure Stan code ends with a blank line

SAMPLING FOR MODEL 'air001_stancode' NOW (CHAIN 1).
Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: bernoulli_logit_lpmf: n[2] is 2, but must be in the interval [0, 1]  (in 'model6c03ac9179b_air001_stancode' at line 62)

Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: bernoulli_logit_lpmf: n[2] is 2, but must be in the interval [0, 1]  (in 'model6c03ac9179b_air001_stancode' at line 62)

Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: bernoulli_logit_lpmf: n[2] is 2, but must be in the interval [0, 1]  (in 'model6c03ac9179b_air001_stancode' at line 62)

Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: bernoulli_logit_lpmf: n[2] is 2, but must be in the interval [0, 1]  (in 'model6c03ac9179b_air001_stancode' at line 62)

Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: bernoulli_logit_lpmf: n[2] is 2, but must be in the interval [0, 1]  (in 'model6c03ac9179b_air001_stancode' at line 62)

Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: bernoulli_logit_lpmf: n[2] is 2, but must be in the interval [0, 1]  (in 'model6c03ac9179b_air001_stancode' at line 62)

this continues and the end of the console messages:

Chain 1: Rejecting initial value:
Chain 1:   Error evaluating the log probability at the initial value.
Chain 1: Exception: bernoulli_logit_lpmf: n[2] is 2, but must be in the interval [0, 1]  (in 'model6c03ac9179b_air001_stancode' at line 62)

Chain 1: 
Chain 1: Initialization between (-2, 2) failed after 100 attempts. 
Chain 1:  Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization failed."                                                                      
[2] "In addition: Warning messages:"                                                                                                              
[3] "1: In system2(CXX, args = ARGS) : error in running command"                                                                                  
[4] "2: In file.remove(c(unprocessed, processed)) :"                                                                                              
[5] "  cannot remove file '/var/folders/9_/y248j5rj1rb82kfhskt4pm680000gn/T//Rtmp6T5T01/file6c059f5dd23.stan', reason 'No such file or directory'"
error occurred during calling the sampler; sampling not done

And line 62 is:

real md = bernoulli_logit_lpmf(id| discrim[i]*(theta[i]-delta[i])) ;
SteveBronder commented 4 years ago

It sounds like this might be a model issue that would be better to post on discourse. I ran your model with the new compiler and cmdstan and it compiled fine so I think the The NEXT version of Stan warning is a false positive from the clang++ -mmacosx-version-min=10.13 issue

c0nfusedc0der commented 4 years ago

Thank you so much! If the model ran and produced results for you then is there an issue with my setup or dataset? I'm not sure what my next step would be on discourse.

I have also attempted to use "brms" R package to use the make stan code function. It successfully worked on the built-in dataset as the example but produced a completely different model from mine, with the exact same rejection errors.

SteveBronder commented 4 years ago

Sorry I by ran I just meant that the model compiled with the new compiler and cmdstan. I think your issue is a data one which should be posted on https://discourse.mc-stan.org/

It looks like id needs to be between [0, 1] for bernouli_logit_lpmf

jgabry commented 4 years ago

I think your issue is a data one which should be posted on https://discourse.mc-stan.org/

Closing this since it's a data issue. If I misinterpreted and this should stay open let me know and we can reopen.

c0nfusedc0der commented 4 years ago

Yes I believe it is a data issue. However when I have a Stan file open, the Rstudio console will sometimes give this message (even when I am not executing code and sometimes when I'm not editing code, simply opening a .stan file produces this).

sh: clang++ -mmacosx-version-min=10.13: command not found

Seems to not impact running code.

jgabry commented 4 years ago

Thanks for letting us know. I'm glad that the message isn't preventing anything from running, but that's still annoying so we'll look into that.

SteveBronder commented 4 years ago

For the clang message checkout #774