-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsx_pp.stan
45 lines (40 loc) · 907 Bytes
/
sx_pp.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
//
data {
int<lower = 0> N; // number of participants
int<lower = 1, upper = 5> stage[N]; //stage variable
int<lower = 1> N_stages; // number of stages
vector [N]sx;
}
parameters {
real<lower = 0> nu;
vector[5]b_stage_raw;
real mu_stage;
real<lower = 0> sig_stage;
real<lower = 0>sig;
}
transformed parameters {
vector[N_stages] b_stage;
for (i in 1:N_stages) {
b_stage[i] = mu_stage + sig_stage * b_stage_raw[i];
}
}
model {
// priors
b_stage_raw ~ normal(0,1);
mu_stage ~ normal(0,0.5);
sig_stage ~ exponential( 1 );
sig ~ exponential( 1 );
nu ~ gamma( 2 ,0.1 );
//likelihood
for (i in 1:N) {
sx[i] ~ student_t(nu,b_stage[stage[i]], sig);
}
}
generated quantities{
vector[N] log_lik;
vector[N] mu;
for ( i in 1:N ) {
mu[i] = b_stage[stage[i]];
}
for ( i in 1:N ) log_lik[i] = student_t_lpdf( sx[i] | nu,mu[i] , sig );
}