1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- functions {
- real model_lpmf(array[] int counts,
- int start, int end,
- array[,] int votes,
- vector alphas
- ) {
- real ll = 0;
- for (k in start:end) {
- ll += dirichlet_multinomial_lpmf(votes[k] | alphas);
- }
- return ll;
- }
- }
- data {
- int<lower=1> N;
- int<lower=1> C;
- array[N,C] int<lower=0> votes;
- }
- transformed data {
- array[N] int counts;
- for (i in 1:N) {
- counts[i] = sum(votes[i]);
- }
- }
- parameters {
- vector<lower=0>[C] alphas;
- //array[N] simplex[C] p;
- }
- model {
- target += reduce_sum(
- model_lpmf, counts, 1,
- votes, alphas
- );
- alphas ~ exponential(1);
- }
- generated quantities {
- simplex[C] p = dirichlet_rng(alphas);
- }
|