fracridge_cv: Fractional Ridge Regression with Cross-Validation

View source: R/fracridge.R

fracridge_cvR Documentation

Fractional Ridge Regression with Cross-Validation

Description

Performs fractional ridge regression with cross-validation to select the optimal fraction.

Usage

fracridge_cv(
  X,
  y,
  frac_grid = seq(0.1, 1, by = 0.1),
  tol = 1e-10,
  cv = 5,
  scoring = "r2"
)

Arguments

X

A numeric matrix of shape (n, p) representing the design matrix, where n is the number of observations and p is the number of predictors.

y

A numeric vector or matrix of shape (n, b) representing the response variable(s), where b is the number of targets. If y is a vector, it is treated as a single target.

frac_grid

A numeric vector specifying the grid of fractions to consider for cross-validation. Must be sorted in increasing order and be between 0 and 1. Default is seq(0.1, 1.0, by = 0.1).

tol

A numeric value specifying the tolerance below which singular values are considered zero. Must be positive. Default is 1e-10.

cv

An integer specifying the number of cross-validation folds, or an object to be used as a cross-validation generator (e.g., cv = 5). Default is 5.

scoring

A character string or function to evaluate the predictions on the test set. Default is "r2".

Details

This function performs fractional ridge regression across a grid of fractions and selects the fraction that maximizes the cross-validated performance metric (e.g., R-squared).

Value

An object of class fracridge_cv containing:

best_frac

The fraction that achieved the best cross-validated score.

coef

A numeric array of shape (p, b) containing the estimated coefficients for the best fraction and each target.

alpha

A numeric vector containing the regularization parameters associated with the best fraction for each target.

cv_results

A data frame containing cross-validation scores for each fraction.

Examples

## Not run: 
# Generate random data
set.seed(1)
X <- matrix(rnorm(100 * 10), nrow = 100, ncol = 10)
y <- rnorm(100)

# Perform cross-validated fractional ridge regression
cv_result <- fracridge_cv(X, y, frac_grid = seq(0.1, 1.0, by = 0.1))

# Print the best fraction
print(cv_result$best_frac)

# Inspect coefficients
print(cv_result$coef)

## End(Not run)


bbuchsbaum/fmrireg documentation built on March 1, 2025, 11:20 a.m.