user3019492
user3019492

Reputation: 51

this chain contains uninitialized variables

I get "this chain contains uninitialized variables" when I load inits for 3 chains with the attached model. I hit "gen init" to keep going on. Is that a right thing to do? It does not happen with fixed model but tend to happen with random models. Please advise.

#BUGS model
model{ 
for(i in 1:ns){ 
  w[i,1] <- 0 
  delta[i,1] <- 0 
  mu[i] ~ dnorm(0,.0001) 
  for (k in 1:na[i]) { 
    r[i,k] ~ dpois(theta[i,k]) 
    theta[i,k] <- lambda[i,k]*E[i,k] 
    log(lambda[i,k]) <- mu[i] + delta[i,k] 
    dev[i,k] <- 2*((theta[i,k]-r[i,k]) + r[i,k]*log(r[i,k]/theta[i,k])) 
  }
  resdev[i] <- sum(dev[i,1:na[i]]) 
  for (k in 2:na[i]) { 
    delta[i,k] ~ dnorm(md[i,k],taud[i,k]) 
    md[i,k] <- d[t[i,k]] - d[t[i,1]] + sw[i,k] 
    taud[i,k] <- tau *2*(k-1)/k 
    w[i,k] <- (delta[i,k] - d[t[i,k]] + d[t[i,1]]) 
    sw[i,k] <- sum(w[i,1:k-1])/(k-1) 
  }
}
for (c in 1:(nt-1)) {
  for (k in (c+1):nt) {
    lhr[c,k] <- (d[k]-d[c])
    log(hr[c,k]) <- lhr[c,k]
  }
}
totresdev <- sum(resdev[]) 
d[1]<-0 
for (k in 2:nt){ 
  d[k] ~ dnorm(0,.0001)
} 
sd ~ dunif(0,5) 
tau <- pow(sd,-2) 
} 

#data
list(ns=9, nt=9)                                                    
t[,1]   t[,2]   t[,3]   t[,4]   E[,1]   E[,2]   E[,3]   E[,4]   r[,1]   r[,2]   r[,3]   r[,4]   na[]    
1   2   3   4   224 226 221 223 19  11  15  7   4   
2   5   NA  NA  818 806 NA  NA  83  73  NA  NA  2   
2   7   NA  NA  412 429 NA  NA  51  37  NA  NA  2   
1   2   7   NA  4572    4563    4599    NA  869 730 736 NA  3   
1   7   NA  NA  68  137 NA  NA  8.8 13.7    NA  NA  2   
1   6   NA  NA  125 131 NA  NA  4   5       NA  NA  2   
2   8   9   NA  131 128 130 NA  10.6    20.2    18.1    NA  3   
1   2   8   NA  256 255 254 NA  79  73  48  NA  3   
2   8   NA  NA  152 147 NA  NA  38  24  NA  NA  2   
END

#inits
list(d=c(NA, 0, 0, 0, 0, 0, 0, 0, 0), sd=1, mu=c(0, 0, 0, 0, 0, 0, 0, 0, 0))
list(d=c( NA, -1, -1, -1, -1, -1, -1, -1, -1), sd=4, mu=c(-3, -3, -3, -3, -3, -3, -3, -    3, -3))
list(d=c( NA, 2, 2, 2, 2, 2 ,2, 2, 2), sd=2, mu=c(-3, 5, -1, -3, 7, -3, -4, -3, -3))

Upvotes: 3

Views: 6328

Answers (1)

Chris Jackson
Chris Jackson

Reputation: 871

You get this message if you haven't supplied initial values for an unknown parameter. In your case that would be the random effects. It's usually OK to allow WinBUGS to generate initial values for random effects. As a general rule, if the prior is vague, you should specify your own initial values (to avoid numerical overflow problems at the start of sampling). If the prior is informative (as it would be for a random effect if you have initialised the parameters of the random effects distribution at sensible values) you can let WinBUGS do it.

Upvotes: 7

Related Questions