cv_model() fits a model.

cv_model(x, ...)

# S3 method for default
cv_model(x, ...)

# S3 method for data.frame
cv_model(x, y, intercept = TRUE, ...)

# S3 method for matrix
cv_model(x, y, intercept = TRUE, ...)

# S3 method for formula
cv_model(formula, data, intercept = TRUE, ...)

# S3 method for recipe
cv_model(x, data, intercept = TRUE, ...)

Arguments

x

Depending on the context:

  • A data frame of predictors.

  • A matrix of predictors.

  • A recipe specifying a set of preprocessing steps created from recipes::recipe().

...

See Details

y

When x is a data frame or matrix, y is the outcome specified as:

  • A data frame with 1 numeric column.

  • A matrix with 1 numeric column.

  • A numeric vector.

intercept

Should intercept column be created? Default is TRUE.

formula

A formula specifying the outcome terms on the left-hand side, and the predictor terms on the right-hand side.

data

When a recipe or formula is used, data is specified as:

  • A data frame containing both the predictors and the outcome.

Value

A bmbstats_cv_model object.

Details

Extra parameters using ... are forwarded to implementation function. These parameters are the following:

model_func

Model function. Default is lm_model. See also baseline_model

predict_func

Predict function. Default is generic_predict

perf_func

Model performance function. Default is performance_metrics

SESOI_lower

Function or numeric scalar. Default is SESOI_lower_func

SESOI_upper

Function or numeric scalar. Default is SESOI_upper_func

control

Control structure using model_control. The parameters used in cv_model are cv_folds, and cv_strata

na.rm

Should NAs be removed? Default is FALSE. This is forwarded to model_func, predict_func, perfr_func, SESOI_lower, and SESOI_upper

In summary, cv_model represents a wrapper function, that performs model_func within the cross-validation loop and provide it's predictive performance metrics using perf_func

Examples

data("vertical_jump_data") m1 <- cv_model( `Post-test` ~ `Pre-test` * Group * `Squat 1RM`, vertical_jump_data, control = model_control( cv_repeats = 10, cv_folds = 3, cv_strata = vertical_jump_data$Group ) )
#> Cross-validating: 3 folds, 10 repeats
#> Done!
m1
#> Training data consists of 8 predictors and 30 observations. Cross-Validation of the model was performed using 10 repeats of 3 folds. #> #> Model performance: #> #> metric training training.pooled testing.pooled mean #> MBE -1.563192e-14 1.894792e-15 0.1826778 0.1826778 #> MAE 8.763836e-01 7.121335e-01 1.4909445 1.4909445 #> RMSE 1.059620e+00 9.051436e-01 2.0197935 1.9203781 #> PPER 7.787868e-01 8.561700e-01 0.4872447 0.5048117 #> SESOI to RMSE 2.543190e+00 2.929626e+00 1.3128731 1.5571820 #> R-squared 9.744091e-01 9.813267e-01 0.9077786 0.8959661 #> MinErr -2.117309e+00 -2.405189e+00 -4.3581655 -2.7076806 #> MaxErr 1.706648e+00 2.053378e+00 10.0065030 3.5323611 #> MaxAbsErr 2.117309e+00 2.405189e+00 10.0065030 4.1730050 #> SD min max #> 0.7000498 -0.8258230 1.7834543 #> 0.4482005 0.5886351 2.4593054 #> 0.6365696 0.7358860 3.6568184 #> 0.1343872 0.2765989 0.8566607 #> 0.5712633 0.7718072 3.3785747 #> 0.1125430 0.4421786 0.9903590 #> 1.0021786 -4.3581655 -0.7893271 #> 2.3255646 0.4105829 10.0065030 #> 1.9372322 1.2929473 10.0065030
plot(m1, "residuals")