Ensure Full Rank Design Matrix
dropCoef.RdCoefficients (columns) are dropped from a design matrix to ensure that it has full rank.
Arguments
- X
a design matrix, e.g., the result of
model.matrixpossibly of less than full column rank, i.e., with redundant parameters. Works forncol(X) >= 0andnrow(X) >= 0.- silent
should a message not be issued if X is column rank deficient?
Details
Redundant columns of the design matrix are identified with the
LINPACK implementation of the qr decomposition and
removed. The returned design matrix will have qr(X)$rank
columns.
Examples
X <- model.matrix( ~ PRODID * DAY, data = soup)
ncol(X)
#> [1] 12
newX <- drop.coef(X)
#> design is column rank deficient so dropping 1 coef
ncol(newX)
#> [1] 11
## Essentially this is being computed:
qr.X <- qr(X, tol = 1e-7, LAPACK = FALSE)
newX <- X[, qr.X$pivot[1:qr.X$rank], drop = FALSE]
## is newX of full column rank?
ncol(newX) == qr(newX)$rank
#> [1] TRUE
## the number of columns being dropped:
ncol(X) - ncol(newX)
#> [1] 1