Question

I am trying to fit a hierarchical model using OpenBUGS, with the following code:

model 
{   
for( i in 1:n){
    tausq[i] <- 1/pow(sigma[i], 2)
    psi[i] ~ dnorm(psi, tausq)
    psihat[i] ~ dnorm(psi[i], tausq[i])
}   
psi  ~ dnorm(0, 1000)
tausq ~ dgamma(0.001, 0.001)
sigmasq <- 1/tausq
}

#data

list(n = 12,
psihat = c(1.055, -0.097, 0.626, 0.017, 1.068, -0.025, -0.117, -0.381, 0.507, 0.00,     3.85, 4.05),
sigma = c(0.373, 0.116, 0.229, 0.117, 0.471, 0.120, 0.220, 0.239, 0.186, 0.328, 0.206, 0.254)) 

# initial values

list(psi = 1.5, sigmsq=.1)

But, I get the error 'expected a comma', and OpenBUGS highlights tausg in the psi[i] ~... statement. I am currently at a loss for what I am doing wrong. Other models fit fine, so I don't think this is a larger program issue.

Any hints would be greatly appreciated

Thanks!

Was it helpful?

Solution

You are defining psi and tausq twice which is confusing BUGS. Once as a vector of values (psi[i] ~ and tausq[i] ~) and once as a single values (psi ~ and tausq ~). You need to relabel one or the other,... probably the later to something like psi.mean ~ and tausq.mean ~ or psi0 ~ and tausq0 ~.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top