Skip to content

Matrix Inversion

3 messages · Wang Chengbin, robin hankin, Peter Dalgaard

#
I got the following error:

a = read.csv("mat.csv")
b = as.matrix(a)
tb = t(b)
bb = tb %*% b
dim(bb)
ibb = solve(bb)
bb %*% ibb
Error in solve.default(bb) :
  system is computationally singular: reciprocal condition number =
1.77573e-19
Are there any ways to find more information about why it is singular?

Thanks.
#
Hello Wang

matrix bb is symmetric positive semidefinite, so
algebraically the eigenvalues are nonnegative.

I would use

bb <- crossprod(b)

to calculate bb (faster and possibly more accurate)

Look at eigen(bb,TRUE,TRUE)$values

(see ?eigen for the meaning of the arguments) to see how
many very small eigenvalues you have.  The number of zero
eigenvalues is equal to the number of linear relations
in the columns of b.


HTH


rksh
On 12 Dec 2007, at 10:59, Wang Chengbin wrote:

            
--
Robin Hankin
Uncertainty Analyst and Neutral Theorist,
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743
#
Wang Chengbin wrote:
Yes. Since the matrix is positive semidefinite by construction, I'd
probably go for chol(bb, pivot=TRUE), then the first "rank" elements of
"pivot" gives you a maximal subset of linearly independent columns, and
you can proceed by something like lm(b[,-subset]~b[,subset]) to see what
the linear dependencies are.

(Other approaches could be eigen() and svd().)