Learn R Programming

MultiNMix (version 0.1.0)

MNM_control: Generate Nimble Code for Multi-Species N-Mixture (MNM) Models

Description

This function generates Nimble code for fitting various Multi-Species N-Mixture (MNM) models. These models can include standard MNM, hurdle components, autoregressive (AR) components, or both hurdle and AR components.

Usage

MNM_control(
  model = "MNM",
  prior_detection_probability = "dnorm(0, 0.001)",
  prior_precision = "dwish(Omega[1:S,1:S], df)",
  prior_mean = "dnorm(0,0.001)",
  prior_mean_AR = "dnorm(0,0.001)",
  prior_sd_AR = "dexp(1)",
  prior_hurdle = "dbeta(1,1)",
  Xp = NULL,
  Xn = NULL
)

Value

Character. Nimble code for the specified MNM model, which can be used for further analysis or fitting.

Arguments

model

Character. Specifies the type of MNM model to generate. Options are:

  • "MNM": Standard MNM model (default)

  • "Hurdle": Hurdle MNM model

  • "AR": Autoregressive MNM model

  • "HurdleAR": Hurdle MNM model with autoregression

prior_detection_probability

Character. Prior distribution for the detection probability intercept (gamma). Default is 'dnorm(0, 0.001)'.

prior_precision

Character. Prior distribution for the precision matrix for the species-level random effect. Default is 'dwish(Omega[1:S,1:S], df)'.

prior_mean

Character. Prior distribution for the mean of the species-level random effect (mu). Default is 'dnorm(0,0.001)'.

prior_mean_AR

Character. Prior distribution for the mean of the autoregressive random effect (phi). Default is 'dnorm(0,0.001)'.

prior_sd_AR

Character. Prior distribution for the standard deviation of the autoregressive random effect (phi). Default is 'dexp(1)'.

prior_hurdle

Character. Prior distribution for theta, the probability of structural zero in hurdle models. Default is 'dbeta(1,1)'.

Xp

Array. Covariates influencing detection probability. Dimensions depend on the model:

  • \(R \times S \times P\) for models without AR

  • \(R \times S \times K \times P\) for AR models where:

  • \(R\): Number of sites

  • \(S\): Number of species

  • \(K\): Number of time points

  • \(P\): Number of covariates

Xn

Array. Covariates influencing abundance. Dimensions depend on the model:

  • \(R \times S \times P\) for models without AR

  • \(R \times S \times K \times P\) for AR models

Details

The generated Nimble code can be used to fit Bayesian hierarchical MNM models. Users can specify prior distributions for key model parameters and provide covariate arrays that influence detection probability and abundance. The function validates prior specifications and adapts model code based on the selected model type. Supported models include:

  • MNM: Standard MNM model

  • Hurdle: MNM model with a hurdle component

  • AR: MNM model with an autoregressive component

  • HurdleAR: MNM model with both hurdle and AR components

This is an internal function, needed for implementing MNM models using the MNM_fit function. While the MNM_fit function allows the user to define prior distributions and linear covariates on detection probability and abundance, if the user wishes to implement more complex models in Nimble (via unsupported prior distributions or non-linear covariate effects), the Nimble model code may be extracted as in examples below, and modified by the user.

Examples

Run this code
# Example
# In order to implement scenarios involving nonlinear covariate effects or complex
#  interaction terms, the user is invited to extract and modify the MNM Nimble code:
model<-MNM_control(model="MNM")
cat(model)

Run the code above in your browser using DataLab