sjSDM_cv {sjSDM}R Documentation

Cross validation of elastic net tuning

Description

Cross validation of elastic net tuning

Usage

sjSDM_cv(
  Y,
  env = NULL,
  biotic = bioticStruct(),
  spatial = NULL,
  tune = c("random", "grid"),
  CV = 5L,
  tune_steps = 20L,
  alpha_cov = seq(0, 1, 0.1),
  alpha_coef = seq(0, 1, 0.1),
  alpha_spatial = seq(0, 1, 0.1),
  lambda_cov = 2^seq(-10, -1, length.out = 20),
  lambda_coef = 2^seq(-10, -0.5, length.out = 20),
  lambda_spatial = 2^seq(-10, -0.5, length.out = 20),
  device = "cpu",
  n_cores = NULL,
  n_gpu = NULL,
  sampling = 5000L,
  blocks = 1L,
  ...
)

Arguments

Y

species occurrence matrix

env

matrix of environmental predictors or object of type linear, or DNN

biotic

defines biotic (species-species associations) structure, object of type bioticStruct. Alpha and lambda have no influence

spatial

defines spatial structure, object of type linear, or DNN

tune

tuning strategy, random or grid search

CV

n-fold cross validation or list of test indices

tune_steps

number of tuning steps

alpha_cov

weighting of l1 and l2 on covariances: (1 - \alpha) * |cov| + \alpha ||cov||^2

alpha_coef

weighting of l1 and l2 on coefficients: (1 - \alpha) * |coef| + \alpha ||coef||^2

alpha_spatial

weighting of l1 and l2 on spatial coefficients: (1 - \alpha) * |coef_sp| + \alpha ||coef_sp||^2

lambda_cov

overall regularization strength on covariances

lambda_coef

overall regularization strength on coefficients

lambda_spatial

overall regularization strength on spatial coefficients

device

device, default cpu

n_cores

number of cores for parallelization

n_gpu

number of GPUs

sampling

number of sampling steps for Monte Carlo integration

blocks

blocks of parallel tuning steps

...

arguments passed to sjSDM, see sjSDM

Value

An S3 class of type 'sjSDM_cv' including the following components:

tune_results

Data frame with tuning results.

short_summary

Data frame with averaged tuning results.

summary

Data frame with summarized averaged results.

settings

List of tuning settings, see the arguments in DNN.

data

List of Y, env (and spatial) objects.

config

List of sjSDM settings, see arguments of sjSDM.

spatial

Logical, spatial model or not.

Implemented S3 methods include sjSDM.tune, plot.sjSDM_cv, print.sjSDM_cv, and summary.sjSDM_cv

See Also

plot.sjSDM_cv, print.sjSDM_cv, summary.sjSDM_cv, sjSDM.tune

Examples

## Not run: 
# simulate sparse community:
com = simulate_SDM(env = 5L, species = 25L, sites = 50L, sparse = 0.5)

# tune regularization:
tune_results = sjSDM_cv(Y = com$response,
                        env = com$env_weights, 
                        tune = "random", # random steps in tune-paramter space
                        CV = 2L, # 3-fold cross validation
                        tune_steps = 2L,
                        alpha_cov = seq(0, 1, 0.1),
                        alpha_coef = seq(0, 1, 0.1),
                        lambda_cov = seq(0, 0.1, 0.001), 
                        lambda_coef = seq(0, 0.1, 0.001),
                        n_cores = 2L,
                        sampling = 100L,
                        # small models can be also run in parallel on the GPU
                        iter = 2L # we can pass arguments to sjSDM via... 
                        )

# print overall results:
tune_results

# summary (mean values over CV for each tuning step)
summary(tune_results)

# visualize tuning and best points:
# best = plot(tune_results, perf = "logLik")

# fit model with best regularization paramter:
model = sjSDM.tune(tune_results)

summary(model)

## End(Not run)

[Package sjSDM version 1.0.5 Index]