MVNH_dissimilarity: MVNH_dissimilarity

View source: R/MVNH_functions.R

MVNH_dissimilarityR Documentation

MVNH_dissimilarity

Description

This function calculates the dissimilarity metric between a pair of multivariate normal hypervolumes, as well as the partitioned centroid distance and determinant ratio components.

Usage

MVNH_dissimilarity(db1,db2,mean1,mean2,cov1,cov2,
                   metric,var.names,cov.matrix)

Arguments

db1, db2

Datasets with rows as observations and columns as variables. The order matters only with the "MacArthur-Levin" metric which compares db2 against db1. Not used when cov.matrix=T.

cov.matrix

Logical value, the default is False. To supply covariance matrices and mean values instead of datasets for calculation.

mean1, mean2

means of hypervolumes supplied by user rather than calculated from the datasets. Should be vectors of length(variables). Used only when cov.matrix=T.

cov1, cov2

The covariance matrices supplied for the calculation. Used only when cov.matrix is TRUE.

metric

Metrics used to calculate the dissimilarity. The default is the "Bhattacharyya_distance". Other available options are "MacArthur-Levins","Pianka","Morisita". Note that Morisita distance does not provide a paritioning for the determinant ratio component, and "MacArthur-Levins" is an asymmetric measure.

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

Mahalanobis_distance

The Mahalanobis distance component of the total dissimilarity of the Bhattacharyya distance, Pianka's metric etc.

Determinant_ratio

The determinant ratio component of the total dissimilarity of the Bhattacharyya distance, Pianka's metric etc.

total

The total dissimilarity of the returned item.

variable i

The dissimilarity of variable i.

cor

The correlation component which is the total dissimilarity subtracted by the sum of all univariate dissimilarity.

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_dissimilarity(db1,db2)

# or directly supply the means and covariance matrices
MVNH_dissimilarity(mean1=c(1,1),mean2=c(2,2),
  cov1=matrix(c(1,0,0,1),nrow=2),cov2=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.