-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjagsboralmodel.txt
28 lines (20 loc) · 1.07 KB
/
jagsboralmodel.txt
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
model {
## Data Level ##
for(i in 1:n) {
for(j in 1:p) { eta[i,j] <- inprod(lv.coefs[j,2:(num.lv+1)],lvs[i,]) + inprod(X.coefs[j,],X[i,]) }
for(j in 1:p) { Z[i,j] ~ dnorm(lv.coefs[j,1] + eta[i,j], 1) }
for(j in 1:p) { y[i,j] ~ dbern(step(Z[i,j])) }
}
## Latent variables ##
for(i in 1:n) { for(k in 1:num.lv) { lvs[i,k] ~ dnorm(0,1) } }
## Process level and priors ##
for(j in 1:p) { lv.coefs[j,1] ~ dnorm(0,0.01) } ## Separate species intercepts
for(i in 1:(num.lv-1)) { for(j in (i+2):(num.lv+1)) { lv.coefs[i,j] <- 0 } } ## Constraints to 0 on upper diagonal
for(i in 1:num.lv) { lv.coefs[i,i+1] ~ dunif(0,20) } ## Sign constraints on diagonal elements
for(i in 2:num.lv) { for(j in 2:i) { lv.coefs[i,j] ~ dnorm(0,0.05) } } ## Free lower diagonals
for(i in (num.lv+1):p) { for(j in 2:(num.lv+1)) { lv.coefs[i,j] ~ dnorm(0,0.05) } } ## All other elements
for(j in 1:p) { X.coefs[j,1] ~ dnorm(0,1) }
for(j in 1:p) { X.coefs[j,2] ~ dnorm(0,1) }
for(j in 1:p) { X.coefs[j,3] ~ dnorm(0,1) }
for(j in 1:p) { X.coefs[j,4] ~ dnorm(0,1) }
}