View source: R/FullConditionals.R
| is.posi_def | R Documentation | 
Tests whether all eigenvalues of a symmetric matrix are positive (or strictly non-negative) to check for positive-definiteness and positive-semidefiniteness, respectively. If the supplied matrix doesn't satisfy the test, the nearest matrix which does can optionally be returned.
is.posi_def(x,
            tol = NULL,
            semi = FALSE,
            make = FALSE)
x | 
 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 =   | 
semi | 
 Logical switch to test for positive-semidefiniteness when   | 
make | 
 Logical switch to return the nearest matrix which satisfies the test - if the test has been passed, this is of course just   | 
If isTRUE(make), a list with two components:
check | 
 A logical value indicating whether the matrix satisfies the test.  | 
X.new | 
 The nearest matrix which satisfies the test (which may just be the input matrix itself.)  | 
Otherwise, only the logical value indicating whether the matrix satisfies the test is returned.
x    <- cov(matrix(rnorm(100), nrow=10, ncol=10))
is.posi_def(x)                                           #FALSE
is.posi_def(x, semi=TRUE)                                #TRUE
Xnew <- is.posi_def(x, semi=FALSE, make=TRUE)$X.new
identical(x, Xnew)                                       #FALSE
identical(x, is.posi_def(x, semi=TRUE, make=TRUE)$X.new) #TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.