-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_jags_model_mrp.jags
39 lines (34 loc) · 1014 Bytes
/
3_jags_model_mrp.jags
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
###John Spaw
###Multi-level regression (binary) with post-stratification (state level)
###Model definition for fit in JAGS Gibbs sampler
data {
for (i in 1:num_state) {
census_sum[i] <- sum(census_count[,i])
}
}
model {
#individual level responses
#i indexes individuals from survey
for (i in 1:num_y) {
y[i] ~ dbern(p[i])
logit(p[i]) <- inprod(x[i,], beta[,state[i]])
}
#set priors on linear predictors for each state
for (i in 1:num_state) {
beta[1:num_x, i] ~ dmnorm(gamma %*% state_x[,i], tau)
}
#Linear priors
#priors for mean of linear coefficients
for (i in 1:num_x) {
gamma[i,1:num_state_x] ~ dmnorm(gamma_mean, gamma_prec)
}
#prior for precision (reciprocal of variance) of linear coefficients
tau ~ dwish(tau_R, tau_k)
#State level predictions
for (i in 1:num_state) {
for (j in 1:num_cells) {
logit(p_cell[j,i]) <- inprod(pred_x[j,], beta[,i])
}
predict[i] <- inprod(p_cell[,i], census_count[,i]) / census_sum[i]
}
}