Menu

Hierarchical logistic regression

Help
Anonymous
2011-02-18
2012-09-01
  • Anonymous

    Anonymous - 2011-02-18

    Hi,

    I am currently learning to use JAGS with rjags. I am starting by trying to
    replicate some of the WinBUGS code and results from Royle and Dorazio's
    Hierarchical Modeling and Inference in Ecology. The current model I am trying
    to fit is a fairly simple hierarchical logistic regression. I am getting
    stumped by an error message:

    Error in node y

    Observed node inconsistent with unobserved parents at initialization

    At other times the error has occured in y or y, but these three nodes are the
    first 3 non-zero nodes in the y variable. The model specification I am using
    is:

    model{
            for(i in 1:M){
                z[i]~ dbern(psi[i])
                psi[i] <- ilogit( b0+b1*elev[i]+b2*elev2[i]+b3*forest[i])
                y[i]~dbin(z[i]*p,J[i])
                }
            p~dunif(0,1)
            b0~dnorm(0,.001)
            b1~dnorm(0,.001)
            b2~dnorm(0,.001)
            b3~dnorm(0,.001)
    
        }
    

    I have posted my r code and the data here:
    https://public.me.com/pokey54

    Any help in interpreting or troubleshooting this error is appreciated.

    Thanks!

     
  • Martyn Plummer

    Martyn Plummer - 2011-02-18

    In your code you are randomly initializing the latent variable z to be 0 or 1.
    But if z = 0 then y = 0. The problem arises because you've got some non-zero y
    values with zero z.

    To fix the code, modify your initial values for z from this

    z=rbinom(M,1,.4)
    

    to this

    z=ifelse(y>0, 1, rbinom(M, 1, 0.4))
    
     

Log in to post a comment.