Skip to content

Commit

Permalink
Prepare for CRAN v1.0.0 release
Browse files Browse the repository at this point in the history
* Fixed bug in `lrren()` to properly extract predicted RR values for cross validation when using `terra::extract()`
* Fixed NOTE in CRAN checks to provide package anchors for Rd \link{} targets not in the package itself and the base packages  within 'envi-package.Rd', 'lrren.Rd', and 'perlrren.Rd'
  * Fixed NOTE in Windows check to remove detritus files after testing
* Renamed 'package.R' to 'envi-package.R' after Roxygen (7.3.0) update
* Updated CITATION with [peer-review publication](https://doi.org/10.1016/j.sste.2024.100696)
  • Loading branch information
idblr committed Nov 6, 2024
1 parent d8462e3 commit 8d0b2b4
Show file tree
Hide file tree
Showing 18 changed files with 203 additions and 148 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: envi
Type: Package
Title: Environmental Interpolation using Spatial Kernel Density Estimation
Version: 0.1.19
Date: 2024-01-23
Version: 1.0.0
Date: 2024-11-06
Authors@R:
c(person(given = "Ian D.",
family = "Buller",
Expand All @@ -28,7 +28,7 @@ Description: Estimates an ecological niche using occurrence data, covariates, an
License: Apache License (>= 2.0)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Depends:
R (>= 3.5.0)
Imports:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ accepting any such warranty or additional liability.

_END OF TERMS AND CONDITIONS_

Copyright 2020 Ian D. Buller; Emory University
Copyright 2024 Ian D. Buller; Emory University

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# envi (development version)

## envi v1.0.0
* Fixed bug in `lrren()` to properly extract predicted RR values for cross validation after update using `terra::extract()`
* Fixed NOTE in CRAN checks to provide package anchors for Rd \link{} targets not in the package itself and the base packages within 'envi-package.Rd', 'lrren.Rd', and 'perlrren.Rd'
* Fixed NOTE in Windows check to remove detritus files after testing
* Renamed 'package.R' to 'envi-package.R' after Roxygen (>=7.3.0) update
* Updated CITATION with [peer-review publication](https://doi.org/10.1016/j.sste.2024.100696)

## envi v0.1.19
* Fixed 'Moved Permanently' content by replacing the old URL with the new URL

Expand Down
9 changes: 4 additions & 5 deletions R/package.R → R/envi-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Estimates an ecological niche model using occurrence data, covariates, and kernel density-based estimation methods.
#'
#' @details For a single species with presence and absence data, the 'envi' package uses the spatial relative risk function estimated using the \code{\link{sparr}} package. Details about the \code{\link{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 (KDE) can be found in J. F. Bithell (1991) \doi{10.1002/sim.4780101112}.
#' @details For a single species with presence and absence data, the 'envi' package uses the spatial relative risk function estimated using the \code{\link[sparr]{sparr}} package. Details about the \code{\link[sparr]{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 (KDE) can be found in J. F. Bithell (1991) \doi{10.1002/sim.4780101112}.
#'
#' This package provides a function to estimate the ecological niche for a single species with presence and absence data. The 'envi' package also provides some sensitivity and visualization tools for the estimated ecological niche, its predicted spatial distribution, and prediction diagnostics. Various options for the correction of multiple testing are available.
#'
Expand All @@ -28,16 +28,15 @@
#'
#' @name envi-package
#' @aliases envi-package envi
#' @docType package
#'
#' @section Dependencies: The 'envi' package relies heavily upon \code{\link{sparr}}, \code{\link{spatstat.geom}}, \code{\link{sf}}, and \code{\link{terra}}. For a single species (presence/absence data), the spatial relative risk function uses the \code{\link[sparr]{risk}} function. Cross-validation is can be performed in parallel using the \code{\link{future}}, \code{\link{doFuture}}, \code{\link{doRNG}}, and \code{\link{foreach}} packages. Spatial perturbation is performed using the \code{\link[spatstat.geom]{rjitter}} function. Basic visualizations rely on the \code{\link[spatstat.geom]{plot.ppp}} and \code{\link[fields]{image.plot}} functions.
#' @section Dependencies: The 'envi' package relies heavily upon \code{\link[sparr]{sparr}}, \code{\link[spatstat.geom]{spatstat.geom}}, \code{\link[sf]{sf}}, and \code{\link[terra]{terra}}. For a single species (presence/absence data), the spatial relative risk function uses the \code{\link[sparr]{risk}} function. Cross-validation is can be performed in parallel using the \code{\link[future]{future}}, \code{\link[doFuture]{doFuture}}, \code{\link[doRNG]{doRNG}}, and \code{\link[foreach]{foreach}} packages. Spatial perturbation is performed using the \code{\link[spatstat.geom]{rjitter}} function. Basic visualizations rely on the \code{\link[spatstat.geom]{plot.ppp}} and \code{\link[fields]{image.plot}} functions.
#'
#' @author Ian D. Buller\cr \emph{Social & Scientific Systems, Inc., a division of DLH Corporation, Silver Spring, Maryland, USA (current); Occupational and Environmental Epidemiology Branch, Division of Cancer Epidemiology and Genetics, National Cancer Institute, National Institutes of Health, Rockville, Maryland, USA (former); Environmental Health Sciences, James T. Laney School of Graduate Studies, Emory University, Atlanta, Georgia, USA (original)}\cr
#' @author Ian D. Buller\cr \emph{DLH, LLC (formerly known as Social & Scientific Systems, Inc.) Bethesda, Maryland, USA (current); Occupational and Environmental Epidemiology Branch, Division of Cancer Epidemiology and Genetics, National Cancer Institute, National Institutes of Health, Rockville, Maryland, USA (former); Environmental Health Sciences, James T. Laney School of Graduate Studies, Emory University, Atlanta, Georgia, USA (original)}\cr
#'
#' Maintainer: I.D.B. \email{ian.buller@@alumni.emory.edu}
#'
#' @keywords package
NULL
"_PACKAGE"

#' @importFrom concaveman concaveman
#' @importFrom cvAUC ci.cvAUC cvAUC
Expand Down
2 changes: 1 addition & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
globalVariables("k")
globalVariables("kk")
globalVariables("kk")
9 changes: 4 additions & 5 deletions R/lrren.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#'
#' If \code{predict = TRUE}, this function will predict ecological niche at every location specified with \code{predict_locs} with best performance if \code{predict_locs} are gridded locations in the same study area as the observations in \code{obs_locs} - a version of environmental interpolation. The predicted spatial distribution of the estimated ecological niche can be visualized using the \code{\link{plot_predict}} function.
#'
#' If \code{cv = TRUE}, this function will prepare k-fold cross-validation data sets for prediction diagnostics. The sample size of each fold depends on the number of folds set with \code{kfold}. If \code{balance = TRUE}, the sample size of each fold will be the frequency of presence locations divided by the number of folds times two. If \code{balance = FALSE}, the sample size of each fold will be the frequency of all observed locations divided by the number of folds. The cross-validation can be performed in parallel if \code{parallel = TRUE} using the \code{\link{future}}, \code{\link{doFuture}}, \code{\link{doRNG}}, and \code{\link{foreach}} packages. Two diagnostics (area under the receiver operating characteristic curve and precision-recall curve) can be visualized using the \code{plot_cv} function.
#' If \code{cv = TRUE}, this function will prepare k-fold cross-validation data sets for prediction diagnostics. The sample size of each fold depends on the number of folds set with \code{kfold}. If \code{balance = TRUE}, the sample size of each fold will be the frequency of presence locations divided by the number of folds times two. If \code{balance = FALSE}, the sample size of each fold will be the frequency of all observed locations divided by the number of folds. The cross-validation can be performed in parallel if \code{parallel = TRUE} using the \code{\link[future]{future}}, \code{\link[doFuture]{doFuture}}, \code{\link[doRNG]{doRNG}}, and \code{\link[foreach]{foreach}} packages. Two diagnostics (area under the receiver operating characteristic curve and precision-recall curve) can be visualized using the \code{plot_cv} function.
#'
#' The \code{obs_window} argument may be useful to specify a 'known' window for the ecological niche (e.g., a convex hull around observed locations).
#'
Expand Down Expand Up @@ -324,8 +324,7 @@ lrren <- function(obs_locs,
rand_lrr <- sparr::risk(f = ppp_presence_training,
g = ppp_absence_training,
tolerate = TRUE,
verbose = FALSE,
...)
verbose = FALSE)

##### Convert to semi-continuous SpatRaster
rr_raster <- terra::rast(rand_lrr$rr)
Expand All @@ -336,11 +335,11 @@ lrren <- function(obs_locs,

##### Output for each k-fold
###### Record category (semi-continuous) of testing data
cv_predictions_rr <- terra::extract(rr_raster, extract_testing)[ , 2]
cv_predictions_rr <- terra::extract(rr_raster, as.matrix(extract_testing))[, 1]
cv_labels <- testing[ , 4] # Record labels (marks) of testing data

par_results <- list("cv_predictions_rr" = cv_predictions_rr,
"cv_labels"= cv_labels)
"cv_labels" = cv_labels)
return(par_results)
}

Expand Down
2 changes: 1 addition & 1 deletion R/perlrren.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#'
#' @details This function performs a sensitivity analysis of an ecological niche model of a single species (presence/absence data), or the presence of one species relative to another, that uses two covariates. The observation locations (presence and absence data) are randomly spatially perturbed (i.e., "jittered") uniformly within a circular disc of a specified radius centered at their recorded location using the \code{\link[spatstat.geom]{rjitter}} function. This method simulates the spatial uncertainty of observations, how that may affect the covariate values at each observation (i.e., misclassification error), and the estimated ecological niche based on the two specified covariates. Observations can be grouped into categories of the uncertainty of class 'factor' and can vary by degrees of uncertainty specified using the \code{radii} argument.
#'
#' The function iteratively estimates the ecological niche using the \code{\link{lrren}} function and computes four summary statistics at every grid cell (i.e., knot) of the estimated surface: 1) mean of the log relative risk, 2) standard deviation of the log relative risk, 3) mean of the asymptotically normal p-value, and 4) proportion of iterations were statistically significant based on a two-tailed alpha-level threshold (argument \code{alpha}). The process can be performed in parallel if \code{parallel = TRUE} using the \code{\link{future}}, \code{\link{doFuture}}, \code{\link{doRNG}}, and \code{\link{foreach}} packages. The computed surfaces can be visualized using the \code{\link{plot_perturb}} function. If \code{predict = TRUE}, this function will predict the four summary statistics at every location specified with \code{predict_locs} and can also be visualized using the \code{\link{plot_perturb}} function.
#' The function iteratively estimates the ecological niche using the \code{\link{lrren}} function and computes four summary statistics at every grid cell (i.e., knot) of the estimated surface: 1) mean of the log relative risk, 2) standard deviation of the log relative risk, 3) mean of the asymptotically normal p-value, and 4) proportion of iterations were statistically significant based on a two-tailed alpha-level threshold (argument \code{alpha}). The process can be performed in parallel if \code{parallel = TRUE} using the \code{\link[future]{future}}, \code{\link[doFuture]{doFuture}}, \code{\link[doRNG]{doRNG}}, and \code{\link[foreach]{foreach}} packages. The computed surfaces can be visualized using the \code{\link{plot_perturb}} function. If \code{predict = TRUE}, this function will predict the four summary statistics at every location specified with \code{predict_locs} and can also be visualized using the \code{\link{plot_perturb}} function.
#'
#' For more information about the spatial perturbation, please refer to the \code{\link[spatstat.geom]{rjitter}} function documentation.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ progBar <- function(kk, N, per = 1) {

# Temporary stopgap for converting 'SpatRaster' to 'im'
## Modification of `as.im.RasterLayer` from `maptools` because `maptools` is retiring in 2023
as.im.SpatRaster <- function (from, factor.col.name = NULL) {
as.im.SpatRaster <- function(from, factor.col.name = NULL) {
if (!requireNamespace("spatstat.geom", quietly = TRUE)) {
stop(paste("package spatstat.geom required; please install it (or the full spatstat package) first"))
}
Expand Down
Loading

0 comments on commit 8d0b2b4

Please # to comment.