Fit a bag of conditional logistic regression/SSF/iSSF models with penalized regression in a train-validate-test setup
Source:R/fit_net_clogit.R, R/fit_net_logit.R
bag_fit_net_functions.RdFits a bag on conditional logistic regressions by calling fit_net_clogit()
multiple times to fit different resamples of the input data.
Fits a bag of logistic regressions by calling fit_net_logit()
multiple times to fit different resamples of the input data.
Usage
bag_fit_net_clogit(
f,
data,
samples,
subset_samples = 1:length(samples$train),
kernel_vars = c("step_length", "ta"),
metric = c("coxnet.deviance", "Cindex", "conditionalAUC", "conditionalSomersD")[1],
metrics_evaluate = c("coxnet.deviance", "Cindex", "conditionalAUC"),
method = c("Lasso", "Ridge", "AdaptiveLasso", "DistanceDecayLasso", "DDLasso",
"OneZOI-AdaptiveLasso", "OZ-AdaptiveLasso", "Grouped-AdaptiveLasso",
"G-AdaptiveLasso", "ElasticNet")[1],
standardize = c("internal", "external", FALSE)[1],
alpha = NULL,
penalty.factor = NULL,
predictor_table = NULL,
na.action = "na.pass",
out_dir_file = NULL,
parallel = c(FALSE, "foreach", "mclapply")[1],
mc.cores = 2L,
verbose = FALSE,
...
)
bag_fit_net_logit(
f,
data,
samples,
subset_samples = 1:length(samples$train),
metric = c(AUC, conditionalBoyce, conditionalSomersD, conditionalAUC)[[1]],
metrics_evaluate = c("AUC"),
method = c("Lasso", "Ridge", "AdaptiveLasso", "DistanceDecayLasso", "DDLasso",
"TruncatedLasso", "OneZOI-AdaptiveLasso", "OZ-AdaptiveLasso",
"Grouped-AdaptiveLasso", "G-AdaptiveLasso", "ElasticNet")[1],
standardize = c("internal", "external", FALSE)[1],
alpha = NULL,
penalty.factor = NULL,
predictor_table = NULL,
na.action = "na.pass",
out_dir_file = NULL,
parallel = c(FALSE, "foreach", "mclapply")[1],
mc.cores = 2L,
verbose = FALSE,
...
)Arguments
- f
[formula]
Formula of the model to be fitted, with all possible candidate terms.- data
[data.frame,tibble]
Complete data set to be analyzed.- samples
[list]
List of samples with at least three elements: train, test, and validate. Typically computed bycreate_resamples().- subset_samples
[vector]
Vector of sample indices to run (e.g.c(1,2,4,5)or3:10). By default, all samples insamplesare run.- kernel_vars
[character]
Names of movement kernel variables in the model (e.g."step_length"and"turning_angle").- metric
[function,character]{AUC, conditionalBoyce, conditionalSomersD, conditionalAUC}
Function representing the metric to evaluate goodness-of-fit. One of AUC (Default), conditionalBoyce, conditionalSomersD, and conditionalAUC. A user-defined function might be provided, with a condition that it must be maximized to find the best fit model. It can also be a character, in case it should be one of the following:c("AUC", "conditionalAUC", "conditionalBoyce", "conditionalSomersD").- metrics_evaluate
[character]
Vector of metric names to compute for model evaluation. See description of the argumentmetric.- method
[character(1)="Lasso"]
Penalized regression method. Default ismethod = "Lasso", but it could bemethod = "Ridge","AdaptiveLasso","ElasticNet", or different versions of ecology-informed methods. Seefit_net_logit()for valid options.- standardize
[character(1)="internal"]{"internal","external",FALSE}
Predictor standardization mode."internal"uses glmnet's internal standardization;"external"standardizes before calling glmnet;FALSEskips standardization, in case which the standardization should have been done before calling the function to fit the models.- alpha
[numeric(1)=NULL]
Elastic net mixing parameter. IfNULL, set automatically by method.- penalty.factor
[numeric]
Penalty factors per coefficient. IfNULL, set automatically by method.- predictor_table
[data.frame,NULL]
Predictor table with ZOI metadata, required for distance-decay and ecology-constrained methods. Typically created through[oneimpact::add_zoi_formula()].- na.action
[character(1)="na.pass"]
Action to take for missing values during fitting.- out_dir_file
[character(1)=NULL]
Prefix path for saving individual model results as RDS files.- parallel
[character(1)=FALSE]{"FALSE","foreach","mclapply"}
Parallelization backend. If FALSE (default), no parallelization is made.- mc.cores
[integer(1)=2]
Number of cores formclapply. Ifparallel == "foreach", cores must be registered beforehand usingparallel::makeCluster()anddoParallel::registerDoParallel().- verbose
[logical(1)=FALSE]
Whether to print progress messages during fitting.- ...
[any]
Additional options passed tofit_net_logit(),net_logit()andglmnet::glmnet().
Value
A list with:
n: total number of models (resamples).formula: model formula.method: fitting method used.metric: metric used for lambda selection.samples: resampling structure.standardize: standardization mode used.models: named list of fitted model objects, one per resample.covariate_mean_sd: data frame of predictor means and SDs used for external standardization (orNULL).numeric_covs: logical vector identifying which covariates are numeric.
A list with:
n: total number of models (resamples).formula: model formula.method: fitting method used.metric: metric used for lambda selection.samples: resampling structure.standardize: standardization mode used.models: named list of fitted model objects, one per resample.covariate_mean_sd: data frame of predictor means and SDs used for external standardization (orNULL).numeric_covs: logical vector identifying which covariates are numeric.