MyNixOS website logo
Description

Environmental Interpolation using Spatial Kernel Density Estimation.

Estimates an ecological niche using occurrence data, covariates, and kernel density-based estimation methods. For a single species with presence and absence data, the 'envi' package uses the spatial relative risk function that is estimated using the 'sparr' package. Details about the 'sparr' package methods can be found in the tutorial: Davies et al. (2018) <doi:10.1002/sim.7577>. Details about kernel density estimation can be found in J. F. Bithell (1990) <doi:10.1002/sim.4780090616>. More information about relative risk functions using kernel density estimation can be found in J. F. Bithell (1991) <doi:10.1002/sim.4780101112>.

envi: Environmental Interpolation using Spatial Kernel Density Estimation

R-CMD-check CRAN status CRAN version CRAN RStudio mirror downloads total CRAN RStudio mirror downloads monthly License GitHub last commit DOI

Date repository last updated: January 23, 2024

Overview

The envi package is a suite of R functions to estimate the ecological niche of a species and predict the spatial distribution of the ecological niche -- a version of environmental interpolation -- with spatial kernel density estimation techniques. A two-group comparison (e.g., presence and absence locations of a single species) is conducted using the spatial relative risk function that is estimated using the sparr package. Internal cross-validation and basic visualization are also supported.

Installation

To install the release version from CRAN:

install.packages("envi")

To install the development version from GitHub:

devtools::install_github("lance-waller-lab/envi")

Available functions

FunctionDescription
lrrenMain function. Estimate an ecological niche using the spatial relative risk function and predict its location in geographic space.perlrrenSensitivity analysis for lrren whereby observation locations are spatially perturbed ("jittered") with specified radii, iteratively.plot_obsDisplay multiple plots of the estimated ecological niche from lrren output.plot_predictDisplay multiple plots of the predicted spatial distribution from lrren output.plot_cvDisplay multiple plots of internal k-fold cross-validation diagnostics from lrren output.plot_perturbDisplay multiple plots of output from perlrren including predicted spatial distribution of the summary statistics.div_plotCalled within plot_obs, plot_predict, and plot_perturb, provides functionality for basic visualization of surfaces with diverging color palettes.seq_plotCalled within plot_perturb, provides functionality for basic visualization of surfaces with sequential color palettes.pval_correctCalled within lrren and perlrren, calculates various multiple testing corrections for the alpha level.

Authors

  • Ian D. Buller - Social & Scientific Systems, Inc., a division of DLH Corporation, Silver Spring, Maryland (current) - Occupational and Environmental Epidemiology Branch, Division of Cancer Epidemiology and Genetics, National Cancer Institute, National Institutes of Health, Rockville, Maryland (former) - Environmental Health Sciences, James T. Laney School of Graduate Studies, Emory University, Atlanta, Georgia. (original) - GitHub - ORCID

See also the list of contributors who participated in this package, including:

  • Lance A. Waller - Biostatistics and Bioinformatics, Emory University, Atlanta, Georgia. - GitHub - ORCID

Usage

For the lrren() function

set.seed(1234) # for reproducibility

# ------------------ #
# Necessary packages #
# ------------------ #

library(envi)
library(spatstat.data)
library(spatstat.geom)
library(spatstat.random)
library(terra)

# -------------- #
# Prepare inputs #
# -------------- #

# Using the 'bei' and 'bei.extra' data within {spatstat.data}

# Environmental Covariates
elev <- spatstat.data::bei.extra[[1]]
grad <- spatstat.data::bei.extra[[2]]
elev$v <- scale(elev)
grad$v <- scale(grad)
elev_raster <- terra::rast(elev)
grad_raster <- terra::rast(grad)

# Presence data
presence <- spatstat.data::bei
spatstat.geom::marks(presence) <- data.frame("presence" = rep(1, presence$n),
                                             "lon" = presence$x,
                                             "lat" = presence$y)
spatstat.geom::marks(presence)$elev <- elev[presence]
spatstat.geom::marks(presence)$grad <- grad[presence]

# (Pseudo-)Absence data
absence <- spatstat.random::rpoispp(0.008, win = elev)
spatstat.geom::marks(absence) <- data.frame("presence" = rep(0, absence$n),
                                            "lon" = absence$x,
                                            "lat" = absence$y)
spatstat.geom::marks(absence)$elev <- elev[absence]
spatstat.geom::marks(absence)$grad <- grad[absence]

# Combine
obs_locs <- spatstat.geom::superimpose(presence, absence, check = FALSE)
obs_locs <- spatstat.geom::marks(obs_locs)
obs_locs$id <- seq(1, nrow(obs_locs), 1)
obs_locs <- obs_locs[ , c(6, 2, 3, 1, 4, 5)]

# Prediction Data
predict_xy <- terra::crds(elev_raster)
predict_locs <- as.data.frame(predict_xy)
predict_locs$elev <- terra::extract(elev_raster, predict_xy)[ , 1]
predict_locs$grad <- terra::extract(grad_raster, predict_xy)[ , 1]

# ----------- #
# Run lrren() #
# ----------- #

test1 <- envi::lrren(obs_locs = obs_locs,
                     predict_locs = predict_locs,
                     predict = TRUE,
                     verbose = TRUE,
                     cv = TRUE)
              
# -------------- #
# Run plot_obs() #
# -------------- #

envi::plot_obs(test1)

# ------------------ #
# Run plot_predict() #
# ------------------ #

envi::plot_predict(test1,
                   cref0 = "EPSG:5472",
                   cref1 = "EPSG:4326")

# ------------- #
# Run plot_cv() #
# ------------- #

envi::plot_cv(test1)

# -------------------------------------- #
# Run lrren() with Bonferroni correction #
# -------------------------------------- #

test2 <- envi::lrren(obs_locs = obs_locs,
                     predict_locs = predict_locs,
                     predict = TRUE,
                     p_correct = "Bonferroni")

# Note: Only showing third plot
envi::plot_obs(test2)

# Note: Only showing second plot
envi::plot_predict(test2,
                   cref0 = "EPSG:5472",
                   cref1 = "EPSG:4326")

# Note: plot_cv() will display the same results because cross-validation only performed for the log relative risk estimate

For the perlrren() function

set.seed(1234) # for reproducibility

# ------------------ #
# Necessary packages #
# ------------------ #

library(envi)
library(spatstat.data)
library(spatstat.geom)
library(spatstat.random)
library(terra)

# -------------- #
# Prepare inputs #
# -------------- #

# Using the 'bei' and 'bei.extra' data within {spatstat.data}

# Scale environmental covariates
ims <- spatstat.data::bei.extra
ims[[1]]$v <- scale(ims[[1]]$v)
ims[[2]]$v <- scale(ims[[2]]$v)

# Presence data
presence <- spatstat.data::bei
spatstat.geom::marks(presence) <- data.frame("presence" = rep(1, presence$n),
                                             "lon" = presence$x,
                                             "lat" = presence$y)

# (Pseudo-)Absence data
absence <- spatstat.random::rpoispp(0.008, win = ims[[1]])
spatstat.geom::marks(absence) <- data.frame("presence" = rep(0, absence$n),
                                            "lon" = absence$x,
                                            "lat" = absence$y)

# Combine and create 'id' and 'levels' features
obs_locs <- spatstat.geom::superimpose(presence, absence, check = FALSE)
spatstat.geom::marks(obs_locs)$id <- seq(1, obs_locs$n, 1)
spatstat.geom::marks(obs_locs)$levels <- as.factor(stats::rpois(obs_locs$n, lambda = 0.05))
spatstat.geom::marks(obs_locs) <- spatstat.geom::marks(obs_locs)[ , c(4, 2, 3, 1, 5)]

# -------------- #
# Run perlrren() #
# -------------- #

# Uncertainty in observation locations
## Most observations within 10 meters
## Some observations within 100 meters
## Few observations within 500 meters

test3 <- envi::perlrren(obs_ppp = obs_locs,
                        covariates = ims,
                        radii = c(10, 100, 500),
                        verbose = FALSE, # may not be availabe if parallel = TRUE
                        parallel = TRUE,
                        n_sim = 100)
                 
# ------------------ #
# Run plot_perturb() #
# ------------------ #

envi::plot_perturb(test3,
                   cref0 = "EPSG:5472",
                   cref1 = "EPSG:4326",
                   cov_labs = c("elev", "grad"))

Funding

This package was developed while the author was originally a doctoral student in the Environmental Health Sciences doctoral program at Emory University and later as a postdoctoral fellow supported by the Cancer Prevention Fellowship Program at the National Cancer Institute. Any modifications since December 05, 2022 were made while the author was an employee of Social & Scientific Systems, Inc., a division of DLH Corporation.

Acknowledgments

When citing this package for publication, please follow:

citation("envi")

Questions? Feedback?

For questions about the package, please contact the maintainer Dr. Ian D. Buller or submit a new issue.

Metadata

Version

0.1.19

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows