Hi, I'm trying to get an occupancy model for a large dataset to converge and am running into memory usage issues. I can't run the chains for enough iterations to achieve convergence without getting an error along the lines of "Can't allocate vector of size X GB". I was wondering if anyone had any suggestions, whether it's increasing sampling efficiency or reducing the amount of memory used.
Thank you in advance!
Kelley
I have included the model code below, along with some details about the size of the data.
code <- nimbleCode({
#Estimate psi for each site
for (i in 1:nsites) {
logit(psi[i]) <- alpha0 + beta*X1[i] + gamma*X2[i] + delta*X3[i]
z[i] ~ dbern(psi[i])
}
#Estimate p for each observation
for (j in 1:nsites.visits) {
logit(p[j]) <- obs[IDobs[j]] + zeta*Y1[j] + eta*Y2[j] + mos[IDmos[j]] + yr[IDyr[j]]
p.temp[j] <- z[Site[j]] * p[j]
h[j] ~ dbern(p.temp[j])
}
#Priors
alpha0 ~ dunif(-5, 5) #intercept for occupancy
beta ~ dunif(-5, 5) # occupancy coefficient associated with population density
gamma ~ dunif(-5, 5) #occupancy coefficient associated with temperature
delta ~ dunif(-5, 5) # occupancy coefficient associated with area
zeta ~ dunif(-5, 5) # detection coefficient associated with whether collector has previously collected the species
eta ~ dunif(-5, 5) # detection coefficient associated with whether collector is a citizen scientist
#Random effect of collector
for(j in 1:nobs) {
obs[j] ~ dnorm(0, tau=tauobs)
}
#Random effect of month
for(k in 1:nmos){
mos[k] ~ dnorm(0, tau=taumos)
}
#Random effect of year
for(l in 1:nyr){
yr[l] ~ dnorm(0, tau=tauyr)
}
#Hyperpriors
tauobs ~ dgamma(0.01, 0.01)
taumos ~ dgamma(0.01, 0.01)
tauyr ~ dgamma(0.01, 0.01)
#Derived parameter
N <- sum(z[])
})
monitors <- c("N","psi", "p", "alpha0","beta", "gamma", "delta", "zeta",
"eta", "obs", "mos", "yr", "tauobs",
"taumos", "tauyr") # parameters to monitor
#N: the number of sites occupied (1 value)
#psi: Occupancy (67 values)
#p: Detection probability (24240 values, one for each site visit)
#alpha0: Occupancy intercept (1 value)
#beta: occupancy coefficient (1 value)
#gamma: occupancy coefficient (1 value)
#delta: occupancy coefficient (1 value)
#zeta: detection coefficient (1 value)
#eta: detection coefficient (1 value)
#obs: random effect of collector (762 values)
#mos: random effect of month (12 values)
#yr: random effect of year (124 values)
#tauobs: hyperprior associated with random effect of collector
#taumos: hyperprior associated with random effect of month
#tauyr: hyperprior associated with random effect of year
initsFx <- function() {
list(
z = rep(1, nsites),
beta = rnorm(1),
gamma = rnorm(1),
delta = rnorm(1),
zeta = rnorm(1),
eta = rnorm(1),
alpha0 = rnorm(1),
obs = rnorm(nobs),
mos = rnorm(nmos),
yr = rnorm(nyr),
tauobs = rlnorm(1),
taumos = rlnorm(1),
tauyr = rlnorm(1)
)
}
nimbleOptions(clearNimbleFunctionsAfterCompiling=T)
mcmc1 <- nimbleMCMC(
code = code, constants = constants, data = data,
monitors = monitors, inits = initsFx,
nchains = 1, niter = 102686, nburnin = 1000, thin = 1,
summary = T, WAIC = F, samplesAsCodaMCMC = TRUE
)