MVNH_det: MVHN_det

View source: R/MVNH_functions.R

MVNH_detR Documentation

MVHN_det

Description

This function calculates the determinant of the covariance matrix (generalized variance), as well as the univariate variances and a correlation component.

Usage

MVNH_det(data,cov,var.names,cov.matrix,log)

Arguments

data

Dataset with rows as observations and columns as variables. Not used when cov.matrix=T.

cov.matrix

Logical value, the default is False. To supply a covariance matrix instead of the dataset for calculation.

cov

The covariance matrix supplied for the calculation. Only used when cov.matrix is TRUE.

log

Logical value, the default is False. Whether the log-value should be returned.

var.names

Names of the variables provided by user. The default is NULL, which takes the column names of the matrix or the dataset, or use 'variable1', 'variable2'... when no names are associated with the data.

Value

total

The determinant of the covariance matrix.

variable i

The variance of variable i.

cor

The correlation component which is the determinant devided by the product of all univariate variances.

Note

When the covariance matrix is singular (high collinearity), the metric is not reliable because the determinant will aprroximate 0.

Author(s)

Muyang Lu (muyang.lu@yale.edu), Kevin Winner, Walter Jetz

References

Lu, M., Winner, K., & Jetz, W. (2020). A unifying framework for quantifying and comparing n-dimensional hypervolumes. BioRxiv. https://doi.org/10.1101/2020.11.21.392696

Examples

## two multivariate normal distributions as toy example
library(MASS)
# db1 for dataframe1 db2 for dataframe2
# two random matrixes generated by 2 mutivariate normal distributions
db1 = mvrnorm(n=50,mu=c(1,1),Sigma=matrix(c(1,0,0,1),nrow=2))
db2 = mvrnorm(n=50,mu=c(2,2),Sigma=matrix(c(2,0.6,0.6,0.5),nrow=2))
MVNH_det(db1)
MVNH_det(db2)
# or directly supply the covariance matrices
MVNH_det(cov=matrix(c(1,0,0,1),nrow=2),cov.matrix=TRUE)
MVNH_det(cov=matrix(c(2,0.6,0.6,0.5),nrow=2),cov.matrix=TRUE)

lvmuyang/MVNH documentation built on Nov. 2, 2024, 1 a.m.