ssolve {statnet.common}R Documentation

Wrappers around matrix algebra functions that pre-scale their arguments

Description

Covariance matrices of variables with very different orders of magnitude can have very large ratios between their greatest and their least eigenvalues, causing them to appear to the algorithms to be near-singular when they are actually very much SPD. These functions first scale the matrix's rows and/or columns by its diagonal elements and then undo the scaling on the result.

Usage

ssolve(a, b, ..., snnd = TRUE)

sginv(X, ..., snnd = TRUE)

srcond(x, ..., snnd = TRUE)

snearPD(x, ...)

xTAx_ssolve(x, A, ...)

xTAx_qrssolve(x, A, tol = 1e-07, ...)

sandwich_ssolve(A, B, ...)

Arguments

snnd

assume that the matrix is symmetric non-negative definite (SNND). If it's "obvious" that it's not (e.g., negative diagonal elements), an error is raised.

x, a, b, X, A, B, tol, ...

corresponding arguments of the wrapped functions.

Details

ssolve(), sginv(), and snearPD() wrap solve(), MASS::ginv(), and Matrix::nearPD(), respectively. srcond() returns the reciprocal condition number of rcond() net of the above scaling. xTAx_ssolve, xTAx_qrssolve, and sandwich_ssolve wrap the corresponding statnet.common functions.

Examples

x <- rnorm(2, sd=c(1,1e12))
x <- c(x, sum(x))
A <- matrix(c(1, 0, 1,
              0, 1e24, 1e24,
              1, 1e24, 1e24), 3, 3)
stopifnot(all.equal(
  xTAx_qrssolve(x,A),
  structure(drop(x%*%sginv(A)%*%x), rank = 2L, nullity = 1L)
))

x <- rnorm(2, sd=c(1,1e12))
x <- c(x, rnorm(1, sd=1e12))
A <- matrix(c(1, 0, 1,
              0, 1e24, 1e24,
              1, 1e24, 1e24), 3, 3)

stopifnot(try(xTAx_qrssolve(x,A), silent=TRUE) ==
  "Error in xTAx_qrssolve(x, A) : x is not in the span of A\n")


[Package statnet.common version 4.9.0 Index]