## 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