## 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
R1 <- R[1:p,]
## select the column to be deleted from X and update X
k <- 2
X1 <- X[, -k]
## downdate the R decomposition
R2 <- fastQR::rdowndate(R = R1, k = k,
m = 1, type = "column")
## check
max(abs(crossprod(R2) - crossprod(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
R1 <- R[1:p,]
## select the column to be deleted from X and update X
k <- 2
X1 <- X[, -c(k,k+1)]
## downdate the R decomposition
R2 <- fastQR::rdowndate(R = R1, k = k,
m = 2, type = "column")
## check
max(abs(crossprod(R2) - crossprod(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
R1 <- R[1:p,]
# select the row to be deleted from X and update X
k <- 5
X1 <- X[-k,]
U <- as.matrix(X[k,], p, 1)
## downdate the R decomposition
R2 <- rdowndate(R = R1, k = k, m = 1,
U = U, fast = FALSE, type = "row")
## check
max(abs(crossprod(R2) - crossprod(X1)))
## Remove m rows
## create data: n > p
set.seed(10)
n <- 10
p <- 6
X <- matrix(rnorm(n * p, 1), n, p)
output <- fastQR::qr(X, type = "householder",
nb = NULL,
complete = TRUE)
Q <- output$Q
R <- output$R
R1 <- R[1:p,]
## select the rows to be deleted from X and update X
k <- 2
m <- 2
X1 <- X[-c(k,k+m-1),]
U <- t(X[k:(k+m-1), ])
## downdate the R decomposition
R2 <- rdowndate(R = R1, k = k, m = m,
U = U, fast = FALSE, type = "row")
## check
max(abs(crossprod(R2) - crossprod(X1)))
Run the code above in your browser using DataLab