Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kmeans fixed #412

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/auxiliary_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ mah_dist <- function(x, y, cov) {
#' @noRd
#'
kf <- function(df, n){
suppressWarnings(km <- stats::kmeans(env_changed %>% dplyr::select(-c(cell:y)),
suppressWarnings(km <- stats::kmeans(df %>% dplyr::select(-c(cell:y)),
centers = n))
result <- data.frame(cluster = km$cluster, cell = names(km$cluster)) %>%
dplyr::as_tibble() %>%
Expand All @@ -454,7 +454,7 @@ kf <- function(df, n){
dplyr::group_by() %>%
dplyr::pull(cell) %>%
as.numeric()
result <- env_changed %>%
result <- df %>%
dplyr::filter(cell %in% result) %>%
dplyr::select(x, y) %>%
dplyr::as_tibble()
Expand Down
6 changes: 3 additions & 3 deletions R/sample_pseudoabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' provide a vector for this argument. The methods implemented are:
#' \itemize{
#' \item random: Random allocation of pseudo-absences throughout the area used for model fitting. Usage method='random'.
#' \item kmeans: Pseudo-absences are sampled randomly within environmental clusters defined by k-means
#' \item kmeans: Pseudo-absences are sampled randomly within environmental clusters defined by K-means
#' cluster analysis (the number of clusters will equal than number of pseudo-absences defined in 'n').
#' For this method, it is necessary to provide a raster object with environmental
#' variables. Usage method = c('kmeans', env = somevar).
Expand All @@ -22,7 +22,7 @@
#' \item geo_env_const: Pseudo-absences are constrained environmentally (based on Bioclim model) and distributed geographically far from occurrences based on a geographical buffer. For this method, a raster with environmental variables stored as SpatRaster object should be provided. A value of the buffer width in m must be provided if raster (used in rlayer) has a longitude/latitude CRS, or in map units in other cases. Usage method=c('geo_env_const', width='50000', env = somevar).
#' \item geo_env_km_const: Pseudo-absences are constrained using a three-level procedure; it is similar to
#' the geo_env_const with an additional step which distributes the pseudo-absences in environmental space
#' using k-means cluster analysis. For this method, it is necessary to provide a raster object with
#' using K-means cluster analysis. For this method, it is necessary to provide a raster object with
#' environmental variables and a value of the buffer width in m if raster (used in rlayer) has a
#' longitude/latitude CRS, or map units in other cases. Usage method=c('geo_env_km_const',
#' width='50000', env = somevar).
Expand Down Expand Up @@ -105,7 +105,7 @@
#' points(single_spp[-1], col = "blue", cex = 0.7, pch = 19)
#' points(ps1, col = "red", cex = 0.7, pch = 19)
#'
#' # Pseudo-absences sampled with K-mean approach
#' # Pseudo-absences sampled with K-means approach
#' set.seed(123)
#' ps1 <-
#' sample_pseudoabs(
Expand Down
6 changes: 3 additions & 3 deletions man/sample_pseudoabs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading