Learn R Programming

monomvn (version 1.9-1)

posdef.approx: Find the Nearest Positive Definite Matrix

Description

Check if the matrix is positive definite via attempted Cholesky decomposition and inversion. If not, then the sechol function is used to obtain the nearest approximate Cholesky decomposition from which to recover an approximate covariance matrix which is positive definite. If that doesn't do the trick, then .Machine$double.eps is added to the diagonal (as a last-ditch effort) until a positive definite matrix can be returned

Usage

posdef.approx(S, name = "S", quiet=FALSE)

Arguments

S
square matrix which is supposed to be positive definite
name
optional name of the matrix -- used for printing errors and warnings
quiet
whether or not to print a warning when a non-positive definite matrix is found

Value

  • Returns a matrix which is positive definite: either the original matrix, or a nearby positive definite approximation

References

Micah Altman, Jeff Gill and Michael McDonald (2003). Numerical Issues in Statistical Computing for the Social Scientist. John Wiley and Sons, New York. http://www.hmdc.harvard.edu/micah_altman/numal/

http://faculty.chicagobooth.edu/robert.gramacy/monomvn.html

See Also

sechol in the accuracy package

Examples

Run this code
## most likely generates a matrix which is close to positive definite
## but not quite
s <- matrix(rnorm(100), ncol=5)
S <- (t(s) %*% s) + matrix(rnorm(25, sd=10), ncol=5)
S

## a correction, quiet=TRUE so there is no warning printed
posdef.approx(S, quiet=TRUE)

Run the code above in your browser using DataLab