Learn R Programming

fastQR (version 1.1.4)

qr_Qty: Multiply Q by a vector using a QR decomposition

Description

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

Usage

qr_Qty(qr, tau, y)

Value

a numeric vector equal to \(Q^\top 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^\top 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_Qty(qr = qr_res$qr, tau = qr_res$qraux, y = y)

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

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

Run the code above in your browser using DataLab