occupancy-model runMCMC returning logProb is NA or NaN warnings

180 views
Skip to first unread message

Gonçalo Ferraz

unread,
Dec 8, 2023, 3:46:14 PM12/8/23
to nimble-users
Hello,

I am trying to fit the single-season, single species occupancy model bellow to a dataset with more than 8000 sites and hundreds of thousands of observations. Because there are so many observations, I am vectorializing the detection part. The model, thus, uses a single data object, called y1, which has 785,718 elements, all equal to 0 or 1.

The problem is that function 'runMCMC' is returning many (hundreds) of warnings of the sort:

'logProb of data node y[66057]: logProb is NA or NaN

Im pasting the model code below. Some details of the occupancy part may look funny because this is set up to add a CAR component later on. Likewise, aspects of the detection code may look funny because it is set up for integration of different data sources on a later stage. But still, I would really like to see this simplified version working without the strange warnings.

I am initializing with a vector of ones and zeros that has as many elements as sites and has z=1 for every site where my focal species was seen.

I am new with NIMBLE, so it is quite possible that I am doing something dumb. I will be thankful if anyone can spot anything obviously wrong in the model code below.

Thank you,

Gonçalo

# Write NIMBLE model ----
Model0b_RQmap <- nimbleCode({
 
  ## Priors
  beta0 ~ dnorm(0, tau = 0.01)
  alpha1 ~ T(dnorm(0, tau = 0.01),0,10) # tried truncating at 10,..., 10000
  # truncating at 10 seems too restrictive, but I tried just to see if warnings kept coming 
 
  ## Likelihood
  # Cell-specific occupancy
  for(i in 1:ncell) { # loop over grid cells
    z[i] ~ dbern(psi[i]) # True occupancy z at site i  
    # put guard rails on the variation of psi[i]
    mu.lim[i] <- min(10, max(-10, mu[i]))  
    logit(psi[i]) <- mu.lim[i]
    # linear function for logit(psi[i]) - will have CAR at later stage
    mu[i] <- beta0      
  }
  # visit-specific detection of the focal species for one data source
  for(j in 1:nobs1) { # loop over observations
    e1[j] <- alpha1*nsps[j] # detection parameter e1 as function of n sps seen in visit 
    p1[j] <- 1 - pow((1-0.5),e1[j])
    zp1[j] <- p1[j]*z[cellID[j]]
    y1[j] ~ dbern(zp1[j])
  }
 
})
  

Daniel Turek

unread,
Dec 8, 2023, 4:17:48 PM12/8/23
to Gonçalo Ferraz, nimble-users
Gonçalo, can you send a reproducible example (an R script), and include either the data you're using, or proxy data which replicates this behaviour?

Thanks,
Daniel


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/567965e1-8929-4e82-b555-735a64dd0187n%40googlegroups.com.

Gonçalo Ferraz

unread,
Dec 8, 2023, 4:26:19 PM12/8/23
to nimble-users
Hello, Daniel,
Yes, I am attaching the R script. You can find the rds data files in the link: https://1drv.ms/f/s!Aj_LUGIsVPm6g9ozEACQw6I1QcOaMA?e=eqrrO5
Thanks,
Gonçalo
Code4b_WriteRunNIMBLECode.R

Gonçalo Ferraz

unread,
Dec 9, 2023, 9:25:03 AM12/9/23
to nimble-users
The code above had a mistaken object name. This one should work:
Code4b_WriteRunNIMBLECode.R

Daniel Turek

unread,
Dec 21, 2023, 2:22:45 PM12/21/23
to nimble-users, Gonçalo Ferraz
To loop back on-list, we were able to identify some numerical issues in the original model relating to prior distributions for parameters, proper initial values, and numerical rounding errors that were causing impossible likelihood / data situations.

Cheers,
Daniel




Reply all
Reply to author
Forward
0 new messages