MNM_fit | R Documentation |
Fits a Multi-Species N-Mixture (MNM) model to observed count data using Nimble, with options to include autocorrelation (AR) and/or hurdle components for advanced ecological modeling.
MNM_fit(
Y = NULL,
AR = FALSE,
Hurdle = FALSE,
Xp = NULL,
Xn = NULL,
verbose = TRUE,
...
)
Y |
Array of observed count data:
|
AR |
Logical. Indicates whether to include an autocorrelation component in the model. Defaults to |
Hurdle |
Logical. Indicates whether to include a hurdle component in the model. Defaults to |
Xp |
An array of covariates affecting detection probability, with dimensions (R, S, P1), where:
|
Xn |
An array of covariates affecting abundance, with dimensions (R, S, P2), where:
|
verbose |
Control the level of output displayed during function execution. Default is TRUE. |
... |
Additional arguments for prior distributions. Supported priors include:
|
This function implements the Bayesian MNM model to estimate latent species abundances and inter-species correlations based on observed count data. Extensions include options for incorporating autocorrelation (AR) to account for temporal dependencies and a hurdle model to handle zero inflation in the data. The input data and covariates must conform to specific dimensional requirements as described below.
The MNM model (Mimnagh et al., 2022) builds upon Royle's (2004) N-mixture model by allowing simultaneous modeling of multiple species, enabling inference about inter-species relationships and correlations.
An MNM object that contains the following components:
summary: Nimble model summary (mean, standard deviation, standard error, quantiles, effective sample size and Rhat value for all monitored values)
n_parameters: Number of parameters in the model (for use in calculating information criteria)
data: Observed abundances
fitted_Y: Predicted values for Y. Posterior predictive checks can be performed by comparing fitted_Y with the observed data.
logLik: Log-likelihood of the observed data (Y) given the model parameters.
n_converged: Number of parameters with successful convergence (Rhat < 1.1).
Ensure that the dimensions of Y
, Xp
, and Xn
match the requirements specified above. Mismatched dimensions will result in errors during model fitting.#'
Royle, J. A. (2004). N-mixture models for estimating population size from spatially replicated counts. Biometrics, 60(1), 108-115.
Mimnagh, N., Parnell, A., Prado, E., & Moral, R. D. A. (2022). Bayesian multi-species N-mixture models for unmarked animal communities. Environmental and Ecological Statistics, 29(4), 755-778.
simulateData
: For generating example datasets compatible with this function.
MNM
: For details on creation of covariate arrays Xp and Xn.
# Example 1: Fit a standard MNM model
Y <- array(data = rpois(60, lambda = 5), dim = c(3, 5, 4)) # Simulated counts
Xp <- array(data = rnorm(60), dim = c(3, 4, 2)) # Detection covariates
Xn <- array(data = rnorm(60), dim = c(3, 4, 2)) # Abundance covariates
model <- MNM_fit(Y = Y, AR = FALSE, Hurdle = FALSE, Xp = Xp, Xn = Xn)
# nimble creates auxiliary functions that may be removed after model
# run is complete using rm(list = ls(pattern = "^str"))
# Example 2: Fit an MNM model with AR-1 component
Y <- array(data = rpois(180, lambda = 5), dim = c(3, 5, 4, 3)) # Simulated counts
Xp <- array(data = rnorm(180), dim = c(3, 4, 3, 2)) # Detection covariates
Xn <- array(data = rnorm(180), dim = c(3, 4, 3, 2)) # Abundance covariates
model <- MNM_fit(Y = Y, AR = TRUE, Hurdle = FALSE, Xp = Xp, Xn = Xn)
# Example 3: Fit an MNM model with user-specified prior distributions
Y <- array(data = rpois(60, lambda = 5), dim = c(3, 5, 4)) # Simulated counts
Xp <- array(data = rnorm(60), dim = c(3, 4, 2)) # Detection covariates
Xn <- array(data = rnorm(60), dim = c(3, 4, 2)) # Abundance covariates
model <- MNM_fit(Y = Y, AR = FALSE, Hurdle = TRUE, Xp = Xp, Xn = Xn,
prior_detection_probability="dnorm(0.01,0.01)")
# Access traceplots and density plots
tracePlot(model, "N[3, 1]")
density(model, "N[3, 1]")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.