model.stan 696 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. data {
  2. int N;
  3. vector<lower=0>[N] age;
  4. vector<lower=0,upper=1>[N] ratio;
  5. }
  6. transformed data {
  7. int M = 500;
  8. real lambda = -log(M);
  9. vector<lower=0,upper=5>[M] c;
  10. for (i in 1:M) {
  11. c[i] = i*5.0/(1.0*M);
  12. }
  13. }
  14. parameters {
  15. real<lower=0,upper=1> mu_low;
  16. real<lower=0,upper=1> mu_up;
  17. real<lower=1> eta;
  18. }
  19. transformed parameters {
  20. vector[M] lp;
  21. lp = rep_vector(lambda, M);
  22. for (m in 1:M) {
  23. for (n in 1:N) {
  24. lp[m] = lp[m] + beta_proportion_lpdf(ratio[n] | age[n] < c[m] ? mu_low : mu_up, eta);
  25. }
  26. }
  27. }
  28. model {
  29. mu_low ~ uniform(0, 1);
  30. mu_up ~ uniform(0, 1);
  31. eta ~ pareto(1,1.5);
  32. target += log_sum_exp(lp);
  33. }