
Thecv package for R provides a consistent andextensible framework for cross-validating standard R statistical models.Some of the functions supplied by the package:
cv() is a generic function with a default method,computationally efficient"lm" and"glm"methods, an"rlm" method (for robust linear models), and amethod for a list of competing models. There are also"merMod","lme", and"glmmTMB"methods for mixed-effects models.cv() supports parallelcomputations.
mse() (mean-squared error),rmse()(root-mean-squared error),medAbsErr() (median absoluteerror), andBayesRule() are cross-validation criteria(“cost functions”), suitable for use withcv().
cv() also can cross-validate a selection procedure(such as the following) for a regression model:
cvModelList() employs CV to select a model fromamong a number of candidates, and then cross-validates thismodel-selection procedure.
selectStepAIC() is a predictor-selection procedurebased on thestepAIC() function in theMASS package.
selectTrans() is a procedure for selecting predictorand response transformations in regression, based on thepowerTransform() function in thecarpackage.
selectTransStepAIC() is a procedure that firstselects predictor and response transformations and then selectspredictors.
For additional introductory information on using thecv package, see the “Cross-validatingregression models” vignette(vignette("cv", package="cv")). There are also vignettes oncross-validatingmixed-effects models(vignette("cv-mixed", package="cv")),cross-validatingmodel selection(vignette("cv-selection", package="cv")), andcomputationaland technical notes(vignette("cv-notes", package="cv")). Thecv package is designed to be extensible to otherclasses of regression models, other CV criteria, and othermodel-selection procedures; for details, see the “Extendingthe cv package” vignette(vignette("cv-extend", package="cv")).
To install the current version of thecv packagefrom CRAN:
install.packages("cv")To install the development version of thecv packagefrom GitHub:
if (!require(remotes)) install.packages("remotes")remotes::install_github("gmonette/cv", build_vignettes=TRUE, dependencies=TRUE)