# 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]")
Run the code above in your browser using DataLab