kfold_disc: Create k disc based folds for cross-validation

Description Usage Arguments Value See Also Examples

View source: R/kfold.R

Description

kfold_disc creates a k-fold partitioning of geographical data for cross-validation based on the distance between points. The n points nearest to a selected point are put into a group. Returns a vector with fold numbers ranging from 1 to k.

Usage

1
kfold_disc(data, k = 5, lonlat = TRUE)

Arguments

data

Matrix or dataframe. The first two columns should represent the longitude and latitude (or x,y coordinates if lonlat = FALSE).

k

Integer. The number of folds (partitions) that have to be created. By default 5 folds are created.

lonlat

Logical. If TRUE (default) then Great Circle distances are calculated else if FALSE Euclidean (planar) distances are calculated.

Value

A vector with fold numbers ranging from 1 to k.

See Also

plot_folds, kfold_grid, kfold, kfold_occurrence_background

Examples

1
2
3
4
5
6
7
8
9
set.seed(42)
lonlat_data <- cbind(runif(11, -180, 180), runif(11, -90, 90))
folds <- kfold_disc(lonlat_data, k = 5)
plot_folds(lonlat_data, folds)

# use the euclidean distance
xy_data <- cbind(runif(11, 0, 100), runif(11, 0, 100))
folds <- kfold_disc(xy_data, k = 5, lonlat = FALSE)
plot_folds(xy_data, folds)

samuelbosch/marinespeed documentation built on Dec. 17, 2019, 11:47 p.m.