user3767071
user3767071

Reputation: 109

Rjags Invalid parent value error with use of hyper prior

I'm using rjags to calculate a species abundance using an N-mixture model and count data. To capture over dispersion of my data, I used hyperpriors. But I get an

"Error in node S[1,1,2] Invalid parent values"

My guess is that I have a problem in the dimension of my prior OR one of the prior is negative, null or NA which stops the calculation of node S.

Any idea how to stop this problem ? Is it possible to initialize S?

model {
##  PRIORS ##

lambda[1] ~ dunif(0, 500)
lambda[2] ~ dunif(0, 500) 
p[1] ~ dunif(0, 1)
p[2] ~ dunif(0, 1)
# surdispersion
muepsomega1 ~ dnorm(0,0.0001)
sigepsomega1 ~ dunif(0,100)
iomega1 ~ dnorm(0,0.0001)
tauepsomega1 <- 1/(sigepsomega1*sigepsomega1) 
omega2 ~ dunif(0, 1)

## LIKELIHOOD ##
# Create a loop across all j sites
for(j in 1:nSites) {

# surdispersion sur omega 1
omega1[j] <- iomega1 + epsomega1[j]
epsomega1[j] ~ dnorm(muepsomega1,tauepsomega1)

N[1,j,1] ~ dpois(lambda[1]) 
N[2,j,1] ~ dpois(lambda[2])

for (i in 1:3) {    
  S[i,j,1] ~ dnegbin(2, 1) 
  } # end loop i
for(t in 2:nYears) {
  # Estimate survivorship (between year survival)
  S[1,j,t] ~ dnegbin(omega1[j], N[1,j,t-1])  
  S[2,j,t] ~ dnegbin(omega2, N[2,j,t-1]) 

  N[1,j,t] <- S[1,j,t] 
  N[2,j,t] <- S[2,j,t] 
  } # end loop t in 2:years

# Loop across sampling replicates to estimate detection
for (t in 1:nYears){
  for(k in 1:nReps){
    n[1,j,k,t] ~ dnegbin(p[1], N[1,j,t]) 
    n[2,j,k,t] ~ dnegbin(p[2], N[2,j,t]) 

   } # end loop k nreps
  } # end loop j sites
}

This is how I call the model:

#Model file
modFile = "model/2016-07-12/model_Nmix.R"

inits <- function(){
list('lambda' =c(1,1), 'p'= c(1,1),'omega2' = 1,'iomega1'=1, 'muepsomega1'= 1, 'sigepsomega1'= 1, 'epsomega1'=c(1,1,1,1,1,1,1)) } # size epsomega1 is length(nSites)=7

 # Compile the model
 require(rjags)
 abundance.out <- jags.model(file=modFile, data=data,n.chains = 3, n.adapt = 3000)

Upvotes: 0

Views: 449

Answers (1)

Jacob Socolar
Jacob Socolar

Reputation: 1202

Let epsomega1 and iomega1 come from distributions that don't have any probability density over negative values. Gamma, uniform, log-normal, or truncated normal distributions are candidates, and your choice should depend on what you think the most correct model specification actually is.

Upvotes: 0

Related Questions