diff --git a/NEWS.md b/NEWS.md index 48b1eecd..92aa5329 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/threshold.R b/R/threshold.R index 7b5dc344..776661da 100644 --- a/R/threshold.R +++ b/R/threshold.R @@ -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 @@ -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. @@ -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', @@ -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', @@ -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 diff --git a/pkgdown/favicon/apple-touch-icon-120x120.png b/pkgdown/favicon/apple-touch-icon-120x120.png index 2766747f..142e8d21 100644 Binary files a/pkgdown/favicon/apple-touch-icon-120x120.png and b/pkgdown/favicon/apple-touch-icon-120x120.png differ diff --git a/pkgdown/favicon/apple-touch-icon-152x152.png b/pkgdown/favicon/apple-touch-icon-152x152.png index 3459cf29..929fc717 100644 Binary files a/pkgdown/favicon/apple-touch-icon-152x152.png and b/pkgdown/favicon/apple-touch-icon-152x152.png differ diff --git a/pkgdown/favicon/apple-touch-icon-180x180.png b/pkgdown/favicon/apple-touch-icon-180x180.png index e22ab0de..27df41f1 100644 Binary files a/pkgdown/favicon/apple-touch-icon-180x180.png and b/pkgdown/favicon/apple-touch-icon-180x180.png differ diff --git a/pkgdown/favicon/apple-touch-icon-60x60.png b/pkgdown/favicon/apple-touch-icon-60x60.png index 42f00214..4622a578 100644 Binary files a/pkgdown/favicon/apple-touch-icon-60x60.png and b/pkgdown/favicon/apple-touch-icon-60x60.png differ diff --git a/pkgdown/favicon/apple-touch-icon-76x76.png b/pkgdown/favicon/apple-touch-icon-76x76.png index d37b5ed3..f3efa90f 100644 Binary files a/pkgdown/favicon/apple-touch-icon-76x76.png and b/pkgdown/favicon/apple-touch-icon-76x76.png differ diff --git a/pkgdown/favicon/apple-touch-icon.png b/pkgdown/favicon/apple-touch-icon.png index 9d041968..b5116d85 100644 Binary files a/pkgdown/favicon/apple-touch-icon.png and b/pkgdown/favicon/apple-touch-icon.png differ diff --git a/pkgdown/favicon/favicon-16x16.png b/pkgdown/favicon/favicon-16x16.png index 258211a2..2d91606d 100644 Binary files a/pkgdown/favicon/favicon-16x16.png and b/pkgdown/favicon/favicon-16x16.png differ diff --git a/pkgdown/favicon/favicon-32x32.png b/pkgdown/favicon/favicon-32x32.png index 56ef9a6e..f7472337 100644 Binary files a/pkgdown/favicon/favicon-32x32.png and b/pkgdown/favicon/favicon-32x32.png differ diff --git a/pkgdown/favicon/favicon.ico b/pkgdown/favicon/favicon.ico index db96b931..36322915 100644 Binary files a/pkgdown/favicon/favicon.ico and b/pkgdown/favicon/favicon.ico differ diff --git a/vignettes/Get_started.Rmd b/vignettes/Get_started.Rmd deleted file mode 100644 index e76d1046..00000000 --- a/vignettes/Get_started.Rmd +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "Get started" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{Get started} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - -```{r setup, eval = FALSE} -library(ibis.iSDM) -```