Pseudo-removed leave-out cross-validation

cv.pr.w(
  modern_taxa,
  modern_climate,
  nPLS = 5,
  trainfun,
  predictfun,
  pseudo,
  usefx = FALSE,
  fx_method = "bin",
  bin = NA,
  cpus = 4,
  test_mode = TRUE,
  test_it = 5
)

Arguments

modern_taxa

The modern taxa abundance data, each row represents a sampling site, each column represents a taxon.

modern_climate

The modern climate value at each sampling site.

nPLS

The number of components to be extracted.

trainfun

Training function you want to use, either WAPLS.w or TWAPLS.w.

predictfun

Predict function you want to use: if trainfun is WAPLS.w, then this should be WAPLS.predict.w; if trainfun is TWAPLS.w, then this should be TWAPLS.predict.w.

pseudo

The geographically and climatically close sites to each test site, obtained from get_pseudo function.

usefx

Boolean flag on whether or not use fx correction.

fx_method

Binned or p-spline smoothed fx correction: if usefx = FALSE, this should be NA; otherwise, fx function will be used when choosing "bin"; fx_pspline function will be used when choosing "pspline".

bin

Binwidth to get fx, needed for both binned and p-splined method. if usefx = FALSE, this should be NA;

cpus

Number of CPUs for simultaneous iterations to execute, check parallel::detectCores() for available CPUs on your machine.

test_mode

Boolean flag to execute the function with a limited number of iterations, test_it, for testing purposes only.

test_it

Number of iterations to use in the test mode.

Value

Leave-one-out cross validation results.

Examples

if (FALSE) {
# Load modern pollen data
modern_pollen <- read.csv("/path/to/modern_pollen.csv")
                                      
# Extract taxa
taxaColMin <- which(colnames(modern_pollen) == "taxa0")
taxaColMax <- which(colnames(modern_pollen) == "taxaN")
taxa <- modern_pollen[, taxaColMin:taxaColMax]

point <- modern_pollen[, c("Long", "Lat")]
test_mode <- TRUE # It should be set to FALSE before running
dist <- fxTWAPLS::get_distance(point, 
                               cpus = 2, # Remove the following line
                               test_mode = test_mode)
pseudo_Tmin <- fxTWAPLS::get_pseudo(dist, 
                                    modern_pollen$Tmin, 
                                    cpus = 2, # Remove the following line
                                    test_mode = test_mode)

cv_pr_t_Tmin <- fxTWAPLS::cv.pr.w(taxa,
                                  modern_pollen$Tmin,
                                  nPLS = 5,
                                  fxTWAPLS::TWAPLS.w,
                                  fxTWAPLS::TWAPLS.predict.w,
                                  pseudo_Tmin,
                                  cpus = 2, # Remove the following line
                                  test_mode = test_mode)
cv_pr_tf_Tmin <- fxTWAPLS::cv.pr.w(taxa,
                                   modern_pollen$Tmin,
                                   nPLS = 5,
                                   fxTWAPLS::TWAPLS.w,
                                   fxTWAPLS::TWAPLS.predict.w,
                                   pseudo_Tmin,
                                   usefx = TRUE,
                                   fx_method = "bin",
                                   bin = 0.02,
                                   cpus = 2, # Remove the following line
                                   test_mode = test_mode)                                

# Run with progress bar
`%>%` <- magrittr::`%>%`
cv_pr_t_Tmin <- fxTWAPLS::cv.pr.w(taxa,
                                  modern_pollen$Tmin,
                                  nPLS = 5,
                                  fxTWAPLS::TWAPLS.w,
                                  fxTWAPLS::TWAPLS.predict.w,
                                  pseudo_Tmin,
                                  cpus = 2, # Remove the following line
                                  test_mode = test_mode) %>% fxTWAPLS::pb()
cv_pr_tf_Tmin <- fxTWAPLS::cv.pr.w(taxa,
                                   modern_pollen$Tmin,
                                   nPLS = 5,
                                   fxTWAPLS::TWAPLS.w,
                                   fxTWAPLS::TWAPLS.predict.w,
                                   pseudo_Tmin,
                                   usefx = TRUE,
                                   fx_method = "bin",
                                   bin = 0.02,
                                   cpus = 2, # Remove the following line
                                   test_mode = test_mode) %>% fxTWAPLS::pb()
                                 
}