cvsegments {pls} | R Documentation |
The function generates a list of segments for cross-validation. Random, consecutive and interleaved segments can be produced.
cvsegments(N, k, length.seg = ceiling(N/k), type = c("random", "consecutive", "interleaved"))
N |
Integer. The number of objects in the data set. |
k |
Integer. The number of segments to return. |
length.seg |
Integer. The length of the segments. If
given, it overrides k . |
type |
One of "random", "consecutive" and "interleaved". The type of segments to generate. Default is "random". |
If length.seg
is specified, it is used to calculate the number of
segments to generate. Otherwise k
must be specified. If
k*length.seg <> N, the
k*length.seg - N last segments will contain only
length.seg - 1 indices.
If type
is "random", the indices are allocated to
segments in random order. If it is "consecutive", the first
segment will contain the first length.seg indices, and so on.
If type
is "interleaved", the first segment will contain
the indices 1, length.seg+1, 2*lenght.seg+1, ...,
(k-1)*length.seg+1, and so on.
A list of vectors. Each vector contains the indices for one segment.
The attribute "incomplete"
contains the number of incomplete
segments, and the attribute "type"
contains the type of segments.
Bjørn-Helge Mevik and Ron Wehrens
## Segments for 10-fold randomised cross-validation: cvsegments(100, 10) ## Segments with four objects, taken consecutive: cvsegments(60, length.seg = 4, type = "cons") ## Incomplete segments segs <- cvsegments(50, length.seg = 3) attr(segs, "incomplete") ## Leave-one-out cross-validation: cvsegments(100, 100) ## Leave-one-out with variable/unknown data set size n: n <- 50 cvsegments(n, length.seg = 1)