Solved – JAGS: unobserved parents and intialization

jags

I have a very simple multinomial logistic regression problem; it's a simplified version of the alligator lake/food/size BUGS example. In my case I have (effectively) lake/food and have just stripped down the alli.bug example to handle two dimensional information: worker and IP address. There are 18 categories of 'worker' and 23 categories of 'IP address'.

Unfortunately I am getting an error

  Error in node X[1,1:23] Observed node inconsistent with 
                     unobserved parents at initialization

Granted, there is a strong possibility I've more than one bug, but I understand that this is typically associated with an initialization problem. Unfortunately, my initialization matrices are rather large. A shotgun approach to finding appropriate values seems unlikely to succeed within a reasonable period of time.

Any hints or suggestions about possible next steps would be greatly appreciated.

EDIT:
Here's the code. As I mentioned, it's just a stripped down version of the Alligator example. I've also fiddled with the subscripts on X[i,] a bit so the error message may be slightly different (will refer to node X[1,1] rather than X[1,1:23]).

var
 X[I,K],      # observations I=no of workers=18, K=no of jobs=23
 n[I],        # total for each covariate pattern
 E[I,K],      # fitted values
 OlogOE[I,K], # O log O/E
 G2,            # goodness-of-fit statistic
 phi[I,K],    # exp (beta[k] ' x[i,j])
 p[I,K],      # fitted probabilities
 alpha[K],      # factor for jobs = 2,...,23
 beta[I,K],     # factor for workers = 2,...,18  for each job
 b[I,K];         # factor for workers = 2,..,,18, relative to job 1, centred
model {
# PRIORS
   alpha[1] <- 0;       # zero contrast for baseline workers
   for (k in 2:K){
      alpha[k] ~ dnorm(0,0.001);  # vague priors
   }
   # Loop around jobs:
   for (k in 1:K){
      beta[1,k] <- 0;   # corner-point contrast with first worker 
   } 
   for (i in 2:I) {     
      beta[i,1] <- 0;   # zero contrast for baseline worker
      for (k in 2:K) {
         beta[i,k] ~ dnorm(0,0.001); # vague priors
      }
   }

# LIKELIHOOD

   for (i in 1:I) {                 # loop around workers
      for (k in 1:K) {           # loop around jobs
   # Multinomial response
         X[i,k] ~ dmulti(p[i,k] , n[i]);
            p[i,k]        <- phi[i,k] / sum(phi[i,]);
            log(phi[i,k]) <- alpha[k] + beta[i,k];
         }
      }  

# FITTED VALUES
   for (i in 1:I) {     # loop around worker
         for (k in 1:K) {     # loop around jobs
            E[i,k] <- p[i,k] * n[i];
            OlogOE[i,k] <- X[i,k] * log( X[i,k] / E[i,k] );
         } 
   }
   G2 <- 2 * sum( OlogOE[,] );
} 

Best Answer

The next step with this particular error message should (always ?) be to check the specific node mentioned in the error message and its parents. This sounds like a lot of work when you have large matrices of initial values but the point is that you are likely making a small number of mistakes in generating those values. Each time you trace the error message to a particular problematic node you will be able to eliminate at least one mistake and fix a lot of bad initial values.

In this case your model is simple enough that having alpha/beta initialized to all zeros should take care of most problems. If alpha/beta are zero then the derived values for phi/p would be consistent with all non-negative X's which means the only inconsistency left is that sum(X[i,]) != n[i]...