Mahin
Mahin

Reputation: 193

Compute the null space of a sparse matrix

I found the function (null OR nullspace) to find the null space of a regular matrix in R, but I couldn't find any function or package for a sparse matrix (sparseMatrix).

Does anybody know how to do this?

Upvotes: 3

Views: 398

Answers (1)

Vincent Guillemot
Vincent Guillemot

Reputation: 3429

If you take a look at the code of ggm::null, you will see that it is based on the QR decomposition of the input matrix.

On the other hand, the Matrix package provides its own method to compute the QR decomposition of a sparse matrix.

For example:

require(Matrix)
A <- matrix(rep(0:1, 3), 3, 2)
As <- Matrix(A, sparse = TRUE)

qr.Q(qr(A), complete=TRUE)[, 2:3]
qr.Q(qr(As), complete=TRUE)[, 2:3]

Upvotes: 3

Related Questions