-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathordinal_model_1.stan
52 lines (41 loc) · 1.29 KB
/
ordinal_model_1.stan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Bayesian CPM model with dirichlet prior
// concentration (alpha) is given as a scalar parameter along with data
// modified in part from code by Philip G Jones <[email protected]>
// itself based on stan_polr() code https://github.com/stan-dev/rstanarm/blob/master/src/stan_files/polr.stan
functions {
#include /bayes_cpm_funs.stan
}
data {
int N; // number of observations
int ncat; // number of unique outcome values
int Ylev[N]; // ranks of unique outcome values
int link; // link function (1=logistic, 2=probit, ...)
int K; // number of predictors
matrix[N, K] Q; // N x K design matrix
real<lower=0> alpha; // concentration parameter
}
parameters {
simplex[ncat] pi;
vector[K] b;
}
transformed parameters {
vector[ncat - 1] cutpoints;
vector[N] log_lik;
cutpoints = make_cutpoints(pi, ncat, link);
log_lik = loglik(Ylev, N, cutpoints, ncat, Q * b, link);
}
model {
//prior for counts
// repeat alpha for all params (i.e. symmetric Dirichlet)
target += dirichlet_lpdf(pi | rep_vector(alpha, ncat));
// equivalently
// pi ~ dirichlet(rep_vector(alpha, ncat));
//prior for betas
//target += student_t_lpdf(b | 3, 0, 10);
// equivalently
// b ~ student_t(3, 0, 10);
target += log_lik;
}
generated quantities {
//vector[K] beta = R_inv * b;
}