title: Stan error: require unconstrained variable declaration. found simplex
body: <p>In Stan, I get the following error:</p>
  
  <pre><code>SYNTAX ERROR, MESSAGE(S) FROM PARSER:
  require unconstrained variable declaration. found simplex.
  
  ERROR at line 48
   46:    for (j in 1:records) {  
   47:            real phenology_predictor;
   48:            simplex[7] pi;
                          ^
  </code></pre>
  
  <p>I don't quite understand what is the problem. When I used <code>real pi[7]</code> instead of <code>simplex[7] pi</code>, I got different error:</p>
  
  <pre><code>SYNTAX ERROR, MESSAGE(S) FROM PARSER:
  no matches for function name="categorical_log"
      arg 0 type=int
      arg 1 type=real[1]
  available function signatures for categorical_log:
  0.  categorical_log(int, vector) : real
  1.  categorical_log(int[1], vector) : real
  unknown distribution=categorical
  
  ERROR at line 63
   62:    
   63:                    Y[j] ~ categorical(pi);
                                        ^
   64:    
  </code></pre>
  
  <p>which I don't understand either... My whole code:</p>
  
  <pre><code>data {
      int sites;
      int records;
      int Y[records];
      vector[records] yday;
      int site[records];
  }
  transformed data {
      int M[sites];
  }
  parameters {
      real&lt;lower=0,upper=1&gt; psi;
      real&lt;lower=0,upper=1000&gt; phi_phen_scale;
      real phi_alpha;
      real q_date;
      real q_date2;
      real q_site[sites];
  }
  model {
      real p[records];
      real q[records];
  
  // priors
  phi_phen_scale ~ normal(0, 10);
  phi_alpha ~ normal(0, 10);
  q_date ~ normal(0, 10);
  q_date2 ~ normal(0, 10);
  
  // vectorized
  M ~ bernoulli(psi);
  q_site ~ normal(0, 10);
  
  for (j in 1:records) {  
      real phenology_predictor;
      simplex[7] pi;
  
      phenology_predictor &lt;- q_date * yday[j] + q_date2 * yday[j]^2;
      p[j] &lt;- M[site[j]] * inv_logit(phi_alpha + phi_phen_scale * phenology_predictor);
      q[j] &lt;- inv_logit(q_site[site[j]] + phenology_predictor);
  
      pi[1] &lt;- 1-p[j] + p[j]*(1-q[j])^6; 
      pi[2] &lt;- p[j]*q[j]  ;   
      pi[3] &lt;- p[j]*(1-q[j])*q[j];
      pi[4] &lt;- p[j]*(1-q[j])^2*q[j];
      pi[5] &lt;- p[j]*(1-q[j])^3*q[j];
      pi[6] &lt;- p[j]*(1-q[j])^4*q[j];
      pi[7] &lt;- p[j]*(1-q[j])^5*q[j];
  
      Y[j] ~ categorical(pi);
  
  }
  
  }
  </code></pre>