-
Notifications
You must be signed in to change notification settings - Fork 0
/
model-pvl.stan
49 lines (46 loc) · 1.06 KB
/
model-pvl.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
functions {
real[] pvl(int[] x, int T, real A, real theta) {
real r[T];
real mem;
mem = 0;
for (t in 1:T) {
r[t] = theta*mem;
mem = A*mem + 2*x[t] - 1;
}
return r;
}
}
data {
int<lower=0> T; // Number of trials
int<lower=0> N; // Number of participants
int<lower=0, upper=1> x[N,T];
int<lower=0, upper=1> y[N,T];
}
parameters {
vector[2] pvl_params[N]; // A, theta
cholesky_factor_corr[2] L_Omega;
vector[2] mu;
vector<lower=0>[2] scale;
}
transformed parameters {
real A[N];
real theta[N];
matrix[2,2] sigma;
real nu;
for (i in 1:N) {
A[i] = inv_logit(pvl_params[i,1]);
theta[i] = exp(pvl_params[i,2]);
}
sigma = diag_pre_multiply(scale, L_Omega);
sigma = sigma * sigma';
nu = 4;
}
model {
mu ~ normal(0, 100);
scale ~ normal(0, 1);
L_Omega ~ lkj_corr_cholesky(1);
pvl_params ~ multi_student_t(nu, mu, sigma);
for (i in 1:N) {
y[i] ~ bernoulli_logit(pvl(x[i], T, A[i], theta[i]));
}
}