spatialBlock: Use spatial blocks to separate train and test folds

View source: R/v2_spatialBlock.R

spatialBlockR Documentation

Use spatial blocks to separate train and test folds


This function is deprecated and will be removed in future updates! Please use cv_spatial instead!


  species = NULL,
  rasterLayer = NULL,
  theRange = NULL,
  rows = NULL,
  cols = NULL,
  k = 5L,
  selection = "random",
  iteration = 100L,
  blocks = NULL,
  foldsCol = NULL,
  numLimit = 0L,
  maskBySpecies = TRUE,
  degMetre = 111325,
  border = NULL,
  showBlocks = TRUE,
  biomod2Format = TRUE,
  xOffset = 0,
  yOffset = 0,
  extend = 0,
  seed = 42,
  progress = TRUE,
  verbose = TRUE



A simple features (sf) or SpatialPoints object containing species data (response variable).


Character (optional). Indicating the name of the column in which species data (response variable e.g. 0s and 1s) is stored. This argument is used to make folds with evenly distributed records. This option only works by random fold selection and with binary or multi-class responses e.g. species presence-absence/background or land cover classes for remote sensing image classification. If speceis = NULL the response classes will be treated the same and only training and testing records will be counted and balanced.


A raster object for visualisation (optional). If provided, this will be used to specify the blocks covering the area.


Numeric value of the specified range by which blocks are created and training/testing data are separated. This distance should be in metres. The range could be explored by spatialAutoRange() and rangeExplorer() functions.


Integer value by which the area is divided into latitudinal bins.


Integer value by which the area is divided into longitudinal bins.


Integer value. The number of desired folds for cross-validation. The default is k = 5.


Type of assignment of blocks into folds. Can be random (default), systematic, checkerboard, or predefined. The checkerboard does not work with user-defined spatial blocks. If the selection = 'predefined', user-defined blocks and foldsCol must be supplied.


Integer value. The number of attempts to create folds that fulfil the set requirement for minimum number of points in each training and testing fold (for each response class e.g. train_0, train_1, test_0 and test_1), as specified by species and numLimit arguments.


A sf or SpatialPolygons object to be used as the blocks (optional). This can be a user defined polygon and it must cover all the species (response) points. If the selection = 'predefined', this argument (and foldsCol) must be supplied.


Character. Indicating the name of the column (in user-defined blocks) in which the associated folds are stored. This argument is necessary if you choose the 'predefined' selection.


deprecated option!


Since version 1.1, this option is always set to TRUE.


Integer. The conversion rate of metres to degree. See the details section for more information.


deprecated option!


Logical. If TRUE the final blocks with fold numbers will be created with ggplot and plotted. A raster layer could be specified in rasterlayer argument to be as background.


Logical. Creates a matrix of folds that can be directly used in the biomod2 package as a DataSplitTable for cross-validation.


Numeric value between 0 and 1 for shifting the blocks horizontally. The value is the proportion of block size.


Numeric value between 0 and 1 for shifting the blocks vertically. The value is the proportion of block size.


numeric; This parameter specifies the percentage by which the map's extent is expanded to increase the size of the square spatial blocks, ensuring that all points fall within a block. The value should be a numeric between 0 and 5.


Integer. A random seed generator for reproducibility.


Logical. If TRUE shows a progress bar when numLimit = NULL in random fold selection.


Logical. To print the report of the recods per fold.

See Also


blockCV documentation built on June 7, 2023, 5:55 p.m.