| ridge | R Documentation |
Adjust a linear model with ridge regularization (possibly
structured \ell_2-norm). The solution path is computed
at a grid of values for the \ell_2-penalty. See details
for the criterion optimized.
ridge(
x,
y,
lambda = NULL,
weights = rep(1, nrow(x)),
struct = Matrix::Diagonal(ncol(x), 1),
penscale = rep(1, ncol(x)),
intercept = TRUE,
normalize = TRUE,
nlambda = 100,
minratio = 1e-05,
lambda_max = 100,
control = list()
)
x |
matrix of features, possibly sparsely encoded
(experimental). Do NOT include intercept. When normalized is
|
y |
response vector. |
lambda |
sequence of decreasing |
weights |
vector with real positive values that weight the observations (like in weighted least square). Default sets all weights to 1. |
struct |
matrix structuring the coefficients, possibly
sparsely encoded. Must be at least positive semidefinite (this is
checked internally). If |
penscale |
vector with real positive values that weight the penalty of each feature. Default sets all weights to 1. |
intercept |
logical; indicates if an intercept should be
included in the model. Default is |
normalize |
logical; indicates if variables should be
normalized to have unit L2 norm before fitting. Default is
|
nlambda |
integer that indicates the number of values to put
in the |
minratio |
minimal value of |
lambda_max |
the largest value of |
control |
list of argument controlling low level options of the algorithm –use with care and at your own risk– :
|
The optimized criterion is the following:
βhat
λ2 = argminβ 1/2
RSS(β) + λ/2 2 βT S
β, where the
\ell_2 structuring positive semidefinite matrix
S is provided via the struct argument (possibly of
class Matrix).
an object with class RidgeRegressionFit, inheriting from QuadrupenFit.
See also QuadrupenFit
## Simulating multivariate Gaussian with blockwise correlation
## and piecewise constant vector of parameters
beta <- rep(c(0,1,0,-1,0), c(25,10,25,10,25))
cor <- 0.75
Soo <- toeplitz(cor^(0:(25-1))) ## Toeplitz correlation for irrelevant variables
Sww <- matrix(cor,10,10) ## bloc correlation between active variables
Sigma <- Matrix::bdiag(Soo,Sww,Soo,Sww,Soo)
diag(Sigma) <- 1
n <- 50
x <- as.matrix(matrix(rnorm(95*n),n,95) %*% chol(Sigma))
y <- 10 + x %*% beta + rnorm(n,0,10)
labels <- rep("irrelevant", length(beta))
labels[beta != 0] <- "relevant"
plot(ridge(x,y) , label=labels) ## a mess
plot(ridge(x,y, struct=solve(Sigma)), label=labels) ## even better
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.