title: Troubleshooting Rstan error "running command...had status 1"
body: <p>I am getting an Rstan error that I don't understand and this particular error hasn't been addressed in the previous Stack Overflow questions.</p>
  
  <p>The R code to call Rstan is</p>
  
  <pre><code>    # Fit the model
      start = Sys.time()
      pvl_d_fit &lt;- stan(file = 'pvl_d.stan', data = pvl_d_dat, 
                verbose = TRUE,
                warmup = 1000, iter = 4000, thin = 3, chains = 3, 
                init = 'random', pars = c(  
                "A_ind", "mu_A", "la_A",
                "w_ind", "mu_w", "la_w",
                "a_ind", "mu_a", "la_a",
                "c_ind", "mu_c", "la_c"))
      end = Sys.time()                  
      end - start 
  </code></pre>
  
  <p>And get the following output:</p>
  
  <pre><code>SAMPLING FOR MODEL 'pvl_d' NOW (CHAIN 1).
  
  Informational Message: The current Metropolis proposal is about to be rejected becuase of the following issue:
  Error in function stan::prob::normal_log(N4stan5agrad3varE): Random variable is -1.#IND:0, but must not be nan!
  If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
  but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
  </code></pre>
  
  <p>Anyone run into this before?</p>
  
  <p>(Note: this message is repeated over and over again).</p>
  
  <pre><code>Error in compileCode(f, code, language = language, verbose = verbose) : 
    Compilation ERROR, function(s)/method(s) not created! cygwin warning:
    MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
    Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
    CYGWIN environment variable option "nodosfilewarning" turns off this warning.
    Consult the user's guide for more details about POSIX paths:
      http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
  C:/Users/User/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
  C:/Users/User/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
  c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/as.exe: file9d8452242a.o: too many sections (39807)
  C:\Users\User\AppData\Local\Temp\ccOl2E
  In addition: Warning message:
  running command 'C:/PROGRA~1/R/R-30~1.2/bin/x64/R CMD SHLIB file9d8452242a.cpp 2&gt; file9d8452242a.cpp.err.txt' had status 1 
  </code></pre>
  
  <p>The stan file is:</p>
  
  <pre><code>    data {
        int&lt;lower=1&gt; n_s;                       // # subjects
        int&lt;lower=1&gt; n_t;                       // # trials
        int&lt;lower=0,upper=4&gt; choice[n_s, n_t];  // # subj. x # trials matrix with choices
        real&lt;lower=-25,upper=2&gt; net[n_s, n_t];  // Net amount of wins + losses   
                                                // (# subj. x # trials matrix) 
      }
  
      parameters {
        // Group-level mean parameters
        real mu_A_pr;   
        real mu_w_pr;
        real mu_a_pr;  
        real mu_c_pr;
  
        // Group-level standard deviation  
        real&lt;lower=0&gt; sd_A;
        real&lt;lower=0&gt; sd_w;
        real&lt;lower=0&gt; sd_a;
        real&lt;lower=0&gt; sd_c;    
  
        // Individual-level paramters    
        real A_ind_pr[n_s]; 
        real w_ind_pr[n_s]; 
        real a_ind_pr[n_s];   
        real c_ind_pr[n_s]; 
      }
  
      transformed parameters {
        real&lt;lower=0,upper=1&gt; mu_A;   
        real&lt;lower=0,upper=5&gt; mu_w;
        real&lt;lower=0,upper=1&gt; mu_a;  
        real&lt;lower=0,upper=5&gt; mu_c;
  
        // Individual-level paramters    
        real&lt;lower=0,upper=1&gt; A_ind[n_s]; 
        real&lt;lower=0,upper=5&gt; w_ind[n_s]; 
        real&lt;lower=0,upper=1&gt; a_ind[n_s];   
        real&lt;lower=0,upper=5&gt; c_ind[n_s];   
  
        // Group-level precision parameters  
        real&lt;lower=0&gt; la_A;
        real&lt;lower=0&gt; la_w;
        real&lt;lower=0&gt; la_a;
        real&lt;lower=0&gt; la_c;     
  
        mu_A &lt;- Phi(mu_A_pr);
        mu_w &lt;- Phi(mu_w_pr) * 5;
        mu_a &lt;- Phi(mu_a_pr); 
        mu_c &lt;- Phi(mu_c_pr) * 5;  
  
        for (s in 1:n_s)
        {
           A_ind[s] &lt;- Phi(A_ind_pr[s]);
           w_ind[s] &lt;- Phi(w_ind_pr[s]) * 5;
           a_ind[s] &lt;- Phi(a_ind_pr[s]); 
           c_ind[s] &lt;- Phi(c_ind_pr[s]) * 5;  
        }
  
         la_A &lt;- pow(sd_A, -2);
         la_w &lt;- pow(sd_w, -2);
         la_a &lt;- pow(sd_a, -2);
         la_c &lt;- pow(sd_c, -2);  
       }
  
       model {
        vector[4] p;
        real Ev[4];
        real dummy[4];
        real theta;
        real v;
  
        # Prior on the group-level mean parameters
        # probit scale [-Inf, Inf]  
        mu_A_pr ~ normal(0, 1);
        mu_w_pr ~ normal(0, 1);
        mu_a_pr ~ normal(0, 1);
        mu_c_pr ~ normal(0, 1);
  
         # Prior on the group-level standard deviation
        sd_A ~ uniform(0,1.5); 
        sd_w ~ uniform(0,1.5); 
        sd_a ~ uniform(0,1.5);    
        sd_c ~ uniform(0,1.5);
  
         # Individual-level paramters
         for (s in 1:n_s)
        {
          A_ind_pr[s] ~ normal(mu_A_pr, sd_A);      
          w_ind_pr[s] ~ normal(mu_w_pr, sd_w);   
          a_ind_pr[s] ~ normal(mu_a_pr, sd_a);   
          c_ind_pr[s] ~ normal(mu_c_pr, sd_c);    
        }
  
        for (s in 1 : n_s)  // loop over subjects
        {  
          theta &lt;- pow(3, c_ind[s]) - 1;     
  
         // Trial 1
          for (d in 1 : 4)  // loop over decks
          {  
            p[d] &lt;- .25;
            Ev[d] &lt;- 0;
          }  
          choice[s,1] ~ categorical(p);
  
          // Remaining trials
          for (t in 1 : (n_t - 1))  
              { 
              if (net[s,t] &gt;= 0)
              v &lt;- pow(net[s,t], A_ind[s]);
              else
              v &lt;- -1 * w_ind[s] * pow(abs(net[s,t]), A_ind[s]);
  
            Ev[choice[s,t]] &lt;- (1 - a_ind[s]) * Ev[choice[s,t]] + a_ind[s] * v;      
  
            for (d in 1 : 4)  // loop over decks
            dummy[d] &lt;- exp(fmax(fmin(Ev[d] * theta, 450), -450));       
  
            for (d in 1 : 4)  // loop over decks
            p[d] &lt;- dummy[d] / sum(dummy); 
  
            choice[s, t + 1] ~ categorical(p);
          }
        } 
      }
  </code></pre>