Skip to content

Commit

Permalink
Prepare for CRAN v0.1.14 release
Browse files Browse the repository at this point in the history
* Updated package URL and BugReports to renamed GitHub account "lance-waller-lab" (previously "Waller-SUSAN")
* Replaced `methods::is()` with `inherits()` and `methods` is no longer Imports
* Added `maptools` and `RStoolbox` to Suggests (used in the package vignette)
* Added CITATION file
* Fixed typos in documentation throughout
  • Loading branch information
Ian Buller, PhD, MA committed Aug 25, 2022
1 parent 0a843db commit 004de63
Show file tree
Hide file tree
Showing 25 changed files with 628 additions and 153 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ rsconnect/

# Sandboxes
inst/doc

# CRAN
CRAN-SUBMISSION
18 changes: 9 additions & 9 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.13
Date: 2022-03-23
Version: 0.1.14
Date: 2022-08-25
Authors@R:
c(person(given = "Ian D.",
family = "Buller",
Expand All @@ -15,21 +15,20 @@ Authors@R:
email = "lwaller@emory.edu",
comment = c(ORCID = "0000-0001-5002-8886")),
person(given = "Emory University",
role = "cph")
)
role = "cph"))
Maintainer: Ian D. Buller <ian.buller@alumni.emory.edu>
Description: 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
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>.
License: Apache License (>= 2.0)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
Depends:
R (>= 3.5.0)
Imports:
Expand All @@ -43,7 +42,6 @@ Imports:
graphics,
grDevices,
iterators,
methods,
pls,
raster,
rgeos,
Expand All @@ -53,13 +51,15 @@ Imports:
spatstat.geom,
stats
Suggests:
maptools,
R.rsp,
RStoolbox,
spatstat.data,
spatstat.random,
spelling,
testthat,
utils
VignetteBuilder: R.rsp
Language: en-US
URL: https://github.com/Waller-SUSAN/envi
BugReports: https://github.com/Waller-SUSAN/envi/issues
URL: https://github.com/lance-waller-lab/envi
BugReports: https://github.com/lance-waller-lab/envi/issues
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ importFrom(graphics,plot)
importFrom(graphics,plot.new)
importFrom(graphics,title)
importFrom(iterators,icount)
importFrom(methods,is)
importFrom(pls,cvsegments)
importFrom(raster,crs)
importFrom(raster,cut)
Expand Down
9 changes: 8 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# envi (development version)

# envi v0.1.14
* Updated package URL and BugReports to renamed GitHub account "lance-waller-lab" (previously "Waller-SUSAN")
* Replaced `methods::is()` with `inherits()` and `methods` is no longer Imports
* Added `maptools` and `RStoolbox` to Suggests (used in the package vignette)
* Added CITATION file
* Fixed typos in documentation throughout

# envi v0.1.13
* In the `div_plot()` and `seq_plot()` internal functions, replaced `if (class(input) == "im")` with `if (methods::is(input, "im"))`
* Added `methods` package to Imports
Expand All @@ -17,7 +24,7 @@
* `spatstat.geom`, `spatstat.core`, `spatstat.linnet`, and `spatstat (>=2.0-0)` are no longer Depends.
* `spatstat.geom` and `spatstat.random` are now Imports
* `spatstat.data` is now Suggests.
* [See the GitHub merge pull request](https://github.com/Waller-SUSAN/envi/pull/2/commits/34b67d8a66151f609cafe4a72de39e382abe7f07).
* [See the GitHub merge pull request](https://github.com/lance-waller-lab/envi/pull/2/commits/34b67d8a66151f609cafe4a72de39e382abe7f07).
* `maptools` is no longer Imports
* Fixed annotation typos in the `perlrren()`, `pval_correct()`, `lrren()` functions
* Fixed bug in `plot_cv()` function that will specify the size of the confidence interval in the subtitle based on the chosen alpha level
Expand Down
3 changes: 1 addition & 2 deletions R/div_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#' }
#'
#' @importFrom grDevices colorRampPalette
#' @importFrom methods is
#' @importFrom raster raster
#'
#' @keywords internal
Expand All @@ -33,7 +32,7 @@ div_plot <- function(input,
digits = 1) {

# Inputs
if (methods::is(input, "im")) {
if (inherits(input, "im")) {
out <- raster::raster(input)
} else { out <- input }

Expand Down
12 changes: 6 additions & 6 deletions R/lrren.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
#' @param predict Logical. If TRUE, will predict the ecological niche in geographic space. If FALSE (the default), will not predict.
#' @param predict_locs Input data frame of prediction locations with 4 features (columns): 1) longitude, 2) latitude, 3) covariate 1 as x-coordinate, 4) covariate 2 as y-coordinate. The covariates must be the same as those included in \code{obs_locs}.
#' @param conserve Logical. If TRUE (the default), the ecological niche will be estimated within a concave hull around the locations in \code{obs_locs}. If FALSE, the ecological niche will be estimated within a concave hull around the locations in \code{predict_locs}.
#' @param alpha Numeric. The two-tailed alpha level for significance threshold (default is 0.05).
#' @param alpha Numeric. The two-tailed alpha level for the significance threshold (the default is 0.05).
#' @param p_correct Optional. Character string specifying whether to apply a correction for multiple comparisons including a False Discovery Rate \code{p_correct = "FDR"}, a Sidak correction \code{p_correct = "Sidak"}, and a Bonferroni correction \code{p_correct = "Bonferroni"}. If \code{p_correct = "none"} (the default), then no correction is applied.
#' @param cv Logical. If TRUE, will calculate prediction diagnostics using internal k-fold cross-validation. If FALSE (the default), will not.
#' @param kfold Integer. Specify the number of folds using in the internal cross-validation. Default is 10.
#' @param kfold Integer. Specify the number of folds used in the internal cross-validation. The default is 10.
#' @param balance Logical. If TRUE, the prevalence within each k-fold will be 0.50 by undersampling absence locations (assumes absence data are more frequent). If FALSE (the default), the prevalence within each k-fold will match the prevalence in \code{obs_locs}.
#' @param parallel Logical. If TRUE, will execute the function in parallel. If FALSE (the default), will not execute the function in parallel.
#' @param n_core Optional. Integer specifying the number of CPU cores on current host to use for parallelization (the default is 2 cores).
#' @param poly_buffer Optional. Specify a custom distance (in same units as covariates) to add to window within which the ecological niche is estimated. The default is 1/100th of the smallest range among the two covariates.
#' @param n_core Optional. Integer specifying the number of CPU cores on the current host for parallelization (the default is 2 cores).
#' @param poly_buffer Optional. Specify a custom distance (in the same units as covariates) to add to the window within which the ecological niche is estimated. The default is 1/100th of the smallest range among the two covariates.
#' @param obs_window Optional. Specify a custom window of class 'owin' within which to estimate the ecological niche. The default computes a concave hull around the data specified in \code{conserve}.
#' @param verbose Logical. If TRUE (the default), will print function progress during execution. If FALSE, will not print.
#' @param ... Arguments passed to \code{\link[sparr]{risk}} to select bandwidth, edge correction, and resolution.
#'
#' @details This function estimates the ecological niche of a single species (presence/absence data), or the presence of one species relative to another, using two covariates, will predict the ecological niche into a geographic area, and prepare k-fold cross-validation data sets for prediction diagnostics.
#' @details This function estimates the ecological niche of a single species (presence/absence data), or the presence of one species relative to another, using two covariates, will predict the ecological niche into a geographic area and prepare k-fold cross-validation data sets for prediction diagnostics.
#'
#' The function uses the \code{\link[sparr]{risk}} function to estimate the spatial relative risk function and forces \code{risk(tolerate == TRUE)} in order to calculate asymptotic p-values. The estimated ecological niche can be visualized using the \code{\link{plot_obs}} function.
#'
#' 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 frequency of presence locations divided by number of folds times two. If \code{balance = FALSE}, the sample size of each fold will be frequency of all observed locations divided by 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}}, \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.
#'
#' 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
5 changes: 2 additions & 3 deletions R/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 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 (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 '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 (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 @@ -24,7 +24,7 @@
#'
#' \code{\link{plot_cv}} Visualizes the \code{\link{lrren}} output, specifically two prediction diagnostics (area under the receiver operating characteristic curve and precision-recall curve).
#'
#' \code{\link{plot_perturb}} Visualizes the \code{\link{perlrren}} output, specifically four summary statistics of the iterations including mean log relative risk, standard deviation of the log relative risk, mean p-value, and proportion of iterations the p-value was significant based on an alpha-level threshold. Also has functionality to predict the spatial distribution of the summary statistics.
#' \code{\link{plot_perturb}} Visualizes the \code{\link{perlrren}} output, specifically four summary statistics of the iterations, including mean log relative risk, standard deviation of the log relative risk, mean p-value, and proportion of iterations the p-value was significant based on an alpha-level threshold. It also can predict the spatial distribution of the summary statistics.
#'
#' @name envi-package
#' @aliases envi-package envi
Expand All @@ -49,7 +49,6 @@ NULL
#' @importFrom graphics abline layout legend lines mtext par plot plot.new title
#' @importFrom grDevices chull colorRampPalette
#' @importFrom iterators icount
#' @importFrom methods is
#' @importFrom pls cvsegments
#' @importFrom raster crs cut extract image projectRaster raster rasterToPoints reclassify values
#' @importFrom rgeos gBuffer
Expand Down
8 changes: 4 additions & 4 deletions R/perlrren.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#' @param predict_locs Input data frame of prediction locations with 4 features (columns): 1) longitude, 2) latitude, 3) covariate 1 as x-coordinate, 4) covariate 2 as y-coordinate. If unspecified (the default), automatically computed from an 'im' object within \code{covariates}.
#' @param radii Vector of length equal to the number of levels of ordinal ID in \code{obs_ppp}. Specifies the radii of the spatial perturbation at each level in units equivalent to the coordinate reference system of \code{obs_ppp}.
#' @param n_sim Integer, specifying the number of simulation iterations to perform.
#' @param alpha Numeric. The two-tailed alpha level for significance threshold (default is 0.05).
#' @param alpha Numeric. The two-tailed alpha level for the significance threshold (default is 0.05).
#' @param p_correct Optional. Character string specifying whether to apply a correction for multiple comparisons including a False Discovery Rate \code{p_correct = "FDR"}, a Sidak correction \code{p_correct = "Sidak"}, and a Bonferroni correction \code{p_correct = "Bonferroni"}. If \code{p_correct = "none"} (the default), then no correction is applied.
#' @param parallel Logical. If TRUE, will execute the function in parallel. If FALSE (the default), will not execute the function in parallel.
#' @param n_core Optional. Integer specifying the number of CPU cores on current host to use for parallelization (the default is 2 cores).
#' @param n_core Optional. Integer specifying the number of CPU cores on the current host for parallelization (the default is 2 cores).
#' @param verbose Logical. If TRUE (the default), will print function progress during execution. If FALSE, will not print.
#' @param ... Arguments passed to \code{\link{lrren}}.
#'
#' @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 uncertainty of class 'factor' and can vary by degrees of uncertainty specified using the \code{radii} argument.
#' @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.
#'
Expand All @@ -27,7 +27,7 @@
#'
#' \describe{
#' \item{\code{sim}}{An object of class 'list' for the summary statistics of the iterative ecological niche.}
#' \item{\code{predict}}{An object of class 'ppp' a marked point pattern with summary statistics for the iterative ecological niche in geographic space.}
#' \item{\code{predict}}{An object of class 'ppp', a marked point pattern with summary statistics for the iterative ecological niche in geographic space.}
#' }
#'
#' The returned \code{sim} is a named list with the following components:
Expand Down
4 changes: 2 additions & 2 deletions R/plot_cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#' Create multiple plots of output from the \code{\link{lrren}} function, specifically for the internal k-fold cross-validation diagnostics.
#'
#' @param input An object of class 'list' from the \code{\link{lrren}} function.
#' @param alpha Numeric. The two-tailed alpha level for significance threshold (default is 0.05).
#' @param alpha Numeric. The two-tailed alpha level for the significance threshold (default is 0.05).
#'
#' @return This function produces two plots: 1) area under the receiver operating characteristic curve, and 2) precision-recall curve. Each plot shows predictions for the log relative risk surface. The red-colored lines are the average curves.
#' @return This function produces two plots: 1) area under the receiver operating characteristic curve and 2) precision-recall curve. Each plot shows predictions for the log relative risk surface. The red-colored lines are the average curves.
#'
#' @importFrom cvAUC ci.cvAUC cvAUC
#' @importFrom fields image.plot
Expand Down
Loading

0 comments on commit 004de63

Please sign in to comment.