-
-
Notifications
You must be signed in to change notification settings - Fork 478
/
camel2.stan
55 lines (50 loc) · 994 Bytes
/
camel2.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
54
55
/*
* Camel: Multivariate normal with structured missing data
* http://www.openbugs.net/Examples/Camel.html
*
* integrate out the missing data
*/
transformed data {
array[4] vector[2] Y;
array[4] real Y1; // missing y2
array[4] real Y2; // msising y1
vector[2] mu;
matrix[2, 2] S;
mu[1] = 0;
mu[2] = 0;
S[1, 1] = 1000;
S[1, 2] = 0;
S[2, 1] = 0;
S[2, 2] = 1000;
Y[1, 1] = 1.;
Y[1, 2] = 1.;
Y[2, 1] = 1.;
Y[2, 2] = -1.;
Y[3, 1] = -1.;
Y[3, 2] = 1.;
Y[4, 1] = -1.;
Y[4, 2] = -1.;
Y1[1] = 2.;
Y1[2] = 2.;
Y1[3] = -2.;
Y1[4] = -2.;
Y2[1] = 2.;
Y2[2] = 2.;
Y2[3] = -2.;
Y2[4] = -2.;
}
parameters {
cov_matrix[2] Sigma;
}
transformed parameters {
real<lower=-1, upper=1> rho;
rho = Sigma[1, 2] / sqrt(Sigma[1, 1] * Sigma[2, 2]);
}
model {
for (n in 1 : 4) {
Y[n] ~ multi_normal(mu, Sigma);
}
Y1 ~ normal(0, sqrt(Sigma[1, 1]));
Y2 ~ normal(0, sqrt(Sigma[2, 2]));
target += -1.5 * log(determinant(Sigma));
}