findDepMat: Identify linearly dependent rows or columns in a matrix

Description Usage Arguments Details Value Author(s) Examples

View source: R/findDepMat.R

Description

Identify linearly dependent rows or columns in a matrix

Usage

1
findDepMat(X, rows = TRUE, tol = 1e-10)

Arguments

X

A numeric matrix

rows

Set rows = TRUE to identify which rows are linearly dependent. Set rows = FALSE to identify columns that are linearly dependent.

tol

The tolerance used to determine whether one row (or column) is a linear combination of another.

Details

A row (or column) is considered to be a linear combination of another if the maximum of the absolute succesive differences of the ratios of the two rows (columns) exceeds the tolerance, tol. This is a fairly crude criterion and may need improvement–but it at least will identify the almost-exact linear dependencies.

findDepMat identifies linearly dependent rows (columns) similar to the way duplicated identifies duplicates. As such, the first instance (row or column) of a set of linearly dependent rows (or columns) is not flagged as being dependent.

The sum of the negated output of findDepMat should be the number of linearly independent rows (columns). This quanity is compared to the rank produced by qr, and if not equal, a warning is issued. The value of tol is passed to qr, but the criteria of convergence for qr is assuredly different from that used here to identify the linearly dependent rows (columns).

Currently this uses nested 'for' loops within R (not C). Consequently, findDepMat is likely to be slow for large matrices.

Value

A logical vector, equal in length to the number of rows (columns) of X, with TRUE indicating that the row (column) is linearly dependent on a previous row (column).

Author(s)

Landon Sego

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# A matrix
Y <- matrix(c(1, 3, 4,
              2, 6, 8,
              7, 2, 9,
              4, 1, 7,
              3.5, 1, 4.5), byrow = TRUE, ncol = 3)

# Note how row 2 is multiple of row 1, row 5 is a multiple of row 3
print(Y)

findDepMat(Y)
findDepMat(t(Y), rows = FALSE)

Example output

     [,1] [,2] [,3]
[1,]  1.0    3  4.0
[2,]  2.0    6  8.0
[3,]  7.0    2  9.0
[4,]  4.0    1  7.0
[5,]  3.5    1  4.5
[1] FALSE  TRUE FALSE FALSE  TRUE
[1] FALSE  TRUE FALSE FALSE  TRUE

Smisc documentation built on May 2, 2019, 2:46 a.m.