Skip to content

Commit

Permalink
Addition of k-means threshold approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Jung committed Aug 23, 2024
1 parent 7c5309b commit db0c362
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 21 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# ibis.iSDM 0.1.5 (current dev branch)

#### New features
* Support for 'modal' value calculations in `ensemble()` and export of method.
* Support for 'modal' value calculations in `ensemble()`.
* Support for 'superlearner' in `ensemble()`.
* Support for 'kmeans' derived threshold calculation in `threshold()`
* Support for future processing streamlined. See FAQ section for instructions #18.

#### Minor improvements and bug fixes
Expand Down
18 changes: 17 additions & 1 deletion R/threshold.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#' @param return_threshold Should threshold value be returned instead (Default: \code{FALSE})
#' @param ... other parameters not yet set.
#'
#' @details The following options are currently implemented:
#' @details
#' The following options are currently implemented:
#'
#' * \code{'fixed'} = applies a single pre-determined threshold. Requires \code{value}
#' to be set.
#' * \code{'mtp'} = minimum training presence is used to find and set the lowest
Expand All @@ -52,6 +54,8 @@
#' Requires the \code{"modEvA"} package to be installed.
#' * \code{'AUC'} = Determines the optimal AUC of presence records. Requires the
#' \code{"modEvA"} package to be installed.
#' * \code{'kmeans'} = Determines a threshold based on a 2 cluster k-means clustering.
#' The presence class is assumed to be the cluster with the larger mean.
#'
#' @returns A [SpatRaster] if a [SpatRaster] object as input. Otherwise the threshold
#' is added to the respective [`DistributionModel`] or [`BiodiversityScenario`] object.
Expand Down Expand Up @@ -113,6 +117,7 @@ methods::setMethod(
)
# Matching for correct method
method <- match.arg(method, c('fixed','mtp','percentile','min.cv',
'kmeans',
# modEvA measures
'TSS','kappa','F1score','Sensitivity','Specificity',
'Misclass','Omission','Commission','Precision',
Expand Down Expand Up @@ -264,6 +269,7 @@ methods::setMethod(

# Match to correct spelling mistakes
method <- match.arg(method, c('fixed','mtp','percentile','min.cv',
'kmeans',
# modEvA measures
'TSS','kappa','F1score','Sensitivity','Specificity',
'Misclass','Omission','Commission','Precision',
Expand Down Expand Up @@ -325,6 +331,16 @@ methods::setMethod(
# Combine as a vector
tr <- c(tr, value)

} else if(method == 'kmeans') {
# K-means based clustering. Presence and absences are identified through
# by getting the value within regular sampled values
val <- terra::spatSample(raster_thresh, size = 1e6, method = "regular",
na.rm = TRUE, exhaustive = TRUE)
val <- subset(val, complete.cases(val))
if(nrow(val)<5) stop("Not enough values for clustering found...")
clus <- stats::kmeans(val, centers = 2)
tr <- clus$centers[which.min(clus$centers[,1])]
rm(clus, val)
} else {
# Optimized threshold statistics using the modEvA package
# FIXME: Could think of porting these functions but too much effort for
Expand Down
Binary file modified pkgdown/favicon/apple-touch-icon-120x120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pkgdown/favicon/apple-touch-icon-152x152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pkgdown/favicon/apple-touch-icon-180x180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pkgdown/favicon/apple-touch-icon-60x60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pkgdown/favicon/apple-touch-icon-76x76.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pkgdown/favicon/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pkgdown/favicon/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pkgdown/favicon/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pkgdown/favicon/favicon.ico
Binary file not shown.
19 changes: 0 additions & 19 deletions vignettes/Get_started.Rmd

This file was deleted.

0 comments on commit db0c362

Please sign in to comment.