R/is_covariance_matrix.R

Defines functions is_covariance_matrix

Documented in is_covariance_matrix

#' Check covariance matrix properties.
#' @description
#' This function checks if the input is a proper covariance matrix, i.e.
#' a symmetric, numeric matrix with non-negative eigenvalues.
#' @param x
#' A matrix.
#' @return
#' A boolean, \code{TRUE} if \code{x} is a proper covariance matrix.
#' @export
#' @keywords
#' helper

is_covariance_matrix = function(x){
  is.matrix(x) &&
    is.numeric(x) &&
    ncol(x) == nrow(x) &&
    all(abs(x - t(x)) < sqrt(.Machine$double.eps)) &&
    all(eigen(x)$value > -sqrt(.Machine$double.eps))
}

Try the RprobitB package in your browser

Any scripts or data that you put into this service are public.

RprobitB documentation built on Nov. 12, 2021, 5:08 p.m.