Examples for 'Matrix::dpoMatrix-class'


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

Aliases: dpoMatrix-class dppMatrix-class corMatrix-class Arith,dpoMatrix,logical-method Arith,dpoMatrix,numeric-method Arith,logical,dpoMatrix-method Arith,numeric,dpoMatrix-method Ops,dpoMatrix,logical-method Ops,dpoMatrix,numeric-method Ops,logical,dpoMatrix-method Ops,numeric,dpoMatrix-method coerce,dpoMatrix,corMatrix-method coerce,dpoMatrix,dppMatrix-method coerce,matrix,dpoMatrix-method determinant,dpoMatrix,logical-method Arith,dppMatrix,logical-method Arith,dppMatrix,numeric-method Arith,logical,dppMatrix-method Arith,numeric,dppMatrix-method Ops,dppMatrix,logical-method Ops,dppMatrix,numeric-method Ops,logical,dppMatrix-method Ops,numeric,dppMatrix-method coerce,dppMatrix,corMatrix-method coerce,dppMatrix,dpoMatrix-method coerce,matrix,dppMatrix-method determinant,dppMatrix,logical-method coerce,matrix,corMatrix-method

Keywords: classes algebra

### ** Examples

h6 <- Hilbert(6)
rcond(h6)
[1] 3.439939e-08
str(h6)
Formal class 'dpoMatrix' [package "Matrix"] with 5 slots
  ..@ Dim     : int [1:2] 6 6
  ..@ Dimnames:List of 2
  .. ..$ : NULL
  .. ..$ : NULL
  ..@ x       : num [1:36] 1 0.5 0.333 0.25 0.2 ...
  ..@ uplo    : chr "U"
  ..@ factors :List of 1
  .. ..$ Cholesky:Formal class 'Cholesky' [package "Matrix"] with 5 slots
  .. .. .. ..@ Dim     : int [1:2] 6 6
  .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. ..$ : NULL
  .. .. .. .. ..$ : NULL
  .. .. .. ..@ x       : num [1:36] 1 0 0 0 0 ...
  .. .. .. ..@ uplo    : chr "U"
  .. .. .. ..@ diag    : chr "N"
h6 * 27720 # is ``integer''
6 x 6 Matrix of class "dpoMatrix"
      [,1]  [,2] [,3] [,4] [,5] [,6]
[1,] 27720 13860 9240 6930 5544 4620
[2,] 13860  9240 6930 5544 4620 3960
[3,]  9240  6930 5544 4620 3960 3465
[4,]  6930  5544 4620 3960 3465 3080
[5,]  5544  4620 3960 3465 3080 2772
[6,]  4620  3960 3465 3080 2772 2520
solve(h6)
6 x 6 Matrix of class "dpoMatrix"
      [,1]    [,2]     [,3]     [,4]     [,5]     [,6]
[1,]    36    -630     3360    -7560     7560    -2772
[2,]  -630   14700   -88200   211680  -220500    83160
[3,]  3360  -88200   564480 -1411200  1512000  -582120
[4,] -7560  211680 -1411200  3628800 -3969000  1552320
[5,]  7560 -220500  1512000 -3969000  4410000 -1746360
[6,] -2772   83160  -582120  1552320 -1746360   698544
str(hp6 <- as(h6, "dppMatrix"))
Formal class 'dppMatrix' [package "Matrix"] with 5 slots
  ..@ uplo    : chr "U"
  ..@ Dim     : int [1:2] 6 6
  ..@ Dimnames:List of 2
  .. ..$ : NULL
  .. ..$ : NULL
  ..@ x       : num [1:21] 1 0.5 0.333 0.333 0.25 ...
  ..@ factors :List of 1
  .. ..$ Cholesky:Formal class 'Cholesky' [package "Matrix"] with 5 slots
  .. .. .. ..@ Dim     : int [1:2] 6 6
  .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. ..$ : NULL
  .. .. .. .. ..$ : NULL
  .. .. .. ..@ x       : num [1:36] 1 0 0 0 0 ...
  .. .. .. ..@ uplo    : chr "U"
  .. .. .. ..@ diag    : chr "N"
### Note that  as(*, "corMatrix")  *scales* the matrix
(ch6 <- as(h6, "corMatrix"))
6 x 6 Matrix of class "corMatrix"
          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
[1,] 1.0000000 0.8660254 0.7453560 0.6614378 0.6000000 0.5527708
[2,] 0.8660254 1.0000000 0.9682458 0.9165151 0.8660254 0.8206518
[3,] 0.7453560 0.9682458 1.0000000 0.9860133 0.9583148 0.9270248
[4,] 0.6614378 0.9165151 0.9860133 1.0000000 0.9921567 0.9749960
[5,] 0.6000000 0.8660254 0.9583148 0.9921567 1.0000000 0.9949874
[6,] 0.5527708 0.8206518 0.9270248 0.9749960 0.9949874 1.0000000
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))

[Package Matrix version 1.5-3 Index]