Learn R Programming

fastQR (version 1.1.4)

qrmridge: RIDGE estimator for the linear multivariate regression model

Description

qrmridge, or LS for linear multivariate regression models, solves the following optimization problem $$\textrm{min}_\beta ~ \frac{1}{2}\|Y-XB\|_2^2,$$ for \(Y\in\mathbb{R}^{n \times q}\) and \(X\in\mathbb{R}^{n\times p}\), to obtain a coefficient matrix \(\widehat{B}\in\mathbb{R}^{p\times q}\). The design matrix \(X\in\mathbb{R}^{n\times p}\) contains the observations for each regressor.

Value

A named list containing

coeff

a matrix of dimension \(p\times q\) containing the solution for the parameters \(B\).

fitted

a matrix of dimension \(n\times q\) of fitted values, \(\widehat{Y}=X\widehat{B}\).

residuals

a matrix of dimension \(n\times q\) of residuals, \(\varepsilon=Y-\widehat{Y}\).

XTX

the matrix \(X^\top X\).

Sigma_hat

a matrix of dimension \(q\times q\) containing the estimated residual variance-covariance matrix.

df

degrees of freedom.

R

\(R\) matrix of the QR decomposition of the matrix \(X^\top X\).

XTy

\(X^\top y\).

R2

\(R^2\), coefficient of determination, measure of goodness-of-fit of the model.

predicted

predicted values for the test set, \(X_{\text{test}}\widehat{B}\). It is only available if X_test is not NULL.

PMSE

Arguments

Y

a matrix of dimension \((n\times q\) response variables.

X

an \((n\times p)\) full column rank 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
q         <- 3
X         <- matrix(rnorm(n * p, 1), n, p)
X[,1]     <- 1
eps       <- matrix(rnorm(n*q), n, q)
B         <- matrix(0, p, q)
B[,1]     <- rep(1, p)
B[,2]     <- rep(2, p)
B[,3]     <- rep(-1, p)
Y         <- X %*% B + eps
X_test    <- matrix(rnorm(5 * p, 1), 5, p)
output    <- fastQR::qrmridge(Y = Y, X = X, lambda = 1, X_test = X_test, type = "QR")
output$coeff

Run the code above in your browser using DataLab