3
$\begingroup$

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[,] );
} 
$\endgroup$
  • $\begingroup$ Try not initializing the parameters for that node (which may be all the parameters in the model) and let JAGS pick the initial values for you; if it fails, we can think of something else. $\endgroup$ – jbowman May 16 '12 at 15:48
  • $\begingroup$ Sorry, I should have mentioned that I tried that. I also tried a few different SEED values. Finally, I'm not sure how relevant it is, but I should mention that my data matrix X[,] is very sparse (mostly 0's) - which may give me problems later. $\endgroup$ – Aengus May 16 '12 at 15:53
  • $\begingroup$ If your code isn't too long, could you post it? $\endgroup$ – jbowman May 16 '12 at 18:24
  • $\begingroup$ is the etiquette to add it as an edit to the original post or to post it in comments? $\endgroup$ – Aengus May 16 '12 at 21:40
  • 1
    $\begingroup$ stats.stackexchange.com/q/17121/5509 $\endgroup$ – Curious Apr 27 '14 at 20:54
1
$\begingroup$

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]...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.