Performs stratified k-fold cross-validation by rotating which cells serve as the test set. Returns per-fold and aggregated metrics.
Arguments
- data
pigauto_data object (output of
preprocess_traits).- tree
phylo object.
- k
integer. Number of folds (default 5).
- seeds
optional integer vector. Seeds for replicate runs. The default
NULLperforms one run using the current RNG stream.- epochs
integer. Training epochs per fold (default 500).
- verbose
logical. Print progress (default TRUE).
- ...
Additional arguments passed to
fit_pigauto(e.g.hidden_dim,k_eigen,use_attention).
Value
A list of class "pigauto_cv" with:
- results
Data.frame with columns: fold, rep, trait, type, metric, value.
- summary
Data.frame with mean and sd across folds/reps for each trait + metric.
- conformal_coverage
Data.frame of coverage per trait across folds (if available).
- k
Number of folds.
- n_reps
Number of replicates.
Examples
# \donttest{
data(avonet300, tree300, package = "pigauto")
tree <- ape::keep.tip(tree300, tree300$tip.label[seq_len(30L)])
traits <- avonet300[match(tree$tip.label, avonet300$Species_Key),
c("Mass", "Wing.Length"), drop = FALSE]
rownames(traits) <- tree$tip.label
cv <- cross_validate(preprocess_traits(traits, tree), tree, k = 3L,
seeds = 1L, epochs = 5L, verbose = FALSE)
#> Error: Lantern is not loaded. Please use `install_torch()` to install additional dependencies.
print(cv)
#> Error: object 'cv' not found
summary(cv)
#> Error: object 'cv' not found
# }
