Learn R Programming

Matrix (version 1.7-4)

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

Description

  • 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" and "copMatrix" classes represent correlation matrices. They extend "dpoMatrix" and "dppMatrix", respectively, with an additional slot sd allowing restoration of the original covariance matrix.

Arguments

See Also

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

Examples

Run this code
 
library(utils, pos = "package:base", verbose = FALSE)

h6 <- Hilbert(6)
rcond(h6)
str(h6)
h6 * 27720 # is ``integer''
solve(h6)
str(hp6 <- pack(h6))

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

Run the code above in your browser using DataLab