fracridge | R Documentation |
Performs fractional ridge regression, approximating regularization parameters to match desired fractions of the Ordinary Least Squares (OLS) parameter vector length.
fracridge(X, y, fracs = seq(0.1, 1, by = 0.1), tol = 1e-10)
X |
A numeric matrix of shape |
y |
A numeric vector or matrix of shape |
fracs |
A numeric vector specifying the desired fractions of the OLS parameter vector length.
Must be sorted in increasing order and be between 0 and 1. Default is |
tol |
A numeric value specifying the tolerance below which singular values are considered zero.
Must be positive. Default is |
Fractional ridge regression finds ridge regression solutions where the parameter vector lengths
equal specified fractions of the OLS solution length. This is achieved by adjusting the
regularization parameter alpha
for each target fraction.
The function uses Singular Value Decomposition (SVD) for efficient computation. Singular values
below tol
are treated as zero, and a warning is issued if rank deficiency is detected.
The regularization path is computed using a grid of alpha values on a log scale, with interpolation used to find the exact alpha values that achieve the target fractions.
An object of class fracridge
containing:
coef
A numeric array of shape (p, length(fracs), b)
containing the estimated coefficients
for each fraction and target. If y
is a vector, the third dimension is dropped.
alpha
A numeric matrix of shape (length(fracs), b)
containing the regularization parameters
associated with each solution.
fracs
The fractions used in the regression.
rank
The effective rank of the design matrix X
.
singular_values
The singular values of X
.
## Not run:
# Generate random data
set.seed(0)
X <- matrix(rnorm(100 * 10), nrow = 100, ncol = 10)
y <- rnorm(100)
# Perform fractional ridge regression
result <- fracridge(X, y, fracs = seq(0.3, 0.9, by = 0.1))
# Inspect the coefficients and regularization parameters
print(result$coef)
print(result$alpha)
# Compare with OLS solution length
ols_coef <- solve(crossprod(X), crossprod(X, y))
ols_norm <- sqrt(sum(ols_coef^2))
coef_norm <- sqrt(colSums(result$coef^2))
print(coef_norm / ols_norm) # Should approximately equal fracs
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.