Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

SparseM.ops

Basic Linear Algebra for Sparse Matrices


Description

Basic linear algebra operations for sparse matrices of class matrix.csr.

Arguments

x

matrix of class matrix.csr.

y

matrix of class matrix.csr or a dense matrix or vector.

value

replacement values.

i,j

vectors of elements to extract or replace.

nrow

optional number of rows for the result.

lag

an integer indicating which lag to use.

differences

an integer indicating the order of the difference.

Details

Linear algebra operations for matrices of class matrix.csr are designed to behave exactly as for regular matrices. In particular, matrix multiplication, kronecker product, addition, subtraction and various logical operations should work as with the conventional dense form of matrix storage, as does indexing, rbind, cbind, and diagonal assignment and extraction. The method diag may be used to extract the diagonal of a matrix.csr object, to create a sparse diagonal see SparseM.ontology.

The function determinant computes the (log) determinant, of the argument, returning a "det" object as the base function. This is preferred over using the function det() which is a simple wrapper for determinant(). Using det() in the following way is somewhat deprecated:
det() computes the determinant of the argument matrix. If the matrix is of class matrix.csr then it must be symmetric, or an error will be returned. If the matrix is of class matrix.csr.chol then the determinant of the Cholesky factor is returned, ie the product of the diagonal elements.

The function norm is used to check for symmetry by computing the maximum of the elements of the difference between the matrix and its transpose. Optionally, this sup norm can be replaced by the Hilbert-Schmidt norm, or the l1 norm.

References

Koenker, R and Ng, P. (2002). SparseM: A Sparse Matrix Package for R,
http://www.econ.uiuc.edu/~roger/research/home.html

See Also

slm for sparse linear model fitting. SparseM.ontology for coercion and other class relations involving the sparse matrix classes.

Examples

n1 <- 10
n2 <- 10
p <- 6
y <- rnorm(n1)
a <- rnorm(n1*p)
a[abs(a) < 0.5] <- 0
A <- matrix(a,n1,p)
A.csr <- as.matrix.csr(A)
b <- rnorm(n2*p)
b[abs(b)<1.0] <- 0
B <- matrix(b,n2,p)
B.csr <- as.matrix.csr(B)

# matrix transposition and multiplication
A.csr%*%t(B.csr)

# kronecker product - via kronecker() methods:
A.csr %x% matrix(1:4,2,2)

SparseM

Sparse Linear Algebra

v1.81
GPL (>= 2)
Authors
Roger Koenker [cre, aut], Pin Tian Ng [ctb] (Contributions to Sparse QR code), Yousef Saad [ctb] (author of sparskit2), Ben Shaby [ctb] (author of chol2csr)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.