-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_test.stan
79 lines (63 loc) · 2.71 KB
/
two_test.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
67
68
69
70
71
72
73
74
75
76
77
78
//
// This Stan program defines a simple model, with a
// vector of values 'y' modeled as normally distributed
// with mean 'mu' and standard deviation 'sigma'.
//
// Learn more about model development with Stan at:
//
// http://mc-stan.org/users/interfaces/rstan.html
// https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
//
data {
int<lower=0> K;
int y1[K];
int y2[K];
real<lower=0> sens1shape[2];
real sens1limits[2];
real<lower=0> sens2shape[2];
real sens2limits[2];
real<lower=0> spec1shape[2];
real spec1limits[2];
real<lower=0> spec2shape[2];
real spec2limits[2];
real<lower=0> pd1shape[2];
real<lower=0> pd2shape[2];
}
parameters {
real<lower=0, upper=1> sens1;
real<lower=0, upper=1> sens2;
real<lower=0, upper=1> spec1;
real<lower=0, upper =1> spec2;
real<lower=0, upper=1> pd1;
real<lower=0, upper=1> pd2;
}
transformed parameters {
simplex[4] p1;
simplex[4] p2;
real<lower=sens1limits[1], upper=sens1limits[2]> sens1_transformed;
real<lower=sens2limits[1], upper=sens2limits[2]> sens2_transformed;
real<lower=spec1limits[1], upper=spec1limits[2]> spec1_transformed;
real<lower=spec2limits[1], upper=spec2limits[2]> spec2_transformed;
sens1_transformed = sens1*(sens1limits[2] - sens1limits[1]) + sens1limits[1];
sens2_transformed = sens2*(sens2limits[2] - sens2limits[1]) + sens2limits[1];
spec1_transformed = spec1*(spec1limits[2] - spec1limits[1]) + spec1limits[1];
spec2_transformed = spec2*(spec2limits[2] - spec2limits[1]) + spec2limits[1];
p1[1] = (1 - sens1_transformed)*(1 - sens2_transformed)*pd1 + spec1_transformed*spec2_transformed*(1 - pd1);
p1[2] = pd1*sens2_transformed*(1 - sens1_transformed) + (1 - pd1)*spec1_transformed*(1 - spec2_transformed);
p1[3] = pd1*sens1_transformed*(1 - sens2_transformed) + (1 - pd1)*spec2_transformed*(1 - spec1_transformed);
p1[4] = sens1_transformed*sens2_transformed*pd1 + (1 - spec1_transformed)*(1 - spec2_transformed)*(1 - pd1);
p2[1] = (1 - sens1_transformed)*(1 - sens2_transformed)*pd2 + spec1_transformed*spec2_transformed*(1 - pd2);
p2[2] = pd2*sens2_transformed*(1 - sens1_transformed) + (1 - pd2)*spec1_transformed*(1 - spec2_transformed);
p2[3] = pd2*sens1_transformed*(1 - sens2_transformed) + (1 - pd2)*spec2_transformed*(1 - spec1_transformed);
p2[4] = sens1_transformed*sens2_transformed*pd2 + (1 - spec1_transformed)*(1 - spec2_transformed)*(1 - pd2);
}
model {
sens1 ~ beta(sens1shape[1], sens1shape[2]);
spec1 ~ beta(spec1shape[1], spec1shape[2]);
sens2 ~ beta(sens2shape[1], sens2shape[2]);
spec2 ~ beta(spec2shape[1], spec2shape[2]);
pd1 ~ beta(pd1shape[1], pd1shape[2]);
pd2 ~ beta(pd2shape[1], pd2shape[2]);
y1 ~ multinomial(p1);
y2 ~ multinomial(p2);
}