Learn R Programming

fastQR (version 1.1.4)

qr_lse_Qty: Compute Q'y for a least-squares problem

Description

Computes the product \(Q^\top y\), where \(Q\) is the orthogonal matrix from the QR decomposition of the design matrix \(X\).

Usage

qr_lse_Qty(X, y)

Value

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

Arguments

X

numeric matrix of dimension \(n \times p\).

y

numeric response vector of length \(n\).

Details

The QR decomposition of \(X\) is computed internally, and the orthogonal matrix \(Q\) is never formed explicitly. The product \(Q^\top y\) is evaluated efficiently using Householder reflectors.

This function is intended as a convenience wrapper for least-squares computations when the explicit QR factors are not required.

Examples

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

res1 <- fastQR::qr_lse_Qty(X, y)

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

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

Run the code above in your browser using DataLab