[R] backsolve, chol, Matrix, and SparseM

Benjamin Tyner btyner at gmail.com
Thu Sep 24 19:47:58 CEST 2015


I have some code which does (on a symmetric matrix 'x')

    backsolve(chol(x), diag(nrow(x)))

and I am wondering what is the recommended way to accomplish this when x
is also sparse (from package:Matrix). I know that package:Matrix
provides a chol method for such matrices, but not a backsolve method. On
the other hand, package:SparseM does provide a backsolve method, but
doesn't actually return a sparse matrix. Moreover, I am a little
hesitant to use SparseM, as the vignette seems to be from 2003.

I did notice that help(topic = "solve", package = "Matrix") says "In
‘solve(a,b)’ in the ‘Matrix’ package, ‘a’ may also be a
‘MatrixFactorization’ instead of directly a matrix." which makes me
think this is the right way:

    Matrix::solve(Cholesky(x), .sparseDiagonal(nrow(x)))

but unfortunately this didn't give the same result as:

    Matrix::solve(chol(x), .sparseDiagonal(nrow(x)))

so I'm asking here in case someone has any suggestions.


More information about the R-help mailing list