cv.ani: Demonstration for the process of cross-validation

Description Usage Arguments Details Value Note Author(s) See Also


This function uses rectangles to illustrate the k folds and mark the test set and the training set with different colors.


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



a numerical vector which stands for the sample points.


an integer: how many parts should we split the data into? (comes from the k-fold cross-validation.)


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.


a numeric vector of length 2 specifying the symbols of the test set and training set respectively.


other arguments passed to plot.default


Briefly 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.

The computation of sample sizes is base on kfcv.


None (invisible NULL).


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 ani.options('nmax') and k.

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


Yihui Xie

See Also


Search within the animation package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.