[R] rank of Matrix

Carson Farmer carson.farmer at gmail.com
Thu Mar 31 21:24:24 CEST 2011


Dear list,

Can anyone tell me how to obtain the rank of a sparse Matrix, for
example from package Matrix (class dgCMatrix)? Here is an example of
QR decomposition of a sparse matrix (from the sparseQR class help).

library(Matrix)
data(KNex)
mm <- KNex$mm
str(mmQR <- qr(mm))

Similarly, using the functions/classes from the relatively new
MatrixModels package:

library(MatrixModels)
str(trial <- data.frame(counts=c(18,17,15,20,10,20,25,13,12),
                        outcome=gl(3,1,9,labels=LETTERS[1:3]),
                        treatment=gl(3,3,labels=letters[1:3])))
glmS <- glm4(counts ~ 0+outcome + treatment, poisson, trial,
                      verbose = TRUE, sparse = TRUE)
str(glmS)
str(X <- glmS at pred@X)
str(QR <- qr(X))

I'm not very familiar with matrix decomposition, but is the 'p' slot
from a sparseQR object the same as $pivot from base qr? Additionally,
how do I obtain the rank of the input matrix? qr from the base package
produces an object with several components, two of which are rank, and
pivot, is there an equivalent way of getting at these values/vectors
for sparse matrices?
Basically, I am trying to get at the variance-covariance matrix in
order to compute t-values for the coefficients of a (sparse) GLM (i.e.
a summary function for class glpModel). Am I going about this the
right way? Are they perhaps more efficient ways of doing this when
working with sparse matrices. Is there a preferred way of calculating
t-statistics? Note that 'rankMatrix' from package Matrix appears to
densify the matrix before use, so this is not a viable option.

I have asked a similar question before [1], though I am now trying to
'answer' it myself by digging in and actually coding a bit more
myself, however, as you can see I'm still a bit stuck :-(

Thanks for any suggestions,

Carson

[1] http://www.mail-archive.com/r-help@r-project.org/msg130145.html

-- 
Carson J. Q. Farmer
ISSP Doctoral Fellow
National Centre for Geocomputation
National University of Ireland, Maynooth,
http://www.carsonfarmer.com/



More information about the R-help mailing list