Skip to content

Commit

Permalink
Merge pull request #35 from adamlilith/solstice_2022_2023
Browse files Browse the repository at this point in the history
Solstice 2022 2023
  • Loading branch information
adamlilith authored Sep 15, 2023
2 parents 804c84d + 817bace commit b83e17b
Show file tree
Hide file tree
Showing 165 changed files with 17,855 additions and 29 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: enmSdmX
Type: Package
Title: Species Distribution Modeling and Ecological Niche Modeling
Version: 1.1.1
Date: 2023-06-22
Version: 1.1.3
Date: 2023-09-15
Authors@R:
c(
person(
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# enmSdmX 1.1.3 2023-09-15
- Added European Datrim 1950 (ED50) to coordinate reference systems table (mea cupla!)

# enmSdmX 1.1.2 2023-09-07
- Minor issue fixes with undocumented arguments for non-exported functions
- Bug fix in `squareCellRast()` that occurred on Linux/Fedora

# enmSdmX 1.1.1 2023-06-11
- Backwards incompatible: `trainRF()` uses `ranger` package for random forests (changed from `randomForest` package)
- Backwards incompatible: `geoFold()` uses `complete` clustering method by default (changed from `single`)
Expand Down
4 changes: 2 additions & 2 deletions R/bioticVelocity.r
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#' \item Root-mean squared difference
#' \item Expected Fraction of Shared Presences or ESP (Godsoe, W. 2014. \emph{Ecography} 37:130-136 \doi{10.1111/j.1600-0587.2013.00403.x})
#' \item D statistic (Schoener, T.W. 1968. \emph{Ecology} 49:704-726. \doi{10.2307/1935534})
#' \item I statistic (Warren, D.L., et al. 2008. \emph{Evolution} 62:2868-2883 \doi{10.111/j.1558-5646.2008.00482.x})
#' \item I statistic (Warren, D.L., et al. 2008. \emph{Evolution} 62:2868-2883 \doi{10.1111/j.1558-5646.2008.00482.x})
#' \item Pearson correlation
#' \item Spearman rank correlation
#' }
Expand Down Expand Up @@ -933,7 +933,6 @@ bioticVelocity <- function(
#' @param x1 Matrix of weights in time 1 (i.e., population size).
#' @param x2 Matrix of weights in time 2 (i.e., population size).
#' @param refCoord Numeric, latitude or longitude (depending on \code{longOrLat}) of reference point from which to partition the weights into a northern, southern, eastern, or western portion.
#' @param refLat Numeric, latitude of reference point.
#' @param x1weightedLongs Matrix of longitudes weighted (i.e., by population size, given by \code{x1}).
#' @param x1weightedLats Matrix of latitudes weighted (i.e., by population size, given by \code{x1}).
#' @param x2weightedLongs Matrix of longitudes weighted (i.e., by population size, given by \code{x2}).
Expand Down Expand Up @@ -1051,6 +1050,7 @@ bioticVelocity <- function(
#' @param weightedElev Raster of elevations weighted by x1 or x2 or \code{NULL}.
#' @param warn Logical. Show warnings.
#' @keywords internal
#' @keywords internal
.interpCoordFromQuantile <- compiler::cmpfun(
function(latOrLong, quants, x, coordVect, weightedElev=NULL, warn=TRUE) {

Expand Down
2 changes: 1 addition & 1 deletion R/evalTjursR2.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @return Numeric value.
#'
#' @references Tjur, T. 2009. Coefficients of determination in logistic regression modelsA new proposal: The coefficient of discrimination. \emph{The American Statistician} 63:366372. \doi{10.1198/tast.2009.08210}.
#' @references Tjur, T. 2009. Coefficients of determination in logistic regression models-A new proposal: The coefficient of discrimination. \emph{The American Statistician} 63:366-372. \doi{10.1198/tast.2009.08210}
#'
#' @seealso \code{\link[dismo]{evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalThresholdStats}}, \code{\link{evalTSS}}
#'
Expand Down
5 changes: 2 additions & 3 deletions R/extentToVect.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#' plot(mad0[1], add=TRUE)
#'
#' @export

extentToVect <- function(x, ...) {

if (inherits(x, c('numeric'))) {
Expand All @@ -29,7 +28,7 @@ extentToVect <- function(x, ...) {

proj <- terra::crs(x)

x <- terra::ext(x)@ptr$vector
x <- as.vector(terra::ext(x))
xCorners <- c(x[1L], x[2L], x[2L], x[1L])
yCorners <- c(x[3L], x[3L], x[4L], x[4L])
corners <- cbind(xCorners, yCorners)
Expand All @@ -49,7 +48,7 @@ extentToVect <- function(x, ...) {
out <- sf::st_as_sf(out, crs=proj)

} else {
stop('Argument "x" must be a vector of 4 numbers, a SpatVector, a SpatRaster, or an sf object.')
stop('Argument x must be a vector of 4 numbers, a SpatVector, a SpatRaster, or an sf object.')
}

out
Expand Down
2 changes: 0 additions & 2 deletions R/geoFoldContrast.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
#' This function generates geographically-distinct cross-validation folds, or "geo-folds" of background or absence sites (i.e., "contrast" sites). Each contrast site is assigned to a fold based on the fold of the presence site that is closest. Typically, this function is run after \code{\link{geoFold}} is run to assign presences to folds.
#'
#' @param contrast A "spatial points" object representing contrast sites:
#' \itemize{
#' \itemize{
#' \item A \code{SpatVector} or \code{sf} vector with points
#' \item A \code{data.frame} or \code{matrix}: Points will be assumed to have the WGS84 coordinate system (i.e., unprojected), and \code{contrastLongLat} should denote the columns with coordinates.
#' }
#' }
#' @param pres A "spatial points" object representing presence sites:
#' \itemize{
#' \item A \code{SpatVector} or \code{sf} vector with points
Expand Down
2 changes: 1 addition & 1 deletion R/nicheOverlapMetrics.r
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' @return List object with one element per value specified by the argument in \code{method}.
#' @references Warren, D.L., Glor, R.E., and Turelli, M. 2008. Environmental niche equivalency versus conservatism: Quantitative approaches to niche evolution. \emph{Evolution} 62:2868-2883. \doi{10.1111/j.1558-5646.2008.00482.x}
#' @references Warren, D.L., Glor, R.E., and Turelli, M. 2008. Erratum. \emph{Evolution} 62:2868-2883. \doi{10.1111/j.1558-5646.2010.01204.x}
#' @references Godsoe, W. 2014. Inferring the similarity of species distributions using Species Distribution Models. \emph{Ecography} 37:130-136. \doi{10.1111/j.1600-0587.2013.00403.x}
#' @references Godsoe, W. 2014. Inferring the similarity of species distributions using Species' Distribution Models. \emph{Ecography} 37:130-136. \doi{10.1111/j.1600-0587.2013.00403.x}
#'
#' @seealso \code{\link[enmSdmX]{compareResponse}}
#' @examples
Expand Down
6 changes: 3 additions & 3 deletions R/predictEnmSdm.r
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ predictEnmSdm <- function(

} else {

preds <- predictRanger(model, data=nd, predict.all=binary, type='response', ...)
out <- predictRanger(model, data=newdata, predict.all=binary, type='response', ...)

if (binary) {
preds <- rowMeans(preds$predictions)
preds <- preds - 1
out <- rowMeans(out$predictions)
out <- out - 1
}

}
Expand Down
3 changes: 2 additions & 1 deletion R/private_calcWeights.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#' Calculates weighting for a model. Each record receives a numeric weight.
#'
#' @param w Either logical in which case \code{TRUE} (default) causes the total weight of presences to equal the total weight of absences (if \code{family='binomial'}) \emph{or} a numeric list of weights, one per row in \code{data} \emph{or} the name of the column in \code{data} that contains site weights. If \code{FALSE}, then each datum gets a weight of 1.
#' @param Data frame
#' @param data Data frame
#' @param resp Name of response column
#' @param family Name of family
#'
#' @returns A numeric vector.
#' @keywords internal
Expand Down
2 changes: 1 addition & 1 deletion R/private_scalePredictors.r
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param data A data frame.
#'
#' @import data.table
#' @noRd
#' @keywords internal
.scalePredictors <- function(scale, preds, data) {

# which predictors are not factors?
Expand Down
2 changes: 1 addition & 1 deletion R/squareCellRast.r
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ squareCellRast <- function(
if (inherits(x, 'sf')) x <- terra::vect(x)

crs <- terra::crs(x)
ext <- terra::ext(x)@ptr$vector
ext <- as.vector(terra::ext(x))
names(ext) <- c('xmin', 'xmax', 'ymin', 'ymax')

longDist <- ext['xmax'] - ext['xmin']
Expand Down
Binary file modified data/crss.rda
Binary file not shown.
45 changes: 45 additions & 0 deletions enmSdmX.Rcheck/00_pkg_src/enmSdmX/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Package: enmSdmX
Type: Package
Title: Species Distribution Modeling and Ecological Niche Modeling
Version: 1.1.2
Date: 2023-09-07
Authors@R:
c(
person(
given = 'Adam B.',
family = 'Smith',
role = c('cre', 'aut'),
email = '[email protected]',
comment = c(ORCID = '0000-0002-6420-1659')
)
)
Maintainer: Adam B. Smith <[email protected]>
Description: Implements species distribution modeling and ecological niche
modeling, including: bias correction, spatial cross-validation, model
evaluation, raster interpolation, biotic "velocity" (speed and
direction of movement of a "mass" represented by a raster), interpolating
across a time series of rasters, and use of spatially imprecise records.
The heart of the package is a set of "training" functions which
automatically optimize model complexity based number of available
occurrences. These algorithms include MaxEnt, MaxNet, boosted regression
trees/gradient boosting machines, generalized additive models,
generalized linear models, natural splines, and random forests. To enhance
interoperability with other modeling packages, no new classes are created.
The package works with 'PROJ6' geodetic objects and coordinate reference
systems.
Depends: R (>= 4.0.0)
Imports: boot, data.table, dismo, doParallel, DT, foreach, gbm,
graphics, ks, maxnet, methods, mgcv, MuMIn, omnibus, parallel,
ranger, rJava, scales, sf, shiny, statisfactory, stats, terra,
utils
Suggests: geodata
LazyData: true
LazyLoad: yes
URL: https://github.com/adamlilith/enmSdmX
BugReports: https://github.com/adamlilith/enmSdmX
Encoding: UTF-8
License: MIT + file LICENSE
RoxygenNote: 7.2.3
NeedsCompilation: no
Packaged: 2023-09-08 17:12:43 UTC; adam
Author: Adam B. Smith [cre, aut] (<https://orcid.org/0000-0002-6420-1659>)
2 changes: 2 additions & 0 deletions enmSdmX.Rcheck/00_pkg_src/enmSdmX/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2022
COPYRIGHT HOLDER: Adam B. Smith
51 changes: 51 additions & 0 deletions enmSdmX.Rcheck/00_pkg_src/enmSdmX/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Generated by roxygen2: do not edit by hand

export(bioticVelocity)
export(compareResponse)
export(coordImprecision)
export(countPoints)
export(customAlbers)
export(customLambert)
export(customVNS)
export(decimalToDms)
export(dmsToDecimal)
export(elimCellDuplicates)
export(evalAUC)
export(evalContBoyce)
export(evalMultiAUC)
export(evalTSS)
export(evalThreshold)
export(evalThresholdStats)
export(evalTjursR2)
export(extentToVect)
export(geoFold)
export(geoFoldContrast)
export(geoThin)
export(getCRS)
export(getValueByCell)
export(globalx)
export(interpolateRasts)
export(longLatRasts)
export(modelSize)
export(nearestEnvPoints)
export(nearestGeogPoints)
export(nicheOverlapMetrics)
export(plotExtent)
export(predictEnmSdm)
export(predictMaxEnt)
export(predictMaxNet)
export(sampleRast)
export(setValueByCell)
export(spatVectorToSpatial)
export(squareCellRast)
export(summaryByCrossValid)
export(trainBRT)
export(trainByCrossValid)
export(trainGAM)
export(trainGLM)
export(trainMaxEnt)
export(trainMaxNet)
export(trainNS)
export(trainRF)
export(weightByDist)
import(data.table)
42 changes: 42 additions & 0 deletions enmSdmX.Rcheck/00_pkg_src/enmSdmX/NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# enmSdmX 1.1.2 2023-09-07
- Minor issue fixes with undocumented arguments for non-exported functions
- Bug fix in `squareCellRast()` that occurred on Linux/Fedora

# enmSdmX 1.1.1 2023-06-11
- Backwards incompatible: `trainRF()` uses `ranger` package for random forests (changed from `randomForest` package)
- Backwards incompatible: `geoFold()` uses `complete` clustering method by default (changed from `single`)
- New feature: `trainGLM()` and `trainNS()` can automatically scale predictors
- New feature: Reworked `trainGLM()` to handle cases with large numbers of predictors
- New feature: Added `geoFoldContrast()` for assigning geo-folds to background or absence sites
- Better functionality: `trainRF()` now indicates if the response is binary using a `binary` argument (vs. `family`, which falsely implied more functionality than RFs have)

# enmSdmX 1.0.6 2023-05-22
- Better functionality: Expanded capacity of .calcWeights() (a hidden function) to handle different values for `family`

# enmSdmX 1.0.5 2023-05-12
- new feature: Added help page for troubleshooting running functions that support parallel operation
- Bug fix: `predictEnmSdm()` when using a BRT model and predicting to a `SpatRaster` (thank you, Nikki C!)

# enmSdmX 1.0.4 2023-04-10
- New feature: Users can select clustering method in `geoThin()` and `geoFold()` (thank you, Pascal T!)
- Bug fix: Example in `customCRS()` when GADM server is down
- Bug fix:`geoThin()` which returned input if it was a `data.frame`*
- Bug fix:`geoThin()` which returned a `data.frame` lacking coordinates if input was a `data.frame` (thank you, Pascal T!)

# enmSdmX 1.0.3 2023-03-07
- Bug fix: Removed Fedora issue with external link to `raster` package
- Bug fix: Added `rJava` dependency

# enmSdmX 1.0.2 2023-03-04
- New feature: `getCRS()` (no arguments) now displays `shiny` table of all available CRSs
- Bug fix: Fixed issue in `nearestGeogPoints()` when polygon lay under centroid
- Bug fix: Fixed bug with "table" call of `getCRS()`

# enmSdmX 1.0.1
- New feature: `summarizeByCrossValid()` now summarizes natural spline (NS) models
- Bug fix: Bug experienced by some users using `predictEnmSdm()` and `predictMaxNet()` (Thank you, Nikki!)
- Bug fix: `trainByCrossValid()` using improper call to `evalContBoyce()`
- Bug fix: `extract()` bug in some examples

# enmSdmX 1.0.0
- First release on CRAN
3 changes: 3 additions & 0 deletions enmSdmX.Rcheck/00_pkg_src/enmSdmX/R/00_datatable_aware.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# needed to use data.table in functions
# https://cran.r-project.org/web/packages/data.table/vignettes/datatable-importing.html
.datatable.aware <- TRUE
13 changes: 13 additions & 0 deletions enmSdmX.Rcheck/00_pkg_src/enmSdmX/R/aaa.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# .onLoad <- function(lib, pkg) {

# }

.onAttach <- function(lib, pkg) {

ver <- read.dcf(file=system.file('DESCRIPTION', package=pkg), fields='Version')
packageStartupMessage(paste0('This is ', pkg, ' ', ver, '.'))
packageStartupMessage(paste0('* Back-incompatible changes starting starting with enmSdmX version 1.1.1:'))
packageStartupMessage(paste0('* trainRF() replaces use of the randomForest package with the faster ranger package, which produces random forests that are statistically equivalent.'))
packageStartupMessage(paste0('geoFold() uses ', dQuote('complete'), ' clustering by default (was ', dQuote('single'), ').'))

}
Loading

0 comments on commit b83e17b

Please sign in to comment.