The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
MultinMix
is an R package designed for fitting
Multispecies N-Mixture (MNM) Models (Mimnagh, Niamh, et al. (2022)), a
powerful tool for estimating abundance and occurrence of multiple
species in a hierarchical Bayesian framework.
To install the development version of MultiNMix
, use the
following commands in R:
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
::install_github("niamhmimnagh/MultiNMix") devtools
Here is a quick example to get you started with
MultiNMix
:
library(MultinMix)
# Example data
<- simulateData(model = "MNM")
x <-x$R
R<-x$T
T<-x$S
S<-x$K
K
<- array(rnorm(R * S * 2), dim = c(R, S, 2)) # creating 2 detection probability covariates
Xp <- array(rnorm(R * S *3), dim = c(R, S, 3)) # creating 3 abundance covariates
Xn
# Fit
<- MNM_fit(
fit Y = species_counts,
Xp = Xp,
Xn = Xn,
Hurdle=FALSE,
AR = FALSE,
iterations = 5000, # Number of iterations
burnin = 1000, # Burn-in period
thin = 10, # Thinning interval
prior_detection_probability="dnorm(0,0.01)" # user-defined normal prior distribution
)
# Summarize results
@summary
fit
# Plot diagnostic results by specifying the model and the parameter
tracePlot(fit, param="N[8,1]")
density(fit, param="N[8,1]")
# A list of all available diagnostic plots can be found:
View(y@plot)
MNM_fit()
: Fits a Multispecies N-Mixture Model using
specified data and parameters.tracePlot()
: Generates traceplots of monitored
parameters.density()
: Generates density plots of monitored
parameters.logLik()
: Extracts the log-likelihood of the
model.AIC()
, BIC()
: Computes AIC and BIC values
for model comparison.check_convergence()
: Assesses model convergence using
Gelman-Rubin diagnostics.Detailed documentation and vignettes are available in the package. After installation, access them using:
??MultiNMix
There are two datasets available in the package birds
and the zero-inflated birds_ZI
. Both are a subset of the
North American Breeding Bird Survey dataset
(https://www.pwrc.usgs.gov/BBS/). birds
is a dataframe with
2,880 observations and 13 columns (R=24, T=10, S=20, K=6) while
birds_ZI
is a dataframe with 600 observations and 13
columns (R=15, T=10, S=10, K=4).
In this vignette, we will show the birds
dataset, the
processing steps required and a worked example of it.
data(birds)
head(birds)
Route | Year | English_Common_Name | Stop 1 | Stop 2 | … | Stop 10 |
---|---|---|---|---|---|---|
001 | 2016 | Mourning Dove | 0 | 1 | … | 0 |
007 | 2016 | Mourning Dove | 6 | 4 | … | 5 |
009 | 2016 | Mourning Dove | 0 | 0 | … | 0 |
The birds
dataset is currently a data frame of dimension
(600, 10). It needs to be reformatted into an array of dimension (R=15,
T=10, S=10, K=4) before it can be used with the MultiNMix
functions.
# Data must first be reformatted to an array of dimension (R,T,S,K)
<- 15
R <- 10
T <- 10
S <- 4
K
# Ensure data is ordered consistently
<- birds[order(birds$Route, birds$Year, birds$English_Common_Name), ]
birds
# Create a 4D array with proper dimension
<- array(NA, dim = c(R, T, S, K))
Y
# Map route, species, and year to indices
<- as.numeric(factor(birds$Route))
route_idx <- as.numeric(factor(birds$English_Common_Name))
species_idx <- as.numeric(factor(birds$Year))
year_idx
# Populate the array
<- as.matrix(birds[, grep("^Stop", colnames(birds))])
stop_data
for (i in seq_len(nrow(birds))) {
<- stop_data[i, ]
Y[route_idx[i], , species_idx[i], year_idx[i]]
}
# Assign dimnames
dimnames(Y) <- list(
Route = sort(unique(birds$Route)),
Stop = paste0("Stop", 1:T),
Species = sort(unique(birds$English_Common_Name)),
Year = sort(unique(birds$Year)))
The function MNM_fit
in the MultiNMix
package allows for easy implementation of a multi-species N-mixture
model using data of this format.
<-MNM_fit((Y=Y, AR=FALSE, Hurdle=FALSE)) model
We can then access elements of the model as follows:
@summary # outputs the mean estimate, standard deviation, standard error, 95% credible interval, effective sample size and gelman rubin statistic for each monitored variable
model
@estimates$N # outputs the estimated mean N
model
logLik(model) # estimates the log likelihood of the model
AIC(model)/BIC(model) # outputs the AIC or BIC values
tracePlot(model, param="N[1,1]") # outputs the traceplot of the N[1,1] parameter
density(model, param="N[1,1]") #outputs the density plot for the N[1,1] parameter
Contributions are welcome! If you encounter any issues or have suggestions for improvement, please submit a report or a pull request.
Mimnagh, Niamh, et al. “Bayesian multi-species N-mixture models for unmarked animal communities.” Environmental and Ecological Statistics 29.4 (2022): 755-778.
MultiNMix
was developed as part of research into
multispecies abundance modeling. Special thanks to the creators of
Nimble (r-nimble.org) for their invaluable tools in Bayesian
modeling.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.