Description Usage Arguments Value Author(s) See Also Examples
is.positive.definite
tests whether all eigenvalues of a symmetric matrix
are positive.
make.positive.definite
computes the nearest positive definite of a
real symmetric matrix, using the algorithm of NJ Higham (1988) <DOI:10.1016/0024-3795(88)90223-6>.
rank.condition
estimates the rank and the condition
of a matrix by
computing its singular values D[i] (using svd
).
The rank of the matrix is the number of singular values D[i] > tol
)
and the condition is the ratio of the largest and the smallest
singular value.
The definition tol= max(dim(m))*max(D)*.Machine$double.eps
is exactly compatible with the conventions used in "Octave" or "Matlab".
Also note that it is not checked whether the input matrix m is real and symmetric.
1 2 3 | is.positive.definite(m, tol, method=c("eigen", "chol"))
make.positive.definite(m, tol)
rank.condition(m, tol)
|
m |
a matrix (assumed to be real and symmetric) |
tol |
tolerance for singular values and for absolute eigenvalues
- only those with values larger than
tol are considered non-zero (default:
|
method |
Determines the method to check for positive definiteness:
eigenvalue computation ( |
is.positive.definite
returns
a logical value (TRUE
or FALSE
).
rank.condition
returns a list object with the following components:
rank |
Rank of the matrix. |
condition |
Condition number. |
tol |
Tolerance. |
make.positive.definite
returns a symmetric positive definite matrix.
Korbinian Strimmer (https://strimmerlab.github.io).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # load corpcor library
library("corpcor")
# Hilbert matrix
hilbert = function(n) { i = 1:n; 1 / outer(i - 1, i, "+") }
# positive definite ?
m = hilbert(8)
is.positive.definite(m)
# numerically ill-conditioned
m = hilbert(15)
rank.condition(m)
# make positive definite
m2 = make.positive.definite(m)
is.positive.definite(m2)
rank.condition(m2)
m2 - m
|
[1] TRUE
$rank
[1] 12
$condition
[1] Inf
$tol
[1] 6.148174e-15
[1] TRUE
$rank
[1] 15
$condition
[1] 1.502707e+14
$tol
[1] 6.148174e-15
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 0 0 0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[2,] 0 0 0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[3,] 0 0 0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[4,] 0 0 0 0.000000e+00 0.000000e+00 1.387779e-17 -1.387779e-17
[5,] 0 0 0 0.000000e+00 1.387779e-17 -5.551115e-17 1.526557e-16
[6,] 0 0 0 1.387779e-17 -5.551115e-17 2.498002e-16 -6.661338e-16
[7,] 0 0 0 -1.387779e-17 1.526557e-16 -6.661338e-16 1.804112e-15
[8,] 0 0 0 2.775558e-17 -2.220446e-16 1.026956e-15 -2.872702e-15
[9,] 0 0 0 -1.387779e-17 1.526557e-16 -7.355228e-16 2.220446e-15
[10,] 0 0 0 -1.387779e-17 5.551115e-17 -1.942890e-16 1.804112e-16
[11,] 0 0 0 1.387779e-17 -1.387779e-16 6.106227e-16 -1.484923e-15
[12,] 0 0 0 0.000000e+00 -6.938894e-18 -1.387779e-17 1.873501e-16
[13,] 0 0 0 -2.081668e-17 1.387779e-16 -5.689893e-16 1.276756e-15
[14,] 0 0 0 1.387779e-17 -1.040834e-16 4.371503e-16 -1.033895e-15
[15,] 0 0 0 -6.938894e-18 2.775558e-17 -1.040834e-16 2.567391e-16
[,8] [,9] [,10] [,11] [,12]
[1,] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[2,] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[3,] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[4,] 2.775558e-17 -1.387779e-17 -1.387779e-17 1.387779e-17 0.000000e+00
[5,] -2.220446e-16 1.526557e-16 5.551115e-17 -1.387779e-16 -6.938894e-18
[6,] 1.026956e-15 -7.355228e-16 -1.942890e-16 6.106227e-16 -1.387779e-17
[7,] -2.872702e-15 2.220446e-15 1.804112e-16 -1.484923e-15 1.873501e-16
[8,] 4.829470e-15 -4.329870e-15 8.396062e-16 1.734723e-15 -6.245005e-16
[9,] -4.329870e-15 5.211109e-15 -3.386180e-15 4.371503e-16 8.118506e-16
[10,] 8.396062e-16 -3.386180e-15 5.592748e-15 -4.399259e-15 5.065393e-16
[11,] 1.734723e-15 4.371503e-16 -4.399259e-15 6.036838e-15 -3.448630e-15
[12,] -6.245005e-16 8.118506e-16 5.065393e-16 -3.448630e-15 5.488665e-15
[13,] -1.304512e-15 -3.538836e-16 1.873501e-15 1.873501e-16 -4.496403e-15
[14,] 1.221245e-15 -9.020562e-17 -1.387779e-15 6.661338e-16 1.942890e-15
[15,] -3.191891e-16 6.245005e-17 3.191891e-16 -2.220446e-16 -3.469447e-16
[,13] [,14] [,15]
[1,] 0.000000e+00 0.000000e+00 0.000000e+00
[2,] 0.000000e+00 0.000000e+00 0.000000e+00
[3,] 0.000000e+00 0.000000e+00 0.000000e+00
[4,] -2.081668e-17 1.387779e-17 -6.938894e-18
[5,] 1.387779e-16 -1.040834e-16 2.775558e-17
[6,] -5.689893e-16 4.371503e-16 -1.040834e-16
[7,] 1.276756e-15 -1.033895e-15 2.567391e-16
[8,] -1.304512e-15 1.221245e-15 -3.191891e-16
[9,] -3.538836e-16 -9.020562e-17 6.245005e-17
[10,] 1.873501e-15 -1.387779e-15 3.191891e-16
[11,] 1.873501e-16 6.661338e-16 -2.220446e-16
[12,] -4.496403e-15 1.942890e-15 -3.469447e-16
[13,] 5.676015e-15 -3.046174e-15 6.314393e-16
[14,] -3.046174e-15 1.755540e-15 -3.747003e-16
[15,] 6.314393e-16 -3.747003e-16 8.326673e-17
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.