Skip to content

rank of a matrix

5 messages · Huntsinger, Reid, Gabor Grothendieck, Duncan Murdoch +1 more

#
qr() returns an estimate of the rank. However the rank of a matrix isn't
really computable (or useful) in general in finite precision arithmetic. The
Hilbert matrix example (from help(svd)) is a good illustration:
[1] 7

but it's actually an invertible 9 x 9 matrix. 


Rather you can estimate how far a matrix is from having rank <= k for
example. A book on numerical linear algebra would be a good reference.

A common approach to statistical analysis of certain kinds of data deals
with the ranks of the data values, and that's why you got so many hits for
"rank". 

Reid Huntsinger

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of mingan
Sent: Wednesday, May 04, 2005 11:54 AM
To: r-help at stat.math.ethz.ch
Subject: [R] rank of a matrix




how do I check the rank of a matrix ?

say

A=  1   0   0
     0   1   0

then rank(A)=2

what is this function?

thanks


  I did try help.search("rank"), but all the returned help information 
seem irrelevant to what I want.

  I would like to know how people search for help information like this.






rank(base)              Sample Ranks
SignRank(stats)         Distribution of the Wilcoxon Signed Rank
                        Statistic
Wilcoxon(stats)         Distribution of the Wilcoxon Rank Sum
                        Statistic
friedman.test(stats)    Friedman Rank Sum Test
kruskal.test(stats)     Kruskal-Wallis Rank Sum Test
pairwise.wilcox.test(stats)
                        Pairwise Wilcoxon rank sum tests
wilcox.test(stats)      Wilcoxon Rank Sum and Signed Rank Tests

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
#
In this case, try a lower tolerance (1e-7 is the default):
[1] 9
On 5/4/05, Huntsinger, Reid <reid_huntsinger at merck.com> wrote:
#
Gabor Grothendieck wrote:
But don't trust the results.  For example, create a matrix with 4 
identical copies of hilbert(9).  This still has rank 9.  It's hard to 
find, though:

 > h9 <- hilbert(9)
 > temp <- cbind(h9, h9)
 > h9times4 <- rbind(temp, temp)
 >
 > qr(h9times4,tol=1e-7)$rank
[1] 7
 > qr(h9times4, tol=1e-8)$rank
[1] 10
 > qr(h9times4, tol=1e-9)$rank
[1] 11
 > qr(h9times4, tol=1e-10)$rank
[1] 12


There's a tolerance that gives the right answer (1.5e-8 works for me), 
but how would I know that in a real problem where I didn't already know 
the answer?

Duncan Murdoch
#
For the example that Duncan just gave, using the "matrix.rank" function of
Spencer Graves (which uses singular value decomposition) I obtained the
following result:
[1] 6 7 7 8 8 9 9 9 9 9

This tells me that the correct rank should be 9, since the rank stabilizes
for smaller tolerances.  I realize that this may not work generally, and one
could create counter-examples to defeat this strategy.

Best,
Ravi.

--------------------------------------------------------------------------
Ravi Varadhan, Ph.D.
Assistant Professor,  The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email:  rvaradhan at jhmi.edu
--------------------------------------------------------------------------
#
One could also examine the eigenvalues themselves:

    plot(log(abs(sort(-eigen(h9times4, T, T)$values))))

shows a graph with a definite gap between 9 and 10 suggesting
that 9 is the right number.
On 5/4/05, Ravi Varadhan <rvaradha at jhsph.edu> wrote: