-
-
Notifications
You must be signed in to change notification settings - Fork 479
/
camel.stan
66 lines (64 loc) · 1.17 KB
/
camel.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
56
57
58
59
60
61
62
63
64
65
66
/**
* Camel: Multivariate normal with structured missing data
* http://www.openbugs.net/Examples/Camel.html
*
* status: results not verified with in those in bugs
*/
transformed data {
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;
}
parameters {
cov_matrix[2] Sigma;
real y52;
real y62;
real y72;
real y82;
real y91;
real y101;
real y111;
real y121;
}
model {
array[12] vector[2] Y;
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;
Y[5, 1] = 2;
Y[6, 1] = 2;
Y[7, 1] = -2;
Y[8, 1] = -2;
Y[5, 2] = y52;
Y[6, 2] = y62;
Y[7, 2] = y72;
Y[8, 2] = y82;
Y[9, 1] = y91;
Y[10, 1] = y101;
Y[11, 1] = y111;
Y[12, 1] = y121;
Y[9, 2] = 2;
Y[10, 2] = 2;
Y[11, 2] = -2;
Y[12, 2] = -2;
// instead of Sigma ~ inv_wishart(2, S),
// using the prior as in Tanner and Wong (1987)
target += -1.5 * log(determinant(Sigma));
for (n in 1 : 12) {
Y[n] ~ multi_normal(mu, Sigma);
}
}
generated quantities {
real<lower=-1, upper=1> rho;
rho = Sigma[1, 2] / sqrt(Sigma[1, 1] * Sigma[2, 2]);
}