kFoldCrossValidation | R Documentation |
This function performs k-fold cross-validation on a given corHMM
model by dividing the data into k equally sized subsets. The function evaluates model performance across multiple lambda regularization values, if provided. Optionally, it can save the trained models for each fold and return the cross-validation results.
kFoldCrossValidation(corhmm_obj, k, lambdas = NULL, return_model = TRUE,
save_model_dir = NULL, model_name = NULL)
corhmm_obj |
A |
k |
An integer specifying the number of folds to divide the data into for cross-validation. |
lambdas |
A numeric vector of lambda regularization values to evaluate during cross-validation. If |
return_model |
A logical value indicating whether to return the trained models for each fold. Defaults to |
save_model_dir |
A character string specifying the directory to save the trained models for each fold. If |
model_name |
A character string specifying the base name for saved model files. If |
The function splits the data into k
folds and trains a separate corHMM
model for each fold by leaving one fold out as the test set. The remaining folds are used for training the model. The performance of the model is evaluated on the test set using a divergence-based (Jensen-Shannon Divergence) scoring method. Evaluations are based on estimating the tips which were removed for that particular fold given the newly fitted model.
The function supports evaluating models across different lambda regularization values. If lambdas
are provided, models are trained and evaluated for each lambda value. The results, including the models (if return_model = TRUE
) and cross-validation scores, are returned as a list.
A list of cross-validation results, including the following components:
models |
A list of the trained models for each fold (if |
scores |
A numeric vector of the cross-validation scores for each fold. |
averageScore |
The average cross-validation score across all folds. |
James D. Boyko
#data(primates)
#phy <- multi2di(primates[[1]])
#data <- primates[[2]]
#dredge_fits <- corHMMDredge(phy = phy, data = data,
# max.rate.cat = 1, pen.type = "l1",
# root.p = "maddfitz", lambda = 1, nstarts = 10, n.cores = 10)
#model_table <- getModelTable(dredge_fits)
#dredge_model <- dredge_fits[[which.min(model_table$dAIC)]]
#k_fold_res <- kFoldCrossValidation(dredge_model,
# k = 5, lambdas = c(0,0.25,0.5,0.75,1))
#cv_table <- getCVTable(k_fold_res)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.