/
brm2.stan
53 lines (48 loc) · 875 Bytes
/
brm2.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
52
53
data {
int<lower = 0> N;
int<lower = 0> J;
matrix[N,J] y;
vector[J] ymax;
}
transformed data{
matrix[N,J] x;
vector[N] tmp;
for(j in 1:J){
tmp = y[,j];
x[,j] = (tmp+1) / (ymax[j]+2);
}
}
parameters {
real<lower = 0> a[J];
real b[J];
real theta[N];
}
transformed parameters{
matrix[N, J] shape1;
matrix[N, J] shape2;
real m;
for(i in 1:N){
for (j in 1:J){
if(x[i,j] < 0) continue;
m = a[j] * (theta[i] - b[j]) / 2.0;
shape1[i,j] = exp(m);
shape2[i,j] = exp(-m);
}
}
}
model {
a ~ cauchy(0.5, 1);
b ~ normal(0, 3);
theta ~ normal(0, 1);
for(i in 1:N){
for(j in 1:J){
if(x[i,j] < 0){
// target += 0;
continue;
} else {
// target += beta_lpdf(x[i,j] | shape1[i,j], shape2[i,j]);
x[i,j] ~ beta(shape1[i,j], shape2[i,j]);
}
}
}
}