cv.ani {animation}R Documentation

Demonstration for the process of cross-validation

Description

Simply speaking, the process of cross-validation is just to split the whole data set into several parts and select one part as the test set and the rest parts as the training set. This function uses rectangles to illustrate these `parts' and mark the test set & the training set with different colors.

Usage

cv.ani(x = runif(150), k = 10, col = c("green", "red", "blue"),
    pch = c(4, 1), ...)

Arguments

x a numerical vector which stands for the sample points.
k an integer: how many parts should we split the data into? (comes from the k-fold cross-validation.)
col a character vector of length 3 specifying the colors of: the rectangle representing the test set, the points of the test set, and points of the training set.
pch a numeric vector of length 2 specifying the symbols of the test set and training set respectively.
... other arguments passed to plot

Details

The computation of sample sizes is base on kfcv.

Value

None (invisible `NULL').

Note

For the `leave-one-out' cross-validation, just specify k as length(x), then the rectangles will `shrink' into single lines.

The final number of animation frames is the smaller one of nmax and k.

This function has nothing to do with specific models used in cross-validation.

Author(s)

Yihui Xie

References

http://animation.yihui.name/dmml:k-fold_cross-validation

See Also

kfcv

Examples

oopt = ani.options(interval = 2, nmax = 10)
cv.ani(main = "Demonstration of the k-fold Cross Validation", bty = "l")

# leave-one-out CV 
cv.ani(x = runif(15), k = 15) 

## Not run: 
 
# save the animation in HTML pages
ani.options(ani.height = 400, ani.width = 600, outdir = getwd(), interval = 2,
    nmax = 10, title = "Demonstration of the k-fold Cross Validation",
    description = "This is a naive demonstration for the k-fold cross
    validation. The k rectangles in the plot denote the k folds of data.
    Each time a fold will be used as the test set and the rest parts
    as the training set.")
ani.start()
par(mar = c(3, 3, 1, 0.5), mgp = c(1.5, 0.5, 0), tcl = -0.3)
cv.ani(bty = "l")
ani.stop()

## End(Not run)
ani.options(oopt)

[Package animation version 1.0-4 Index]