1\name{in.span} 2\alias{in.span} 3\alias{inSpan} 4\alias{id.span} 5\alias{idSpan} 6\alias{thinCol} 7\title{ 8Is \code{x} in the column span of matrix \code{A} and what columns are 9linearly dependent? 10} 11\description{ 12The function \code{in.span} checks if the vector \code{x} (or 13columns of the matrix \code{x}) is in the column span of the matrix 14\code{A}. If desired, it returns the coefficient matrix \code{B} so that 15\code{AB=x}. The function \code{thinCol} removes linearly dependent 16columns an returns a matrix of full rank. 17} 18\usage{ 19in.span( A, 20 x, 21 coef = FALSE, 22 tol = 1e-08 ) 23inSpan( A, x, coef=FALSE, tol=1e-08 ) 24id.span( A, B, tol=1e-08 ) 25idSpan( A, B, tol=1e-08 ) 26thinCol( A, tol = 1e-06, col.num = FALSE ) 27} 28\details{\code{\link{thinCol}} is mainly a workhorse in 29 \code{\link{detrend}}, but made available because of its general 30 usefulness. 31 32 \code{in.span} and \code{inSpan} are just different names for the same 33 to accommodate different naming schools. 34 35 \code{in.span} (\code{inSpan}) is handy in checking whether different 36 parametrizations of a model are identical in the sense of spanning the 37 same linear space. Equivalent to checking whether fitted values under 38 different parametrizations are identical, but has the further use of 39 checking if subspaces of models are equivalent. The function 40 simply checks if the regression of (columns of) \code{x} on the 41 columns of \code{A} produces residuals that are all 0. 42 43 \code{id.span} (equivalent to \code{idSpan}) checks whether two 44 matrices have the same column span. 45} 46\arguments{ 47\item{A}{A matrix.} 48\item{B}{A matrix.} 49\item{x}{A vector or matrix. \code{length(x)} (or \code{nrow(x)}) must 50 be equal to \code{nrow(A)}.} 51\item{coef}{Logical. Should the coefficient matrix (\code{k}) be 52 returned, so that \code{Ak=x}?} 53\item{tol}{Tolerance for identity of matrices in check 54 (\code{in.span}) or QR decomposition (\code{thinCol})} 55\item{col.num}{Logical. Should the positions of dependent columns be 56 returned instead of the full-rank matrix?} 57} 58\value{\code{in.span} returns a logical: is \code{x} is in 59 \code{span(A)}? If \code{coef=TRUE} it returns a matrix \code{k} so 60 that \code{Ak=x}. \code{k} is not necessarily unique (A may not have 61 full rank). 62 63 \code{id.span} returns a logical: is \code{span(A)} the same as 64 \code{span(B)}? 65 66 \code{thinCol} returns a matrix of full rank, formed from \code{A} by 67 deleting columns linearly dependent on other. If \code{col.num=TRUE} 68 (one possible set of) positions of columns forming a full rank basis 69 for the column space of \code{A} is returned. 70} 71\author{Bendix Carstensen, \url{http://bendixcarstensen.com} with essential 72 help from Lars Jorge Diaz and Peter Dalgaard. 73} 74\seealso{\code{\link{det}} 75} 76\examples{ 77# Matrices and vectors, x in span(A), z (hopefully) not 78A <- matrix(round(rnorm(15)*20),5,3) 79B <- matrix(round(rnorm(15)*20),5,3) 80B <- cbind( B, B\%*\%c(3,4,2) ) 81x <- A \%*\% c(3,4,2) 82z <- 5:9 83 84# how they look 85data.frame( A=A, x=x, z=z, B=B ) 86 87# vectors in span(A)? 88in.span(A,x) 89in.span(x,A) 90in.span(A,x,coef=TRUE) 91 92in.span(A,z) 93in.span(A,z,coef=TRUE) 94 95# Do matrices span the same space ? 96in.span( A, B ) 97in.span( B, A ) 98 99# B is not in span of a subspace of B columns, but vice versa 100( M <- matrix( rnorm(8)*7, 4, 2 ) ) 101in.span( B\%*\%M, B ) 102in.span( B, B\%*\%M ) 103id.span( B, B\%*\%M ) 104 105# But not unique for singular matrices: 106( xx <- in.span( B, B\%*\%M, coef=TRUE ) ) 107cbind( B\%*\%M, B\%*\%xx ) 108cbind( xx, M ) 109 110# Easier for full rank matrices: 111( K <- matrix( rnorm(9)*7, 3, 3 ) ) 112in.span( A\%*\%K, A ) 113in.span( A, A\%*\%K ) 114id.span( A, A\%*\%K ) 115in.span( A, A\%*\%K, coef=TRUE ) 116} 117\keyword{math} 118