cv.LV: Cross-validate fit for Lotka-Volterra coefficients

View source: R/cross_validate.R

cv.LVR Documentation

Cross-validate fit for Lotka-Volterra coefficients

Description

The function preforms k-fold cross-validation on a grid of regularization parameters

Usage

cv.LV(
  time_series,
  n_folds = length(time_series),
  kind = "integral",
  weights = expand.grid(self = 0.1 * 0:100, interaction = 0.1 * 0:100),
  show_progress = TRUE,
  parallel = FALSE,
  ncpus = getOption("micInt.ncpus", 1L),
  cl = NULL
)

Arguments

time_series

A list of OTU_time_series to be cross-validated

n_folds

The number of folds to apply. If missing, leave-one-out cross-validation is preformed.

kind

Charachter, one of c('integral','log_integral') Choose whether use the integral or log-integral approach described in the article cited.

weights

A n times 2 data.frame containing the weights to be tried out. The two colmns are:

  • 'self' The regularization for the maximal growth rate

  • 'interaction' The regulartization for the interactions between OTUs

If missing, the cross validation is carried out over a quadratic grid from 0 to 10 in steps of 0.1

show_progress

Logical, if TRUE, the progress is printed for each combination of weights is is to cross-validate, ignored if parallel=TRUE

parallel

Should the analysis be run in parallel?

ncpus

If parallel = TRUE, how many cores should be used? Defaults to one.

cl

Custom cluster to use if parallel = TRUE.

Details

In this setting, each time series is a “data point” in the cross-validation procedure, meaning that each fit is preformed on some of the time series and the other are used for validation.

Value

An object of class cvLV, inheiriting data.frame containing the parameter values, and the two columns of cross-validation error:

  • 'RMSE' The root mean square error of the right sides

  • 'MAE' The mean absolute error of the right sides

References

P. H. Kloppers and J. C. Greeff. “Lotka-Volterra model parameter estimation using experiential data”. In: Appl. Math. Comput. 224 (Nov. 2013), pp. 817–825. ISSN: 0096-3003. DOI: https://doi.org/10.1016/j.amc.2013.08.093

Examples

library(micInt)
library(phyloseq)
library(magrittr)
data("seawater")
physeq_list <- subdivide_by_environment(seawater,"Reactor")
time_series <- lapply(physeq_list$phyloseq,OTU_time_series,
time_points ="Week")
systems <- integralSystem(time_series,kind = "integral")
cv_res <- cv.LV(time_series,n_folds = 3, kind = "integral",
weights = expand.grid(self= c(1,2),
interaction = c(1,2)
)
)
best_parameters <- cv_res[which.min(cv_res$RMSE),c("self","interaction")] %>% unlist()
fit <- ridge_fit(systems,best_parameters)
predict(fit,start = rep(1,nrow(fit)),times = c(0,1,4,6,10,20))



AlmaasLab/micInt documentation built on April 1, 2022, 10:37 a.m.