Learn R Programming

fastQR (version 1.1.4)

qr_Qy: Multiply Q by a vector using a QR decomposition

Description

Computes \(Q y\), where \(Q\) is the orthogonal matrix from the QR decomposition stored in compact (Householder) form.

Usage

qr_Qy(qr, tau, y)

Value

a numeric vector equal to \(Q y\).

Arguments

qr

numeric matrix containing the QR decomposition in compact form (as returned by qr_fast()).

tau

numeric vector of Householder coefficients.

y

numeric vector of length \(n\).

Details

The orthogonal matrix \(Q\) is not formed explicitly. The product \(Q y\) is computed efficiently using the Householder reflectors stored in qr and tau.

Examples

Run this code
set.seed(1)
n <- 10; p <- 4
X <- matrix(rnorm(n * p), n, p)
y <- rnorm(n)

qr_res <- fastQR::qr_fast(X)
res1   <- fastQR::qr_Qy(qr = qr_res$qr, tau = qr_res$qraux, y = y)

## reference computation
Q    <- base::qr.Q(base::qr(X), complete = TRUE)
res2 <- Q %*% y

max(abs(res1 - drop(res2)))

Run the code above in your browser using DataLab