Learn R Programming

metaSEM (version 0.9.4)

is.pd: Test Positive Definiteness of a List of Square Matrices

Description

It tests the positive definiteness of a square matrix or a list of square matrices. It returns TRUE if the matrix is positive definite. It returns FALSE if the matrix is either non-positive definite or not symmetric. Variables with NA in the diagonals will be removed before testing. It returns NA when there are missing correlations even after deleting the missing variables.

Usage

is.pd(x, check.asyCov=FALSE, cor.analysis=TRUE, tol=1e-06)

Arguments

x
A square matrix or a list of square matrices
check.asyCov
If it is TRUE, it mirrors the checking in asyCov.
cor.analysis
Whether the input matrix is a correlation or a covariance matrix. It is ignored when check.asyCov=FALSE.
tol
Relative tolerance of positiveness of smallest eigenvalue compared to largest eigenvalue. The matrix is considered positive definite if the ratio of the smallest eigenvalue to the largest eigenvalue is larger than tol. See

Value

  • If the input is a matrix, it returns TRUE, FALSE or NA. If the input is a list of matrices, it returns a list of TRUE, FALSE or NA.

Examples

Run this code
A <- diag(1,3)
is.pd(A)
# TRUE

B <- matrix(c(1,2,2,1), ncol=2)
is.pd(B)
# FALSE

is.pd(list(A, B))
# TRUE FALSE

C <- A
C[2,1] <- C[1,2] <- NA
is.pd(C)
# NA

Run the code above in your browser using DataLab