Learn R Programming

BayesERtools (version 0.2.0)

run_kfold_cv: Run k-fold cross-validation

Description

This function performs k-fold cross-validation using the appropriate model development function based on the class of the ermod object.

Usage

run_kfold_cv(ermod, newdata = NULL, k = 5, seed = NULL)

Value

A kfold_cv_ermod class object containing the fitted models and holdout predictions for each fold.

Arguments

ermod

An ermod object containing the model and data.

newdata

Optional new dataset to use instead of the original data. Default is NULL.

k

The number of folds for cross-validation. Default is 5.

seed

Random seed for reproducibility. Default is NULL.

Examples

Run this code
# \donttest{
data(d_sim_binom_cov_hgly2)

ermod_bin <- dev_ermod_bin(
  data = d_sim_binom_cov_hgly2,
  var_resp = "AEFLAG",
  var_exposure = "AUCss_1000",
  var_cov = "BHBA1C_5",
  # Settings to make the example run faster
  chains = 2,
  iter = 1000
)

cv_results <- run_kfold_cv(ermod_bin, k = 3, seed = 123)

print(cv_results)
# }

Run the code above in your browser using DataLab