-
Notifications
You must be signed in to change notification settings - Fork 0
/
concord-7.5.stan
107 lines (87 loc) · 2.58 KB
/
concord-7.5.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Concordance model 7.4: Impute SES using the low-quality proxy and medicaid status
functions {
real logodds(data int [] X, data int N) {
real Nx = sum(X);
real px = Nx / N;
print("\tNx: ", Nx, " px: ", px, " logit(px): ", logit(px));
return logit(px);
}
}
data {
int<lower=0> N;
int<lower=0, upper=1> S[N];
int<lower=0, upper=1> H[N];
int<lower=0, upper=1> O[N];
int<lower=0, upper=1> D[N];
}
transformed data {
real ao0;
real ad0;
print("Calc ao0");
ao0 = logodds(O, N); // base rate outcome
print("Calc ad0");
ad0 = logodds(D, N); // base rate medicaid
print("ad0 = ", ad0);
}
parameters {
real bsu; // sex effect on mean SES
real bhu; // HNW effect on mean SES
real<lower=0> bud; // SES effect on medicaid, presumed positive (together with the
// sign convention below, this implies higher SES lowers the prob.
// of being enrolled in medicaid.
real ad; // base rate medicaid
real ao; // base rate for outcome
real bso; // sex effect on outcome
real bho; // HNW effect on outcome
real buo; // SES effect on outcome.
real uSES[N];
}
model {
vector[N] SES_mean; // latent socioeconomic status
vector[N] pO; // accumulator variable for outcome probability
vector[N] pD; // accumulator for other var probabilities.
// priors for all parameters
bsu ~ normal(0, 0.5);
bhu ~ normal(0, 0.5);
bud ~ normal(0, 0.5);
ad ~ normal(0, 0.5);
ao ~ normal(0, 0.5);
bso ~ normal(0, 0.5);
bho ~ normal(0, 0.5);
buo ~ normal(0, 0.5);
// latent SES variable
for (i in 1:N) {
SES_mean[i] = bsu*S[i] + bhu*H[i];
}
uSES ~ normal(SES_mean, 1.0);
// medicaid: base rate + SES effect.
for (i in 1:N) {
pD[i] = ad - bud*uSES[i]; // Effect of higher SES presumed to be negative.
}
D ~ bernoulli_logit(pD);
// outcome
for (i in 1:N) {
pO[i] = ao + bso*S[i] + bho*H[i] + buo*uSES[i];
}
O ~ bernoulli_logit(pO);
}
generated quantities {
real ADCE_H; // Average direct causal effect of H
real ADRR_H; // Average direct relative risk due to H
{
real lp0; // logit of p when H==0
vector[N] p_h0; // p(O | do(H==0))
vector[N] p_h1; // p(O | do(H==1))
vector[N] rr; // relative risk
for (i in 1:N) {
lp0 = ao + bso*S[i] + buo*uSES[i];
p_h0[i] = inv_logit(lp0);
p_h1[i] = inv_logit(lp0 + bho);
}
ADCE_H = mean(p_h1 - p_h0);
for(j in 1:N) {
rr[j] = p_h1[j] / p_h0[j];
}
ADRR_H = mean(rr);
}
}