dpoMatrix-class: Positive Semi-definite Dense (Packed | Non-packed) Numeric...

dpoMatrix-classR Documentation

Positive Semi-definite Dense (Packed | Non-packed) Numeric Matrices


  • The "dpoMatrix" class is the class of positive-semidefinite symmetric matrices in nonpacked storage.

  • The "dppMatrix" class is the same except in packed storage. Only the upper triangle or the lower triangle is required to be available.

  • The "corMatrix" class of correlation matrices extends "dpoMatrix" with a slot sd, which allows to restore the original covariance matrix.

Objects from the Class

Objects can be created by calls of the form new("dpoMatrix", ...) or from crossprod applied to an "dgeMatrix" object.



Object of class "character". Must be either "U", for upper triangular, and "L", for lower triangular.


Object of class "numeric". The numeric values that constitute the matrix, stored in column-major order.


Object of class "integer". The dimensions of the matrix which must be a two-element vector of non-negative integers.


inherited from class "Matrix"


Object of class "list". A named list of factorizations that have been computed for the matrix.


(for "corMatrix") a numeric vector of length n containing the (original) sqrt(var(.)) entries which allow reconstruction of a covariance matrix from the correlation matrix.


Class "dsyMatrix", directly.
Classes "dgeMatrix", "symmetricMatrix", and many more by class "dsyMatrix".



signature(x = "dpoMatrix"): Returns (and stores) the Cholesky decomposition of x, see chol.


signature(x = "dpoMatrix"): Returns the determinant of x, via chol(x), see above.


signature(x = "dpoMatrix", norm = "character"): Returns (and stores) the reciprocal of the condition number of x. The norm can be "O" for the one-norm (the default) or "I" for the infinity-norm. For symmetric matrices the result does not depend on the norm.


signature(a = "dpoMatrix", b = "....")

, and


signature(a = "dppMatrix", b = "....")

work via the Cholesky composition, see also the Matrix solve-methods.


signature(e1 = "dpoMatrix", e2 = "numeric") (and quite a few other signatures): The result of (“elementwise” defined) arithmetic operations is typically not positive-definite anymore. The only exceptions, currently, are multiplications, divisions or additions with positive length(.) == 1 numbers (or logicals).


Currently the validity methods for these classes such as getValidity(getClass("dpoMatrix")) for efficiency reasons only check the diagonal entries of the matrix – they may not be negative. This is only necessary but not sufficient for a symmetric matrix to be positive semi-definite.

A more reliable (but often more expensive) check for positive semi-definiteness would look at the signs of diag(BunchKaufman(.)) (with some tolerance for very small negative values), and for (strict) positive definiteness at something like !inherits(tryCatch(chol(.), error=identity), "error") . Indeed, when coercing to these classes, a version of Cholesky() or chol() is typically used, e.g., see selectMethod("coerce", c(from="dsyMatrix", to="dpoMatrix")) .

See Also

Classes dsyMatrix and dgeMatrix; further, Matrix, rcond, chol, solve, crossprod.


h6 <- Hilbert(6)
h6 * 27720 # is ``integer''
str(hp6 <- as(h6, "dppMatrix"))

### Note that  as(*, "corMatrix")  *scales* the matrix
(ch6 <- as(h6, "corMatrix"))
stopifnot(all.equal(h6 * 27720, round(27720 * h6), tolerance = 1e-14),
          all.equal(ch6@sd^(-2), 2*(1:6)-1, tolerance= 1e-12))
chch <- chol(ch6)
stopifnot(identical(chch, ch6@factors$Cholesky),
          all(abs(crossprod(chch) - ch6) < 1e-10))

Matrix documentation built on Sept. 13, 2022, 9:05 a.m.