 functions {
      real simplx_lpdf(real y, real mu, real si2) {
        return -.5*(log(2)+log(pi())+log(si2)+3*log(y)+3*log(1-y)) -1*(y-mu)^2/(2*si2*y*(1-y)*mu^2*(1-mu)^2);
      }
  }
data {
  int<lower=0> N;
  int<lower=0> nit;
  matrix[N,nit] z;
}
parameters {
  vector[N] theta;
  vector[nit] beta;
  vector[nit] ln_phi;
  vector[nit] ln_alpha;
}
transformed parameters{
  vector<lower=0>[nit] alpha = exp(ln_alpha);
  vector<lower=0>[nit] phi = exp(ln_phi);
}
model {
  beta~normal(0,10) ;
  ln_phi~normal(0,10);
  ln_alpha~normal(0,10);
  theta~normal(0,1);

  for(p in 1:N)
    for(i in 1:nit)
      if(z[p,i]!=-999) target+=simplx_lpdf(z[p,i] | inv_logit(beta[i]+alpha[i]*theta[p]) ,phi[i]);
 }

