Learn R Programming

fastQR (version 1.1.4)

qr: The QR factorization of a matrix

Description

qr provides the QR factorization of the matrix \(X\in\mathbb{R}^{n\times p}\) with \(n>p\). The QR factorization of the matrix \(X\) returns the matrices \(Q\in\mathbb{R}^{n\times n}\) and \(R\in\mathbb{R}^{n\times p}\) such that \(X=QR\). See Golub and Van Loan (2013) for further details on the method.

Value

A named list containing

Q

the Q matrix.

R

the R matrix.

Arguments

X

a \(n\times p\) matrix.

type

either "givens" or "householder".

nb

integer. Defines the number of block in the block recursive QR decomposition. See Golud and van Loan (2013).

complete

logical expression of length 1. Indicates whether an arbitrary orthogonal completion of the \(Q\) matrix is to be made, or whether the \(R\) matrix is to be completed by binding zero-value rows beneath the square upper triangle.

References

golub_van_loan.2013fastQR

bjorck.2015fastQR

bjorck.2024fastQR

bernardi_etal.2024fastQR

Examples

Run this code
## generate sample data
set.seed(1234)
n <- 10
p <- 6
X <- matrix(rnorm(n * p, 1), n, p)

## QR factorization via Givens rotation
output <- qr(X, type = "givens", complete = TRUE)
Q      <- output$Q
R      <- output$R

## check
round(Q %*% R - X, 5)
max(abs(Q %*% R - X))

## QR factorization via Householder rotation
output <- qr(X, type = "householder", complete = TRUE)
Q      <- output$Q
R      <- output$R

## check
round(Q %*% R - X, 5)
max(abs(Q %*% R - X))

Run the code above in your browser using DataLab