I'm trying to specify a model in JAGS/rjags with one between subjects factor (a, with two levels - Y, N) interacting with one repeated measures continuous variable x plus subject varying slopes and intercepts that correlate. I can specify this model simply enough with the lmer function:
lmer(y ~ a + x + a:x + (1 + a | id))
My JAGS/rjags is very rusty (or very fresh). The below seems to me to be fitting a model with subject varying intercepts and subject varying slopes while estimating the slope for both levels of a, but I'm not sure I'm doing what I think I'm doing. There's also no correlation specified between the two.
modelstring = "
model {
for ( i in 1:Ntotal ) {
y[i] ~ dnorm( mu[i] , tau )
mu[i] <- a1[aLvl[i]] + s1[sLvl[i]] + a2[aLvl[i]] * x[i] + s2[sLvl[i]] * x[i]
}
# Prior:
tau <- pow( sigma , -2 )
sigma ~ dunif(0,1000)
for ( j in 1:2 ) {
a1[j] ~ dnorm( 0.0 , aTau )
a2[j] ~ dnorm( 0.0 , aTau )
}
aTau <- 1 / pow( aSD , 2 )
aSD <- abs( aSDunabs ) + .1
aSDunabs ~ dt( 0 , 1.0E-7 , 2 )
#
for ( j in 1:NsLvl ) {
s1[j] ~ dnorm( 0.0 , sTau )
s2[j] ~ dnorm( 0.0 , sTau )
}
sTau <- 1 / pow( sSD , 2 )
sSD <- abs( sSDunabs ) + .1
sSDunabs ~ dt( 0 , 1.0E-7 , 2 )
}
"
The framework for this comes from Kruschke and this has been of some help too. I would appreciate some pointers or links to examples of similar analyses.