Hi Perry,
Thank you for responding and apologies for the confusion. It seems that having J.r in the constants fixed that issue. But, now im dealing with some initialization issues that I'm not sure how to handle. Below is the error and the code for the model along with the initial values I've already stated.
Thank you and apologies, I'm very new to NIMBLE.
-Dave
> model <- nimbleModel(
+ code = acoustic_model,
+ constants = constants_list,
+ data = Wolfe14.data,
+ inits = inits
+ )
Defining model
Building model
Setting data and initial values
Running calculate on model
[Note] Any error reports that follow may simply reflect missing values in model variables.
Checking model sizes and dimensions
[Note] This model is not fully initialized. This is not an error.
To see which variables are not initialized, use model$initializeInfo().
For more information on model initialization, see help(modelInitialization).
> model$initializeInfo()
[Note] Missing values (NAs) or non-finite values were found in model variables: lifted_oPdelta_oBs_comma_A_times_oBs_comma_j_cB_cB_times_N_oBs_cB_plus_omega_cP_times_phi_oBs_comma_A_times_oBs_comma_j_cB_cB_times_y_oBs_comma_A_times_oBs_comma_j_cB_cB_L29, K, lifted_v_oBsites_a_oBs_cB_comma_val_times_oBs_comma_j_cB_cB_minus_K_oBs_comma_j_cB_L33.
[Note] This is not an error, but some or all variables may need to be initialized for certain algorithms to operate properly.
[Note] For more information on model initialization, see help(modelInitialization).
# Initial Values
inits <- list(
# Abundance
N = rep(1, S),
beta0 = rnorm(1, 0, 1),
beta1 = rnorm(1, 0, 1),
beta2 = rnorm(1, 0, 1),
# Detection
alpha0 = 0,
mu_alpha = 0.5,
alpha1 = runif(1, 0, 1),
alpha2 = rnorm(1, 0, 1),
alpha3 = rnorm(1, 0, 1),
# Vocalization
omega = runif(1, 0, 1),
gamma0 = log(10),
# Survey random effect
Jraneff = rep(0, J_A),
mu_j = 1,
tau_j = 1,
# Overdispersion
mu_phi = 1,
tau_phi = 1,
phi = matrix(1, nrow = S, ncol = J_A)
)
# -----------------------------
# Model Statement
# -----------------------------
acoustic_model <- nimbleCode({
# ----------------------
# Abundance Priors
# ----------------------
# Intercept
beta0 ~ dnorm(0, 1)
# Covariate effect
beta1 ~ dnorm(0, 1)
beta2 ~ dnorm(0, 1)
# ------------------------
# Detection Priors
# ------------------------
# Intercept
alpha0 <- logit(mu_alpha)
mu_alpha ~ dunif(0, 1)
# True individuals
alpha1 ~ dunif(0, 1000)
# Covariate effect
alpha2 ~ dnorm(0, 1)
alpha3 ~ dnorm(0, 1)
# ------------------------
# Call Rate Priors
# ------------------------
# False positive rate
omega ~ dunif(0, 1000)
# Intercept
gamma0 ~ dunif(log(1), log(60))
# Survey random effect
mu_j ~ dgamma(0.01, 0.01)
tau_j ~ dgamma(0.01, 0.01)
for (j in 1:n_days) {
Jraneff[j] ~ dnorm(0, tau_j)
}
# Overdispersion
mu_phi ~ dgamma(0.01, 0.01)
tau_phi ~ dgamma(0.01, 0.01)
for (j in 1:J_A) {
phi[s, j] ~ dgamma(mu_phi, tau_phi)
}
}
# ------------------------
# Likelihood and Process Model
# ------------------------
# ---------------------------------
# Abundance Submodel
# ---------------------------------
# Poisson
log(lambda[s]) <- beta0 + beta1 * X_abund[s, 7] + beta2 * X_abund[s, 12]
N[s] ~ dpois(lambda[s])
# Survey
for (j in 1:J_A) {
# ---------------------------------
# Detection Submodel
# ---------------------------------
# True Positives + Vegetation Density + Wind
logit(p_a[s, j]) <- alpha0 + alpha1 * N[s] + alpha2 * X_abund[s, 21] + alpha3 * X_det[j, 2]
# ---------------------------------
# Call rate Submodel
# ---------------------------------
# Intercept + Survey Random Effect
log(delta[s, j]) <- gamma0 + Jraneff[j]
# ---------------------------------
# Observations
# ---------------------------------
y[s, j] ~ dbin(p_a[s, j], 1)
# ---------------------------------
# True Positives
# ---------------------------------
tp[s, j] <- delta[s, j] * N[s] / (delta[s, j] * N[s] + omega)
} # End J
# ---------------------------------
# Vocalizations
# ---------------------------------
# Surveys with Vocalizations
for (j in 1:J_r[s]) {
# Zero Truncated Negative Binomial
v[s, A_times[s, j]] ~ T(dpois((delta[s, A_times[s, j]] * N[s] + omega) * phi[s, A_times[s, j]] * y[s, A_times[s, j]]), 1, )
}# End J_R
} # End S
# ------------------------
# Manual Validation
# ------------------------
for (s in 1:S_val) {
for (j in 1:J_val[s]) {
K[s, j] ~ dbin(tp[sites_a[s], j], v[sites_a[s], val_times[s, j]])
k[s, val_times[s, j]] ~ dhyper_nimble(K[s, j], v[sites_a[s], val_times[s, j]] - K[s, j], n[s, val_times[s, j]])
} # End J
} # End S
# -------------------------------------------
# Derive Parameters
# -------------------------------------------
# Abundance
N_tot <- sum(N[1:S])
})
# ---------------------------- End Model ----------------------------