Skip to contents

Generate spatio-temporal cross-validation index

Usage

generate_cv_index(
  covars,
  cv_mode = c("lolo", "loto", "random", "lblo", "lbto", "lblto", "lolto", "loo"),
  cv_fold = 5L,
  sp_fold = NULL,
  t_fold = NULL,
  blocks = NULL,
  block_id = NULL
)

Arguments

covars

data.frame-like object with lon, lat, and time columns. See prep_input() for details.

cv_mode

character(1). One of "lolo" (leave-one-location-out), "loto" (leave-one-time-out), "lolto" (leave-one-location-time-out), "lblo" (leave-block-location-out), "lbto" (leave-block-time-out), "loo", "lblto" (leave-block-location-time-out) "random" (full random selection)

cv_fold

integer(1). Number of folds for cross-validation.

sp_fold

integer(1). Number of subfolds for spatial blocks.

t_fold

integer(1). Number of subfolds for temporal blocks.

blocks

integer(2)/sf/SpatVector object.

block_id

character(1). The unique identifier of each block.

Value

A numeric vector with length of the number of input rows

Details

blocks is NULL as default (i.e., no block structure is considered); then "lb*" cv_mode is not working. blocks should be one of integer vector (length 2), sf, sftime, or SpatVector object. Please be advised that we cannot provide error messages related to the blocks type invalidity due to the cyclometric complexity. If any valid object is assigned here, cv_fold will not make sense and be ignored. Definition of unit grid (horizontal, vertical) size, arbitrary shape of blocks (sf/SpatVector case) where users can consider common spatial hierarchies such as states, counties, hydrological unit code areas, etc. lblto mode will accept sp_fold and t_fold. The maximum of results in this case is sp_fold * t_fold.

Author

Insang Song

Examples

data(spdat)

lolo <- generate_cv_index(spdat, cv_mode = "lolo")
loto <- generate_cv_index(spdat, cv_mode = "loto")
lolto <- generate_cv_index(spdat, cv_mode = "lolto")
lblo <- generate_cv_index(spdat, cv_mode = "lblo", cv_fold = 5)
lbto <- generate_cv_index(spdat, cv_mode = "lbto", cv_fold = 5)
lblto <- generate_cv_index(spdat, cv_mode = "lblto", sp_fold = 5, t_fold = 4)
random <- generate_cv_index(spdat, cv_mode = "random", cv_fold = 5)
plot_cv_folds(spdat, lblto)