Skip to content

Commit

Permalink
Merge pull request #36 from adamlilith/solstice_2022_2023
Browse files Browse the repository at this point in the history
Solstice 2022 2023
  • Loading branch information
adamlilith authored Mar 6, 2024
2 parents b83e17b + e7b4a62 commit e847e00
Show file tree
Hide file tree
Showing 184 changed files with 956 additions and 17,889 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: enmSdmX
Type: Package
Title: Species Distribution Modeling and Ecological Niche Modeling
Version: 1.1.3
Date: 2023-09-15
Date: 2023-03-06
Authors@R:
c(
person(
Expand All @@ -13,7 +13,6 @@ Authors@R:
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
Expand All @@ -32,7 +31,6 @@ Depends:
Imports:
boot,
data.table,
dismo,
doParallel,
DT,
foreach,
Expand All @@ -45,11 +43,13 @@ Imports:
MuMIn,
omnibus,
parallel,
predicts,
ranger,
rJava,
scales,
sf,
shiny,
sp,
statisfactory,
stats,
terra,
Expand All @@ -62,4 +62,4 @@ URL: https://github.com/adamlilith/enmSdmX
BugReports: https://github.com/adamlilith/enmSdmX
Encoding: UTF-8
License: MIT + file LICENSE
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ export(trainNS)
export(trainRF)
export(weightByDist)
import(data.table)
importFrom(stats,predict)
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# enmSdmX 1.1.3 2023-09-15
- Added European Datrim 1950 (ED50) to coordinate reference systems table (mea cupla!)
# enmSdmX 1.1.3 2023-02-02
- Removed dependency on `dismo`, replaced where possible by `predicts`; copied `gbm.step()` and `predict()` method for MaxEnt to `enmSdmX` as a momentary fix; would love a professional solution!
- Added European Datum 1950 (ED50) to coordinate reference systems table
- Added ability to export intermediate values for plotting in `evalContBoyce()`
- Fixed spelling errors in `crss` data table (coordinate reference system names)

# enmSdmX 1.1.2 2023-09-07
- Minor issue fixes with undocumented arguments for non-exported functions
Expand Down
1 change: 1 addition & 0 deletions R/01_imports.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#' @import predicts::MaxEnt_model
4 changes: 2 additions & 2 deletions R/aaa.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

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('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'), ').'))
packageStartupMessage(paste0('* geoFold() uses ', dQuote('complete'), ' clustering by default (was ', dQuote('single'), ').'))

}
2 changes: 1 addition & 1 deletion R/evalAUC.r
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param ... Other arguments (unused).
#' @return A Numeric value.
#'
#' @seealso \code{\link[dismo]{evaluate}}, \code{\link{evalMultiAUC}}
#' @seealso \code{\link[predicts]{pa_evaluate}}, \code{\link{evalMultiAUC}}
#'
#' @examples
#' pres <- seq(0.5, 1, by=0.1)
Expand Down
18 changes: 15 additions & 3 deletions R/evalContBoyce.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
#' @param method Character. Type of correlation to calculate. The default is \code{'spearman'}, the Spearman rank correlation coefficient used by Boyce et al. (2002) and Hirzel et al. (2006), which is the "traditional" CBI. In contrast, \code{'pearson'} or \code{'kendall'} can be used instead. See \code{\link[stats]{cor}} for more details.
#' @param dropZeros Logical. If \code{TRUE} then drop all bins in which the frequency of presences is 0.
#' @param graph Logical. If \code{TRUE} then plot P vs E and P/E versus bin.
#' @param table Logical. If \code{TRUE}, the function will also return a table of P (proportion of presence weights per bin), E (expected proportion of presence weights per bin--from contrast sites), and the ratio of the two.
#' @param na.rm Logical. If \code{TRUE} then remove any presences and associated weights and background predictions and associated weights with \code{NA}s.
#' @param ... Other arguments (not used).
#'
#' @return Numeric value.
#' @return Numeric value, or if \code{table} is \code{TRUE}, then a list object with CBI plus a data frame with P (proportion of presence weights per bin), E (expected proportion of presence weights per bin--from contrast sites), and the ratio of the two.
#'
#' @details CBI is the Spearman rank correlation coefficient between the proportion of sites in each prediction class and the expected proportion of predictions in each prediction class based on the proportion of the landscape that is in that class. The index ranges from -1 to 1. Values >0 indicate the model's output is positively correlated with the true probability of presence. Values <0 indicate it is negatively correlated with the true probability of presence.
#'
#' @references Boyce, M.S., Vernier, P.R., Nielsen, S.E., and Schmiegelow, F.K.A. 2002. Evaluating resource selection functions. \emph{Ecological Modeling} 157:281-300. \doi{https://doi.org/10.1016/S0304-3800(02)00200-4}
#' @references Hirzel, A.H., Le Lay, G., Helfer, V., Randon, C., and Guisan, A. 2006. Evaluating the ability of habitat suitability models to predict species presences. \emph{Ecological Modeling} 199:142-152. \doi{10.1016/j.ecolmodel.2006.05.017}
#'
#' @seealso \code{\link[stats]{cor}}, \code{\link[dismo]{evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalThresholdStats}}, \code{\link{evalTjursR2}}, \code{\link{evalTSS}}
#' @seealso \code{\link[stats]{cor}}, \code{\link[predicts]{pa_evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalThresholdStats}}, \code{\link{evalTjursR2}}, \code{\link{evalTSS}}
#'
#' @examples
#'
Expand All @@ -47,6 +48,7 @@ evalContBoyce <- function(
method = 'spearman',
dropZeros = TRUE,
graph = FALSE,
table = FALSE,
na.rm = FALSE,
...
) {
Expand Down Expand Up @@ -154,6 +156,16 @@ evalContBoyce <- function(

# calculate continuous Boyce index (cbi)
cbi <- stats::cor(x=meanPred, y=PE, method=method)
cbi

if (table) {
out <- list(
table = data.frame(bin = 1:numBins, propPres = P, propExpected = E, PtoERatio = PE),
cbi = cbi
)
} else {
out <- cbi
}

out

}
2 changes: 1 addition & 1 deletion R/evalMultiAUC.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @return Named numeric vector. The names will appear as \code{case2_over_case1} (which in this example means the AUC of item #1 in the \code{...} when compared to the second item in \code{...}), plus \code{multivariate} (which is the multivariate AUC).
#'
#' @seealso \code{\link[dismo]{evaluate}}, \code{\link{evalAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalThresholdStats}}, \code{\link{evalTjursR2}}, \code{\link{evalTSS}}
#' @seealso \code{\link[predicts]{pa_evaluate}}, \code{\link{evalAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalThresholdStats}}, \code{\link{evalTjursR2}}, \code{\link{evalTSS}}
#'
#' @references
#' Hand, DJ and Till, RJ. 2001. A simple generalisation of the area under the ROC curve for multiple class classification problems. \emph{Machine Learning} 45:171-186 \doi{10.1023/A:1010920819831}.
Expand Down
10 changes: 1 addition & 9 deletions R/evalTSS.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @details This function calculates the maximum value of the True Skill Statistic (i.e., across all thresholds, the values that maximizes sensitivity plus specificity).
#' @references See Allouche, O., Tsoar, A., and Kadmon, R. 2006. Assessing the accuracy of species distribution models: Prevalence, kappa and the true skill statistic (TSS). \emph{Journal of Applied Ecology} 43:1223-1232. \doi{10.1111/j.1365-2664.2006.01214.x}
#'
#' @seealso \code{\link[dismo]{evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalThresholdStats}}, \code{\link{evalTjursR2}}
#' @seealso \code{\link[predicts]{pa_evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalThresholdStats}}, \code{\link{evalTjursR2}}
#'
#' @examples
#' set.seed(123)
Expand All @@ -34,14 +34,6 @@
#' presWeight <- c(rep(0.1, 30), rep(1, 30))
#' evalTSS(pres, contrast, presWeight=presWeight)
#'
#' e <- dismo::evaluate(pres, contrast)
#' max(e@TPR + e@TNR) - 1
#'
#' # Why different values from dismo's evaluate() function?
#' # Because dismo's function uses thresholds based on presence/non-presence
#' # values, whereas evalTSS uses equall-spaced thresholds.
#' head(e@t)
#'
#' @export
evalTSS <- function(
pres,
Expand Down
4 changes: 2 additions & 2 deletions R/evalThreshold.r
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Weighted thresholds for predictions
#'
#' This function is similar to the \code{\link[dismo]{threshold}} function in the \pkg{dismo} package, which calculates thresholds to create binary predictions from continuous values. However, unlike that function, it allows the user to specify weights for presences and absence/background predictions. The output will thus be the threshold that best matches the specified criterion taking into account the relative weights of the input values.
#' This function is similar to the \code{\link[predicts]{threshold}} function in the \pkg{predicts} package, which calculates thresholds to create binary predictions from continuous values. However, unlike that function, it allows the user to specify weights for presences and absence/background predictions. The output will thus be the threshold that best matches the specified criterion taking into account the relative weights of the input values.
#' @param pres Numeric vector. Predicted values at test presences.
#' @param contrast Numeric vector. Predicted values at background/absence sites.
#' @param presWeight Numeric vector same length as \code{pres}. Relative weights of presence sites. The default is to assign each presence a weight of 1.
Expand All @@ -20,7 +20,7 @@
#' @return Named numeric vector.
#' Fielding, A.H. and J.F. Bell. 1997. A review of methods for the assessment of prediction errors in conservation presence/absence models. \emph{Environmental Conservation} 24:38-49. \doi{10.1017/S0376892997000088}
#'
#' @seealso \code{\link[dismo]{threshold}}, \code{\link[dismo]{evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThresholdStats}}, \code{\link{evalTjursR2}}, \code{\link{evalTSS}}
#' @seealso \code{\link[predicts]{threshold}}, \code{\link[predicts]{pa_evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThresholdStats}}, \code{\link{evalTjursR2}}, \code{\link{evalTSS}}
#'
#' @examples
#' set.seed(123)
Expand Down
2 changes: 1 addition & 1 deletion R/evalThresholdStats.r
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' }
#' Fielding, A.H. and J.F. Bell. 1997. A review of methods for the assessment of prediction errors in conservation presence/absence models. \emph{Environmental Conservation} 24:38-49. \doi{10.1017/S0376892997000088}
#'
#' @seealso \code{\link[dismo]{threshold}}, \code{\link[dismo]{evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalTjursR2}}, \code{\link{evalTSS}}
#' @seealso \code{\link[predicts]{threshold}}, \code{\link[predicts]{pa_evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalTjursR2}}, \code{\link{evalTSS}}
#'
#' @examples
#' set.seed(123)
Expand Down
2 changes: 1 addition & 1 deletion R/evalTjursR2.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' @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}}
#' @seealso \code{\link[predicts]{pa_evaluate}}, \code{\link{evalAUC}}, \code{\link{evalMultiAUC}}, \code{\link{evalContBoyce}}, \code{\link{evalThreshold}}, \code{\link{evalThresholdStats}}, \code{\link{evalTSS}}
#'
#' @examples
#' pres <- seq(0.5, 1, by=0.1)
Expand Down
Loading

0 comments on commit e847e00

Please sign in to comment.