Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dropCoef

Ensure Full Rank Design Matrix


Description

Coefficients (columns) are dropped from a design matrix to ensure that it has full rank.

Usage

drop.coef(X, silent = FALSE)

Arguments

X

a design matrix, e.g., the result of model.matrix possibly of less than full column rank, i.e., with redundant parameters. Works for ncol(X) >= 0 and nrow(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.

Value

The design matrix X without redundant columns.

Author(s)

Rune Haubo B Christensen

See Also

qr and lm

Examples

X <- model.matrix( ~ PRODID * DAY, data = soup)
ncol(X)
newX <- drop.coef(X)
ncol(newX)

## 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
## the number of columns being dropped:
ncol(X) - ncol(newX)

ordinal

Regression Models for Ordinal Data

v2019.12-10
GPL (>= 2)
Authors
Rune Haubo Bojesen Christensen [aut, cre]
Initial release
2019-12-10

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.