Learn R Programming

fastQR (version 1.1.4)

qr_Q_full: Reconstruct the full Q matrix from the qr object.

Description

returns the full \(Q\in\mathbb{R}^{n\times n}\) matrix.

Usage

qr_Q_full(qr, tau)

Value

returns the matrix \(Q\in\mathbb{R}^{n\times n}\).

Arguments

qr

object representing a QR decomposition. This will typically have come from a previous call to qr.

tau

a vector of length \(ncol(X)\) which contains additional information on \(Q\). It corresponds to qraux from a previous call to qr.

References

golub_van_loan.2013fastQR

bjorck.2015fastQR

bjorck.2024fastQR

bernardi_etal.2024fastQR

Examples

Run this code
## create data: n > p
set.seed(1234)
n <- 12
p <- 7
X <- matrix(rnorm(n * p), n, p)

## get the full QR decomposition with pivot
qr_res <- fastQR::qr_fast(X = X,
                          tol = sqrt(.Machine$double.eps),
                          pivot = TRUE)

## complete the reduced Q matrix
Q <- fastQR::qr_Q_full(qr  = qr_res$qr,
                       tau = qr_res$qraux)

## check the Q matrix (orthogonality)
max(abs(crossprod(Q)-diag(1, n)))

Run the code above in your browser using DataLab