Skip to contents

Computes the orthogonal complement of a subspace relative to a universe.

Usage

null_complement(m, universe = NULL, na.allow = TRUE)

Arguments

m

NA or a matrix whose columns define the subspace, a vector is treated as a matrix with one column.

universe

a matrix whose columns specify the subspace relative to which to compute the complement, the default is the full space.

na.allow

if TRUE, default, treat NA's specially, see Details.

Details

null_complement computes the orthogonal complement of a subspace (spanned by the columns of m) relative to a universe.

Argument universe can be used to specify a subspace w.r.t. which to compute the complement. If universe is NULL (the default), the complement w.r.t. the full space is computed. The full space is the \(n\)-dimensional space, where \(n\) is the number of rows of argument m.

null_complement returns a matrix whose columns give a basis of the required subspace.

null_complement uses Null() from package MASS for the actual computation. null_complement(m, na.allow = FALSE) is equivalent to Null(m).

m is typically a matrix whose columns represent the subspace w.r.t. which to compute the complement. null_complement can also deal with NA's in m. This facility can be turned off by specifying na.allow = FALSE.

If na.allow = TRUE, the default, and m is identical to NA, universe is returned (i.e. m = NA represents the empty subspace). Note that in this case universe cannot be NULL, since there is no way to determine the dimension of the full space.

Otherwise, m is a matrix. If all elements of m are NA, a matrix of NA's is returned with number of columns equal to ncol(universe) - ncol(m).

Value

a matrix representing a basis of the requested subspace

Author

Georgi N. Boshnakov

Examples

m1 <- diag(1, nrow = 3, ncol = 2)
null_complement(m1)
#>      [,1]
#> [1,]    0
#> [2,]    0
#> [3,]    1

null_complement(c(1,1,0))
#>            [,1] [,2]
#> [1,] -0.7071068    0
#> [2,]  0.7071068    0
#> [3,]  0.0000000    1
null_complement(c(1,1,0), m1)
#>            [,1]
#> [1,]  0.7071068
#> [2,] -0.7071068
#> [3,]  0.0000000

## the columns of the result from null_complement() are orthogonal
## to  the 1st argument:
t(c(1,1,0)) %*% null_complement(c(1,1,0))
#>              [,1] [,2]
#> [1,] 1.110223e-16    0
t(c(1,1,0)) %*% null_complement(c(1,1,0), m1)
#>               [,1]
#> [1,] -1.110223e-16

null_complement(rep(NA_real_, 3), m1)
#>      [,1]
#> [1,]   NA
#> [2,]   NA
#> [3,]   NA
null_complement(NA, m1)
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    1
#> [3,]    0    0