Learn R Programming

fastQR (version 1.0.0)

qrdowndate: Fast downdating of the QR factorization

Description

qrdowndate provides the update of the QR factorization after the deletion of \(m>1\) rows or columns to the matrix \(X\in\mathbb{R}^{n\times p}\) with \(n>p\). The QR factorization of the matrix \(X\in\mathbb{R}^{n\times p}\) returns the matrices \(Q\in\mathbb{R}^{n\times n}\) and \(R\in\mathbb{R}^{n\times p}\) such that \(X=QR\). The \(Q\) and \(R\) matrices are factorized as \(Q=\begin{bmatrix}Q_1&Q_2\end{bmatrix}\) and \(R=\begin{bmatrix}R_1\\R_2\end{bmatrix}\), with \(Q_1\in\mathbb{R}^{n\times p}\), \(Q_2\in\mathbb{R}^{n\times (n-p)}\) such that \(Q_1^{\top}Q_2=Q_2^\top Q_1=0\) and \(R_1\in\mathbb{R}^{p\times p}\) upper triangular matrix and \(R_2\in\mathbb{R}^{(n-p)\times p}\). qrupdate accepts in input the matrices \(Q\) and either the complete matrix \(R\) or the reduced one, \(R_1\). See Golub and Van Loan (2013) for further details on the method.

Usage

qrdowndate(Q, R, k, m = NULL, type = NULL, fast = NULL, complete = NULL)

Value

A named list containing

Q

the updated Q matrix.

R

the updated R matrix.

Arguments

Q

a \(n\times n\) matrix.

R

a \(n\times p\) upper triangular matrix.

k

position where the columns or the rows are removed.

m

number of columns or rows to be removed. Default is \(m=1\).

type

either 'row' of 'column', for deleting rows or columns. Default is 'column'.

fast

fast mode: disable to check whether the provided matrices are valid inputs. Default is FALSE.

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
## Remove one column
## generate sample data
set.seed(10)
n      <- 10
p      <- 6
X      <- matrix(rnorm(n * p, 1), n, p)

## get the initial QR factorization
output <- fastQR::qr(X, type = "householder",
                     nb = NULL,
                     complete = TRUE)
Q      <- output$Q
R      <- output$R

## select the column to be deleted
## from X and update X
k  <- 2
X1 <- X[, -k]

## downdate the QR decomposition
out <- fastQR::qrdowndate(Q = Q, R = R,
                          k = k, m = 1,
                          type = "column",
                          fast = FALSE,
                          complete = TRUE)

## check
round(out$Q %*% out$R - X1, 5)
max(abs(out$Q %*% out$R - X1))

## Remove m columns
## generate sample data
set.seed(10)
n      <- 10
p      <- 6
X      <- matrix(rnorm(n * p, 1), n, p)

## get the initial QR factorization
output <- fastQR::qr(X, type = "householder",
                     nb = NULL,
                     complete = TRUE)
Q      <- output$Q
R      <- output$R

## select the column to be deleted from X
## and update X
m  <- 2
k  <- 2
X1 <- X[, -c(k,k+m-1)]

## downdate the QR decomposition
out <- fastQR::qrdowndate(Q = Q, R = R,
                          k = k, m = 2,
                          type = "column",
                          fast = TRUE,
                          complete = FALSE)

## check
round(out$Q %*% out$R - X1, 5)
max(abs(out$Q %*% out$R - X1))

## Remove one row
## generate sample data
set.seed(10)
n      <- 10
p      <- 6
X      <- matrix(rnorm(n * p, 1), n, p)

## get the initial QR factorization
output <- fastQR::qr(X, type = "householder",
                     nb = NULL,
                     complete = TRUE)
Q      <- output$Q
R      <- output$R

## select the row to be deleted from X and update X
k  <- 5
X1 <- X[-k,]

## downdate the QR decomposition
out <- fastQR::qrdowndate(Q = Q, R = R,
                          k = k, m = 1,
                          type = "row",
                          fast = FALSE,
                          complete = TRUE)

## check
round(out$Q %*% out$R - X1, 5)
max(abs(out$Q %*% out$R - X1))

## Remove m rows
## generate sample data
set.seed(10)
n      <- 10
p      <- 6
X      <- matrix(rnorm(n * p, 1), n, p)

## get the initial QR factorization
output <- fastQR::qr(X, type = "householder",
                     nb = NULL,
                     complete = TRUE)
Q      <- output$Q
R      <- output$R

## select the rows to be deleted from X and update X
k  <- 5
m  <- 2
X1 <- X[-c(k,k+1),]

## downdate the QR decomposition
out <- fastQR::qrdowndate(Q = Q, R = R,
                          k = k, m = m,
                          type = "row",
                          fast = FALSE,
                          complete = TRUE)

## check
round(out$Q %*% out$R - X1, 5)
max(abs(out$Q %*% out$R - X1))

Run the code above in your browser using DataLab