Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rank.condition

Positive Definiteness of a Matrix, Rank and Condition Number


Description

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.

Usage

is.positive.definite(m, tol, method=c("eigen", "chol"))
make.positive.definite(m, tol)
rank.condition(m, tol)

Arguments

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: tol = max(dim(m))*max(D)*.Machine$double.eps)

method

Determines the method to check for positive definiteness: eigenvalue computation (eigen, default) or Cholesky decomposition (chol).

Value

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.

Author(s)

Korbinian Strimmer (https://strimmerlab.github.io).

See Also

Examples

# 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

corpcor

Efficient Estimation of Covariance and (Partial) Correlation

v1.6.10
GPL (>= 3)
Authors
Juliane Schafer, Rainer Opgen-Rhein, Verena Zuber, Miika Ahdesmaki, A. Pedro Duarte Silva, and Korbinian Strimmer.
Initial release
2021-09-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.