Source-linked AI summary
spOccupancy: An R package for single-species, multi-species, and integrated spatial occupancy models
Jeffrey W. Doser, Andrew O. Finley, Marc Kéry, Elise F. Zipkin
TL;DR
Spatial occupancy models must account for imperfect detection, but fitting spatial random effects becomes computationally expensive as the number of locations grows. This paper introduces spOccupancy, a Bayesian R package using nearest-neighbor Gaussian processes; in the warbler case study, spatial models outperformed nonspatial models on WAIC and 10-fold cross-validation, while the NNGP model was much more computationally efficient than the full Gaussian process model.
Problem
Fitting spatial random effects for occupancy models becomes computationally expensive as the number of locations grows, complicating their use with large spatial datasets.
Source: served locations, accounting for… · p. 4Method
spOccupancy is an R package for Bayesian spatial and nonspatial single-species, multispecies, and integrated occupancy models, using nearest-neighbor Gaussian processes for spatial models.
Source: §2 · p. 5, accommodate spatial autocorrelation in… · p. 5Results
The warbler spatial SSOM outperformed its nonspatial alternative on WAIC and 10-fold cross-validation, while its NNGP implementation greatly increased computing efficiency versus the full GP with small differences in estimates and effective sample sizes.
Source: §5.1 · p. 11Takeaways & Limitations
The package is intended to help ecologists and conservation practitioners account for detection biases and spatial autocorrelation in large-scale species-distribution and community-pattern assessments.
Source: §6 · p. 15The Bayesian model specification uses Gaussian priors, so analyses rely on that prior assumption.
Source: probability can vary by site and/or… · p. 6
Abstract
from arXiv · showhide
Occupancy modeling is a common approach to assess spatial and temporal species distribution patterns, while explicitly accounting for measurement errors common in detection-nondetection data. Numerous extensions of the basic single species occupancy model exist to address dynamics, multiple species or states, interactions, false positive errors, autocorrelation, and to integrate multiple data sources. However, development of specialized and computationally efficient software to fit spatial models to large data sets is scarce or absent. We introduce the spOccupancy R package designed to fit single-species, multi-species, and integrated spatially-explicit occupancy models. Using a Bayesian framework, we leverage P\'olya-Gamma data augmentation and Nearest Neighbor Gaussian Processes to ensure models are computationally efficient for potentially massive data sets. spOccupancy provides user-friendly functions for data simulation, model fitting, model validation (by posterior predictive checks), model comparison (using information criteria and k-fold cross-validation), and out-of-sample prediction. We illustrate the package's functionality via a vignette, simulated data analysis, and two bird case studies, in which we estimate occurrence of the Black-throated Green Warbler (Setophaga virens) across the eastern USA and species richness of a foliage-gleaning bird community in the Hubbard Brook Experimental Forest in New Hampshire, USA. The spOccupancy package provides a user-friendly approach to fit a variety of single and multi-species occupancy models, making it straightforward to address detection biases and spatial autocorrelation in species distribution models even for large data sets.
3. spOccupancy provides user-friendly functions for data simulation, model fitting, model · 1 Introduction
spOccupancy provides user-friendly tools for fitting spatial single-species, multi-species, and integrated occupancy models, addressing imperfect detection and spatial autocorrelation in large data sets. Its Gaussian-process and Nearest Neighbor Gaussian Process options support spatial modeling, while package functions cover simulation, validation, comparison, and prediction.
3. spOccupancy provides user-friendly functions for data simulation, model fitting, model
- spOccupancy provides functions for data simulation, model fitting, posterior predictive checks, model comparison, and out-of-sample prediction.Model comparison uses information criteria and k-fold cross-validation; the paper illustrates the package with a vignette, simulated analysis, and two bird case studies.Source: §3 · p. 2
- spOccupancy fits single-species, multi-species, and integrated occupancy models with spatial autocorrelation, helping address detection biases in large data sets.The package supports point-referenced models using Gaussian processes or Nearest Neighbor Gaussian Processes.Source: §3 · p. 2, served locations, accounting for… · p. 4, accommodate spatial autocorrelation in… · p. 4
1 Introduction
- Single-species occupancy models separate latent occurrence from detection using replicated detection-nondetection data, while multi-species models share species parameters through a community-level distribution.The shared distribution enables species- and community-scale inference; the supplied passage continues that it improves precision of species-specific effects and biodiversity metrics with fully propagated uncertainty.Source: §1 · p. 3, precision of species-specific effects… · p. 3
precision of species-specific effects and biodiversity metrics, all with fully propagated uncertainty
- Integrated occupancy models combine multiple detection-nondetection data sources and accommodate differences in sampling processes to improve inference on latent processes and uncertainty.Such data sources may arise from protocols across large regions, including autonomous recording units.Source: precision of species-specific effects… · p. 3
served locations, accounting for spatial autocorrelation becomes increasingly more important
- Spatial random effects can improve occurrence predictions, but their computational cost grows cubically with the number of locations, limiting practical use on larger data sets.The passage notes that fitting spatial models may take weeks or be infeasible, motivating computationally efficient software.Source: served locations, accounting for… · p. 4
- The package supports point-referenced spatial single-species, multi-species, and integrated occupancy models using Gaussian processes or Nearest Neighbor Gaussian Processes.Source: served locations, accounting for… · p. 4, accommodate spatial autocorrelation in… · p. 4
accommodate spatial autocorrelation in potentially massive data sets. We fit spatial SSOMs,
- Nearest Neighbor Gaussian Processes use local information from a small neighbor set to approximate a full Gaussian process while reducing computational complexity.This enables computationally efficient models for large spatial data sets.Source: accommodate spatial autocorrelation in… · p. 5
2 Models
Section 2 presents the package’s Bayesian single-species, multi-species, and integrated occupancy models, including nonspatial and spatial structures. It describes how the models account for imperfect detection, spatial variation, and species-level effects.
2 Models
- spOccupancy fits six nonspatial and spatial single-species, multi-species, and integrated occupancy model structures in a Bayesian framework.The package uses priors and numerical algorithms designed for computational efficiency.Source: §2 · p. 5
2.1 Single-species occupancy models (SSOMs)
- The SSOM models true site presence as Bernoulli occurrence, links occupancy to site covariates, and estimates detection from repeated surveys using site or observation covariates and Gaussian priors.Source: §2.1 · p. 6, assumes zj arises from a Bernoulli… · p. 6, We model ψj using a logit link following · p. 6
2.2 Spatial single-species occupancy models (SSOMs)
- Spatial SSOMs add a Gaussian-process occurrence effect and support exponential, spherical, Gaussian, and Matérn correlation functions, with WAIC or k-fold cross-validation recommended for selection.Matérn is the most flexible option but may require comparatively more data; spPGOcc fits spatial SSOMs.Source: §2.2 · p. 7, ψ(sj), now takes the form · p. 7
2.3 Multi-species occupancy models (MSOMs)
- MSOMs model species-specific occupancy and detection coefficients as community-level normal random effects, improving precision especially for rare species and facilitating biodiversity-metric estimation.Source: §2.3 · p. 8
where µβ0 is the community-level occurrence intercept and τ 2
The methods assign priors to community-level regression coefficients and variance parameters, then extend multi-species and integrated occupancy models to incorporate spatial processes. Integrated models share a latent occupancy process across data sources while allowing source-specific detection models.
where µβ0 is the community-level occurrence intercept and τ 2
- Normal priors are assigned to community-level occurrence and detection regression coefficients, and inverse-Gamma priors to occurrence variance parameters.Source: where µβ0 is the community-level… · p. 8
tection (τ 2
- The detection variance parameters also receive inverse-Gamma priors.Source: tection (τ 2 · p. 8
2.4 Spatial multi-species occupancy models (MSOMs)
- Spatial MSOMs add a species-specific spatial Gaussian process to each species’ occurrence probability, with spatial parameters estimated separately by species.The spatial variance parameters have inverse-Gamma priors; range and smoothness parameters have uniform priors. The spMsPGOcc function fits these models.Source: §2.4 · p. 8
2.5 Integrated occupancy models (IOMs)
- Integrated occupancy models share a latent occupancy process across data sources while assigning each source its own detection model, allowing source-specific detection covariate effects and intercepts.The intPGOcc function fits integrated occupancy models.Source: §2.5 · p. 9
2.6 Spatial integrated occupancy models (IOMs)
- Spatial integrated occupancy models add a spatial random intercept to the latent occurrence probability; spIntPGOcc fits these models.Source: §2.6 · p. 9
3 Computational Advances in spOccupancy
spOccupancy improves computational efficiency through Pólya-Gamma data augmentation for logit-link occupancy models and NNGP-based spatial modeling. Models are implemented in C/C++ through R’s foreign language interface.
3 Computational Advances in spOccupancy
- Pólya-Gamma data augmentation enables efficient Gibbs updates for occurrence and detection regression parameters in logit-link occupancy models.It introduces two sets of latent auxiliary variables with Pólya-Gamma distributions to address inefficient parameter-estimation algorithms in standard Bayesian software.Source: §3 · p. 9
faster than traditional algorithms (Clark and Altwegg, 2019). See Supplemental Information
- NNGP spatial models use local information from nearest neighbors to provide nearly indistinguishable inferences from full Gaussian processes across tens to hundreds of thousands of locations.Fifteen neighbors are often sufficient; as few as five may be adequate for some data sets with long-range spatial dependence.Source: faster than traditional algorithms… · p. 9
- All spOccupancy occupancy models are written in C/C++ using R’s foreign language interface, drawing on computational technology from spNNGP.The package’s Gibbs samplers are described in Supplemental Information S2.Source: faster than traditional algorithms… · p. 10
4 Implementation and Usage of spOccupancy
The section introduces spOccupancy’s functionality for five main tasks and directs readers to package resources for further details and examples.
4 Implementation and Usage of spOccupancy
- spOccupancy supports five main tasks, with further details and examples available in its vignette, website, and R package documentation.The section points to Table 1 for the functionality overview.Source: §4 · p. 10
1. Data simulation. The functions simOcc, simMsOcc, and simIntOcc simulate data un-
spOccupancy provides functions to simulate data under single-species, multi-species, and integrated occupancy frameworks, with optional spatial random effects in the occurrence model.
1. Data simulation
- simOcc, simMsOcc, and simIntOcc simulate data under the SSOM, MSOM, and IOM frameworks, respectively.Source: §1 · p. 10
- All three simulation functions optionally include spatial random effects in the occurrence portion of the model.Source: §1 · p. 10
2. Model fitting. Each of the model fitting functions was described previously (Section
The SSOM and MSOM fitting functions support random intercepts in occurrence and detection models, and users can customize parameter priors; weakly informative priors are the default.
Model fitting
- SSOM and MSOM functions allow random intercepts in both occurrence and detection models.These can represent, for example, habitat-classification or observer effects.Source: §2 · p. 10
- Random intercepts can account for effects such as habitat classification or observer identity.Source: §2 · p. 10
- Users may specify vague or informative priors for each parameter, with weakly informative priors used by default.Source: §2 · p. 10
3. Model validation and comparison. The spOccupancy function ppcOcc performs posterior · 4. Posterior summaries. All posterior samples are returned as coda::mcmc objects (Plum-
spOccupancy provides posterior predictive checks, model-comparison tools, and posterior summaries with convergence diagnostics. Its functions support both WAIC and k-fold cross-validation, while returning posterior samples as coda::mcmc objects.
3. Model validation and comparison. The spOccupancy function ppcOcc performs posterior
- ppcOcc performs posterior predictive checks on all spOccupancy model objects.Users can also calculate Bayesian p-values as a simple assessment of model fit.Source: §3 · p. 10
- waicOcc computes the WAIC for model selection and assessment.The passage cites Watanabe (2010) for WAIC.Source: §3 · p. 10
- Users can alternatively perform k-fold cross-validation through the k.fold argument in any spOccupancy model-fitting function.The model deviance serves as the cross-validation scoring rule.Source: §3 · p. 10
4. Posterior summaries. All posterior samples are returned as coda::mcmc objects (Plum-
- All posterior samples are returned as coda::mcmc objects (Plummer et al., 2006).Source: §4 · p. 10
- Summary functions for all spOccupancy model objects print concise posterior quantiles and means.Source: §4 · p. 10
- Model summaries also report Rhat and effective sample size as convergence diagnostics.The passage cites Brooks and Gelman 1998 for Rhat.Source: §4 · p. 10
5. Prediction. We implement a predict function for all spOccupancy model objects to yield · 5 Case Studies
spOccupancy predicts latent occurrences, occurrence probabilities, and detection probabilities, and the case studies illustrate its use for spatial single- and multi-species bird occupancy models. The studies show spatial and elevational structure in occurrence and richness, with model comparisons varying by criterion.
5. Prediction. We implement a predict function for all spOccupancy model objects to yield
- The predict function returns posterior predictive distributions of latent occurrence and occurrence probability at specified locations, supporting distribution maps with propagated uncertainty.It can also predict detection probability across a user-specified range of covariate values.Source: §5 · p. 11
5 Case Studies
- The case studies demonstrate spOccupancy on forest-breeding birds in the eastern USA, with additional simulated-data analyses across 40,000 locations described in the supplement.The two case studies concern Black-throated Green Warbler occurrence and foliage-gleaning bird community richness.Source: §5 · p. 11
5.1 Black-throated Green Warbler in eastern USA (SSOM)
- The Black-throated Green Warbler analysis modeled 2018 route-level occurrence across the eastern USA using forest cover and elevation, with detection modeled from survey timing and observer effects.The authors compared a nonspatial SSOM, a full-GP spatial SSOM, and an NNGP spatial SSOM with 15 neighbors.Source: §5.1 · p. 11
- Spatial SSOMs outperformed the nonspatial SSOM by WAIC and 10-fold cross-validation, while the NNGP greatly reduced computation with only small differences in estimates and effective sample sizes.Table 2 reports model estimates, WAIC, cross-validation deviance, and run time for the nonspatial, NNGP, and full-GP models.Source: §5.1 · p. 11, Table 2 · p. 13
5.2 Foliage-gleaning birds in Hubbard Brook (MSOM)
- The Hubbard Brook analysis estimated richness for 12 foliage-gleaning bird species from point counts at 373 sites surveyed three times in 2015.Models varied elevation occurrence predictors and spatial random effects; spatial models used an NNGP with five neighbors.Source: §5.2 · p. 12
- The spatial MSOM with linear and quadratic elevation performed best by WAIC, but the nonspatial elevation model performed best by four-fold cross-validation.The spatial intercept-only model alone outperformed the nonspatial intercept-only model on both criteria.Source: §5.2 · p. 12
only model outperformed the nonspatial intercept-only model according to both criteria, which
- Foliage-gleaning bird occurrence varied spatially, but the elevational gradient explained much of that variation; predicted richness was lower at low and high elevations than at moderate elevations.Predicted richness uncertainty was high along forest edges, corresponding closely to high-elevation areas.Source: only model outperformed the nonspatial… · p. 13
6 Conclusions and Future Directions
spOccupancy provides spatially explicit single-species, multi-species, and integrated occupancy models, with tools for simulation, fitting, validation, comparison, and prediction. Planned extensions and its support for large data sets are intended to help users account for detection biases and spatial autocorrelation across broad regions.
6 Conclusions and Future Directions
- The package fits spatially explicit single-species, multi-species, and integrated occupancy models and includes tools for simulation, fitting, validation, comparison, and out-of-sample prediction.It is designed for potentially massive data sets.Source: §6 · p. 13
- Planned extensions include dynamic occupancy models, spatially varying coefficients, and multi-species integrated occupancy models (Doser et al., 2022).Source: §6 · p. 15
- The authors expect spOccupancy to help ecologists and conservation practitioners account for detection biases and spatial autocorrelation in data sets with hundreds of thousands of locations.The aim is to support assessments of species distributions and community patterns across broad spatial regions.Source: §6 · p. 15
7 Data Availability Statement
spOccupancy is available on CRAN, and materials associated with the examples are available on GitHub and planned for Zenodo upon acceptance.
7 Data Availability Statement
- The spOccupancy package is available on CRAN, while materials associated with the examples are available on GitHub and will be posted on Zenodo upon acceptance.Source: §7 · p. 15
Authors’ Contributions
- JWD developed the package, performed analyses, and led manuscript writing; all authors approved the final publication.AOF guided package development, and MK, EFZ, and AOF provided critical insights on the manuscript.Source: Authors’ Contributions · p. 16