Skip to contents

Turns a function that summarises a data set into one that summarises, for every fold, the sites kept (train) and the sites left out (test). Use it as summarise in abc_table(), so that one simulation gives the statistics of every fold, and apply it to the observed data before abc_cv(). The statistics are named f1_train_alpha, f1_test_alpha and so on.

Usage

fold_summarise(folds, summarise = function(x, shared) summary_stats(x))

Arguments

folds

Integer vector with the fold of each site, as from spatial_folds().

summarise

Function of an mc_data() object and shared that gives a named numeric vector. The default is summary_stats().

Value

A function of sim, a simulation or an mc_data() object, and shared.

Examples

tree <- treeshapesim::sim_tree_shape(8)
grid <- landscape_grid(side = 4)
sim <- simulate_metacommunity(grid, species_traits(tree, 0.5), competition_matrix(tree, "none"),
                              dispersal = 0.05, n_steps = 40)
by_fold <- fold_summarise(spatial_folds(grid$coords, k = 2),
                          function(x, shared) summary_stats(x, n_null = 9)[1:3])
by_fold(sim, list())
#> f1_train_alpha f1_train_gamma  f1_train_beta  f1_test_alpha  f1_test_gamma 
#>       4.500000       8.000000       1.777778       4.875000       8.000000 
#>   f1_test_beta f2_train_alpha f2_train_gamma  f2_train_beta  f2_test_alpha 
#>       1.641026       4.875000       8.000000       1.641026       4.500000 
#>  f2_test_gamma   f2_test_beta 
#>       8.000000       1.777778