in.span: Is 'x' in the column span of matrix 'A' and what columns are...

in.spanR Documentation

Is x in the column span of matrix A and what columns are linearly dependent?

Description

The function in.span checks if the vector x (or columns of the matrix x) is in the column span of the matrix A. If desired, it returns the coefficient matrix B so that AB=x. The function thinCol removes linearly dependent columns an returns a matrix of full rank.

Usage

in.span( A,
         x,
      coef = FALSE,
       tol = 1e-08 )
inSpan( A, x, coef=FALSE, tol=1e-08 )
id.span( A, B, tol=1e-08 )
idSpan( A, B, tol=1e-08 )
thinCol( A, tol = 1e-06, col.num = FALSE )

Arguments

A

A matrix.

B

A matrix.

x

A vector or matrix. length(x) (or nrow(x)) must be equal to nrow(A).

coef

Logical. Should the coefficient matrix (k) be returned, so that Ak=x?

tol

Tolerance for identity of matrices in check (in.span) or QR decomposition (thinCol)

col.num

Logical. Should the positions of dependent columns be returned instead of the full-rank matrix?

Details

thinCol is mainly a workhorse in detrend, but made available because of its general usefulness.

in.span and inSpan are just different names for the same to accommodate different naming schools.

in.span (inSpan) is handy in checking whether different parametrizations of a model are identical in the sense of spanning the same linear space. Equivalent to checking whether fitted values under different parametrizations are identical, but has the further use of checking if subspaces of models are equivalent. The function simply checks if the regression of (columns of) x on the columns of A produces residuals that are all 0.

id.span (equivalent to idSpan) checks whether two matrices have the same column span.

Value

in.span returns a logical: is x is in span(A)? If coef=TRUE it returns a matrix k so that Ak=x. k is not necessarily unique (A may not have full rank).

id.span returns a logical: is span(A) the same as span(B)?

thinCol returns a matrix of full rank, formed from A by deleting columns linearly dependent on other. If col.num=TRUE (one possible set of) positions of columns forming a full rank basis for the column space of A is returned.

Author(s)

Bendix Carstensen, http://bendixcarstensen.com with essential help from Lars Jorge Diaz and Peter Dalgaard.

See Also

det

Examples

# Matrices and vectors, x in span(A), z (hopefully) not
A <- matrix(round(rnorm(15)*20),5,3)
B <- matrix(round(rnorm(15)*20),5,3)
B <- cbind( B, B%*%c(3,4,2) )
x <- A %*% c(3,4,2)
z <- 5:9

# how they look
data.frame( A=A, x=x, z=z, B=B )

# vectors in span(A)?
in.span(A,x)
in.span(x,A)
in.span(A,x,coef=TRUE)

in.span(A,z)
in.span(A,z,coef=TRUE)

# Do matrices span the same space ?
in.span( A, B )
in.span( B, A )

# B is not in span of a subspace of B columns, but vice versa
( M <- matrix( rnorm(8)*7, 4, 2 ) )
in.span( B%*%M, B )
in.span( B, B%*%M )
id.span( B, B%*%M )

# But not unique for singular matrices:
( xx <- in.span( B, B%*%M, coef=TRUE ) )
cbind( B%*%M, B%*%xx )
cbind( xx, M )

# Easier for full rank matrices:
( K <- matrix( rnorm(9)*7, 3, 3 ) )
in.span( A%*%K, A )
in.span( A, A%*%K )
id.span( A, A%*%K )
in.span( A, A%*%K, coef=TRUE )

Epi documentation built on Oct. 1, 2024, 5:07 p.m.

Related to in.span in Epi...