Learn R Programming

fastQR (version 1.0.0)

qrridge: RIDGE estimation for the linear regression model

Description

lmridge, or RIDGE for linear regression models, solves the following penalized optimization problem $$\textrm{min}_\beta ~ \frac{1}{n}\|y-X\beta\|_2^2+\lambda\Vert\beta\Vert_2^2,$$ to obtain a coefficient vector \(\widehat{\beta}\in\mathbb{R}^{p}\). The design matrix \(X\in\mathbb{R}^{n\times p}\) contains the observations for each regressor.

Usage

qrridge(y, X, lambda, X_test = NULL, type = NULL)

Value

A named list containing

mean_y

mean of the response variable.

mean_X

a length-\(p\) vector containing the mean of each column of the design matrix.

path

the whole path of estimated regression coefficients.

ess

explained sum of squares for the whole path of estimated coefficients.

GCV

generalized cross-validation for the whole path of lambdas.

GCV_min

minimum value of GCV.

GCV_idx

inded corresponding to the minimum values of GCV.

coeff

a length-\(p\) vector containing the solution for the parameters \(\beta\) which corresponds to the minimum of GCV.

lambda

the vector of lambdas.

scales

the vector of standard deviations of each column of the design matrix.

Arguments

y

a vector of length-\(n\) response vector.

X

an \((n\times p)\) matrix of predictors.

lambda

a vector of lambdas.

X_test

an \((q\times p)\) full column rank matrix. Test set. By default it set to NULL.

type

either "QR" or "R". Specifies the type of decomposition to use: "QR" for the QR decomposition or "R" for the Cholesky factorization of \(A^\top A\). The default is "QR".

Examples

Run this code

## generate sample data
set.seed(10)
n         <- 30
p         <- 6
X         <- matrix(rnorm(n * p, 1), n, p)
X[,1]     <- 1
eps       <- rnorm(n, sd = 0.5)
beta      <- rep(0, p)
beta[1:3] <- 1
beta[4:5] <- 2
y         <- X %*% beta + eps
X_test    <- matrix(rnorm(5 * p, 1), 5, p)
output    <-  fastQR::qrridge(y = y, X = X,
                              lambda = 0.2,
                              X_test = X_test)
output$coeff

Run the code above in your browser using DataLab