This implements Leave-one-out cross-validation (LOO-CV) for trees of class aphylo and multiAphylo.
aphylo_cv(...)
# S3 method for formula
aphylo_cv(model, ...)
Further arguments passed to the method.
As passed to aphylo_mcmc.
An object of class aphylo_cv
with the following components:
pred_out
Out of sample prediction.
expected
Expected annotations
call
The call
ids
Integer vector with the ids of the leafs used in the loo process.
For each observation in the dataset (either a single gene if of
class aphylo, or an entire tree if of class multiAphylo), we restimate
the model removing the observation and use the parameter estimates to make
a prediction on it. The prediction is done using the function predict.aphylo_estimates
with argument loo = TRUE
.
# It takes about two minutes to run this example
# \donttest{
set.seed(123)
atrees <- rmultiAphylo(10, 10, P = 1)
cv_multi <- aphylo_cv(atrees ~ mu_d + mu_s + Pi)
#> Warning: While using multiple chains, a single initial point has been passed via `initial`: c(0.9, 0.5, 0.1, 0.05, 0.5). The values will be recycled. Ideally you would want to start each chain from different locations.
#> Convergence has been reached with 10000 steps. Gelman-Rubin's R: 1.0182. (500 final count of samples).
#> --------------------------------------------------------------------------------
#> Leave-one-out cross validation of aphylo model with 10 cases
#> 1 done...
#> 2 done...
#> 3 done...
#> 4 done...
#> 5 done...
#> 6 done...
#> 7 done...
#> 8 done...
#> 9 done...
#> 10 done...
cv_single <- aphylo_cv(atrees[[1]] ~ mu_d + mu_s + Pi)
#> Warning: While using multiple chains, a single initial point has been passed via `initial`: c(0.9, 0.5, 0.1, 0.05, 0.5). The values will be recycled. Ideally you would want to start each chain from different locations.
#> Convergence has been reached with 10000 steps. Gelman-Rubin's R: 1.0461. (500 final count of samples).
#> --------------------------------------------------------------------------------
#> Leave-one-out cross validation of aphylo model with 10 cases
#> 1 done...
#> 2 done...
#> 3 done...
#> 4 done...
#> 5 done...
#> 6 done...
#> 7 done...
#> 8 done...
#> 9 done...
#> 10 done...
# }