Skip to contents

These functions check whether the input fulfills the properties of a correlation matrix, i.e., whether it is a square, symmetric, and positive semi-definite matrix with ones on the diagonal and values between -1 and 1.

Usage

check_correlation_matrix(x, dim = NULL, tolerance = sqrt(.Machine$double.eps))

assert_correlation_matrix(
  x,
  dim = NULL,
  tolerance = sqrt(.Machine$double.eps),
  .var.name = checkmate::vname(x),
  add = NULL
)

test_correlation_matrix(x, dim = NULL, tolerance = sqrt(.Machine$double.eps))

Arguments

x

[any]
Object to check.

dim

[integer(1)]
The matrix dimension.

tolerance

[numeric(1)]
A non-negative tolerance value, which is used when checking for symmetry, for ones on the diagonal, and for non-negative eigenvalues.

.var.name

[character(1)]
Name of the checked object to print in assertions. Defaults to the heuristic implemented in vname.

add

[AssertCollection]
Collection to store assertion messages. See AssertCollection.

Value

Same as documented in check_matrix.

Examples

M <- matrix(c(1,  0.9,  0.9, 0.9,  1,  -0.9, 0.9,  -0.9,  1), nrow = 3)
check_correlation_matrix(M)
#> [1] "Must have positive eigenvalues only"
test_correlation_matrix(M)
#> [1] FALSE
try(assert_correlation_matrix(M))
#> Error in try(assert_correlation_matrix(M)) : 
#>   Assertion on 'M' failed: Must have positive eigenvalues only.