randomFolds: Create Random Folds

Description Usage Arguments Details Value Author(s) Examples

View source: R/randomFolds.R

Description

Create random folds for cross validation.

Usage

1
randomFolds(data, k, only_presence = FALSE, seed = NULL)

Arguments

data

SWD object that will be used to train the model.

k

integer. Number of fold used to create the partition.

only_presence

logical, if TRUE the random folds are created only for the presence locations and all the background locations are included in each fold, used manly for presence-only methods, default is FALSE.

seed

integer. The value used to set the seed for the fold partition, default is NULL.

Details

When only_presence = FALSE, the proportion of presence and absence is preserved.

Value

list with two matrices, the first for the training and the second for the testing dataset. Each column of one matrix represents a fold with TRUE for the locations included in and FALSE excluded from the partition.

Author(s)

Sergio Vignali

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
                    pattern = "grd", full.names = TRUE)
predictors <- raster::stack(files)

# Prepare presence and background locations
p_coords <- virtualSp$presence
bg_coords <- virtualSp$background

data <- prepareSWD(species = "Virtual species", p = p_coords, a = bg_coords,
                   env = predictors, categorical = "biome")

# Create 4 random folds splitting presence and absence locations
folds <- randomFolds(data, k = 4)

# Create 4 random folds splitting only the presence locations
folds <- randomFolds(data, k = 4, only_presence = TRUE)

SDMtune documentation built on July 17, 2021, 9:06 a.m.