diff --git a/R/sample_background.R b/R/sample_background.R index e129a27..5d68745 100644 --- a/R/sample_background.R +++ b/R/sample_background.R @@ -19,14 +19,14 @@ #' (see details below). #' @param raster the [terra::SpatRaster] or `stars` from which cells will be sampled (the first layer #' will be used to determine which cells are NAs, and thus can not be sampled). If -#' sampling is "biased", then the sampling probability will be proportional to the values on +#' sampling is "bias", then the sampling probability will be proportional to the values on #' the first layer (i.e. band) of the raster. #' @param n number of background points to sample. #' @param coords a vector of length two giving the names of the "x" and "y" #' coordinates, as found in `data`. If left to NULL, the function will #' try to guess the columns based on standard names `c("x", "y")`, `c("X","Y")`, #' `c("longitude", "latitude")`, or `c("lon", "lat")`. -#' @param method sampling method. One of 'random', 'dist_max', and 'targeted'. +#' @param method sampling method. One of 'random', 'dist_max', and 'bias'. #' For dist_max, the maximum distance is set as an additional element of a vector, #' e.g c('dist_max',70000). #' @param class_label the label given to the sampled points. Defaults to `background` @@ -68,14 +68,14 @@ sample_background <- function(data, raster, n, coords = NULL, } dist_max <- as.numeric(method[2]) } else if (!method[1] %in% c("random", "bias")) { - stop("method has to be one of 'random', 'dist_min', 'dist_max', or 'dist_disc'") + stop("method has to be one of 'random', 'dist_max', or 'bias'") } xy_pres <- as.matrix(as.data.frame(data)[, coords]) # get a one layer raster sampling_raster <- raster[[1]] names(sampling_raster) <- "class" - # remove buffer >dist_max (or second parameter for disc) + # remove buffer >dist_max if (!is.null(dist_max)) { max_buffer <- terra::buffer( terra::vect(xy_pres, diff --git a/R/sample_background_time.R b/R/sample_background_time.R index ae3ba54..9aeecde 100644 --- a/R/sample_background_time.R +++ b/R/sample_background_time.R @@ -1,7 +1,7 @@ #' Sample background points for SDM analysis for points with a time point. #' #' This function samples background points from a raster given a set of presences. -#' The locations returned as the center points of the sampled cells,, which can +#' The locations returned as the center points of the sampled cells, which can #' overlap with the presences (in contrast to pseudo-absences, see #' [sample_pseudoabs_time]). The following methods are implemented: #' * 'random': background points randomly sampled from the region covered by the @@ -31,8 +31,8 @@ #' @param time_col The name of the column with time; if time is not a lubridate object, #' use `lubridate_fun` to provide a function that can be used to convert appropriately #' @param lubridate_fun function to convert the time column into a lubridate object -#' @param method sampling method. One of 'random', 'dist_min', 'dist_max', or -#' 'dist_disc'. +#' @param method sampling method. One of 'random', 'dist_max', or +#' 'bias'. #' @param class_label the label given to the sampled points. Defaults to `background` #' @param return_pres return presences together with background #' in a single tibble @@ -56,7 +56,6 @@ sample_background_time <- function(data, raster, n_per_time_step, coords = NULL, stop("'time_buffer' should only be set with method 'dist_max'") } - # create a vector of times formatted as proper dates time_lub <- data %>% sf::st_drop_geometry() %>% diff --git a/man/sample_background.Rd b/man/sample_background.Rd index fafae94..d8005e2 100644 --- a/man/sample_background.Rd +++ b/man/sample_background.Rd @@ -21,7 +21,7 @@ These can be defined in \code{coords}, unless they have standard names \item{raster}{the \link[terra:SpatRaster-class]{terra::SpatRaster} or \code{stars} from which cells will be sampled (the first layer will be used to determine which cells are NAs, and thus can not be sampled). If -sampling is "biased", then the sampling probability will be proportional to the values on +sampling is "bias", then the sampling probability will be proportional to the values on the first layer (i.e. band) of the raster.} \item{n}{number of background points to sample.} @@ -31,7 +31,7 @@ coordinates, as found in \code{data}. If left to NULL, the function will try to guess the columns based on standard names \code{c("x", "y")}, \code{c("X","Y")}, \code{c("longitude", "latitude")}, or \code{c("lon", "lat")}.} -\item{method}{sampling method. One of 'random', 'dist_max', and 'targeted'. +\item{method}{sampling method. One of 'random', 'dist_max', and 'bias'. For dist_max, the maximum distance is set as an additional element of a vector, e.g c('dist_max',70000).} diff --git a/man/sample_background_time.Rd b/man/sample_background_time.Rd index 952cad5..c82053a 100644 --- a/man/sample_background_time.Rd +++ b/man/sample_background_time.Rd @@ -39,8 +39,8 @@ use \code{lubridate_fun} to provide a function that can be used to convert appro \item{lubridate_fun}{function to convert the time column into a lubridate object} -\item{method}{sampling method. One of 'random', 'dist_min', 'dist_max', or -'dist_disc'.} +\item{method}{sampling method. One of 'random', 'dist_max', or +'bias'.} \item{class_label}{the label given to the sampled points. Defaults to \code{background}} @@ -61,7 +61,7 @@ presence level is set as the reference (to match the expectations in the } \description{ This function samples background points from a raster given a set of presences. -The locations returned as the center points of the sampled cells,, which can +The locations returned as the center points of the sampled cells, which can overlap with the presences (in contrast to pseudo-absences, see \link{sample_pseudoabs_time}). The following methods are implemented: \itemize{