[R-sig-ME] BUGS/JAGS: prior for a 2D random effect
Andrew Digby
andrewdigby at mac.com
Thu Nov 1 06:28:23 CET 2012
I'm writing a hierarchical BUGS/JAGS model with two 'for' loops, and want to include nested random effects, a1 & a2 (nested in a1). But I can't work out how to specify the prior for the nested random effect. This doesn't work:
model{
for (i in 1:N){
for (j in 1:M){
...
eta[j,i] <- alpha + b[1]*Var1[j,i] + ... + a1[i] + a2[j,i]
}
}
for (i in 1:N){a1[i] ~ dnorm(0.0, tau1} # Prior for random effect a1
# This next part, specifying the prior for random effect a2, is wrong, but what should it be:?
for (i in 1:N){
for (j in 1:M){
a2[j, i] ~ dnorm(0.0, tau2}
}
}
}
inits <- function(){
list ( ...
a1 = rnorm(N, 0, 1),
a2 = matrix(rnorm(N*M, 0, 1), nrow=M, ncol=N),
...
)
}
Apologies for the lack of reproducible example, but this is just a syntax issue. How do I specify the prior for the nested random effect a2? I can't find the answer to this anywhere. I know I can reduce this to just one 'for' loop, but don't want to for other reasons (I later want to introduce an AR1 structure within one loop).
Thanks very much,
Andrew
More information about the R-sig-mixed-models
mailing list