Skip to contents

Combines the cross-validation results of different models. The “...” arguments can include cvs, models or multimodels. cv() will be applied to the (multi)models in “...”, using the folds from x. All “cv” objects in “...” must have the same folds as x.

Usage

# S3 method for cv
c(x, ..., param = TRUE)

Arguments

x

An object of class “cv”.

...

One or several models, multimodels or cvs. Any cv must have the same folds as x.

param

Logical: Keep the parameter table? See multimodel.

Value

An object of class “cv” including all models featured in x and “...”.

See also

Examples

mod1 <- model(lm(mpg ~ cyl, mtcars), label = "simpleLinear")
mod2 <- model(lm(mpg ~ ., mtcars), label = "linear")
# Define common folds
mtcars_folds <- make_folds(mtcars, nfold = 5)
# Cross validate both models separately
cv1 <- cv(mod1, folds = mtcars_folds)
cv2 <- cv(mod2, folds = mtcars_folds)
# Combine the two
cv_cars <- c(cv1, cv2)
cv_performance(cv_cars)
#> --- Performance table ---
#> Metric: rmse
#>              train_rmse test_rmse time_cv
#> simpleLinear     3.0725    3.2240   0.006
#> linear           2.0398    3.2441   0.009

# Add a model to a cv object:
c(cv_cars, constant = model(lm(mpg ~ 1, mtcars)))
#> --- A “cv” object containing 3 validated models ---
#> 
#> Validation procedure: Complete k-fold Cross-Validation
#>   Number of obs in data:   32
#>   Number of test sets:      5
#>   Size of test sets:       ~6
#>   Size of training sets:  ~26
#> 
#> Models:
#> 
#> ‘simpleLinear’:
#>   model class:  lm
#>   formula:      mpg ~ cyl
#>   metric:       rmse
#> 
#> ‘linear’:
#>   model class:  lm
#>   formula:      mpg ~ cyl + disp + hp + drat + wt + qsec + vs + 
#>                     am + gear + carb
#>   metric:       rmse
#> 
#> ‘constant’:
#>   model class:  lm
#>   formula:      mpg ~ 1
#>   metric:       constant.rmse