cross_validated_group_fits: Perform Cross-Validation on Group Fits of a Model

View source: R/crossval.R

cross_validated_group_fitsR Documentation

Perform Cross-Validation on Group Fits of a Model

Description

This function runs k-fold cross-validation for group fits of a specified model using a set of conditions. On each fold, the model is fit (via xsl_fit()) to the training conditions, and the fitted model is then evaluated (via xsl_run()) on the held-out test conditions to obtain an out-of-sample SSE.

Usage

cross_validated_group_fits(
  model,
  combined_data,
  lower,
  upper,
  n_folds = 5,
  control = xslControl(),
  deoptim_control = DEoptim::DEoptim.control(reltol = 0.001, NP = 100, itermax = 100),
  seed = NULL
)

Arguments

model

An object of class xslMod giving the model to cross-validate (its starting parameter values are only used to determine how many parameters xsl_fit() should optimize).

combined_data

A list of xslData conditions used for cross-validation.

lower

Numeric vector of lower bounds for the model's parameters.

upper

Numeric vector of upper bounds for the model's parameters.

n_folds

Number of folds (default: 5).

control

Control arguments passed to xsl_fit()/xsl_run().

deoptim_control

Control parameters passed to DEoptim() (via xsl_fit()).

seed

Optional random seed, for reproducible fold assignment.

Value

A list containing cross-validation results:

  • folds: a list (one per fold) with the fitted params, train_sse (in-sample), and test_sse (out-of-sample).

  • params: a matrix of fitted parameters, one row per fold.

  • train_sse / test_sse: numeric vectors of per-fold SSE.

Examples

# A reduced DEoptim search keeps this example fast; drop
# deoptim_control for a real, thorough fit.
cross_validated_group_fits(decay(C = 0.98), xsl_datasets[1:6],
                           lower = 0.8, upper = 1.0, n_folds = 2,
                           deoptim_control = DEoptim::DEoptim.control(NP = 10, itermax = 5))

XSLmodels documentation built on Oct. 18, 2026, 5:08 p.m.