metan (version 1.18.0)

mahala: Mahalanobis Distance

Description

[Stable]

Compute the Mahalanobis distance of all pairwise rows in .means. The result is a symmetric matrix containing the distances that may be used for hierarchical clustering.

Usage

mahala(.means, covar, inverted = FALSE)

Value

A symmetric matrix with the Mahalanobis' distance.

Arguments

.means

A matrix of data with, say, p columns.

covar

The covariance matrix.

inverted

Logical argument. If TRUE, covar is supposed to contain the inverse of the covariance matrix.

Author

Tiago Olivoto tiagoolivoto@gmail.com

Examples

Run this code
# \donttest{
library(metan)
library(dplyr)
# Compute the mean for genotypes
means <- mean_by(data_ge, GEN) %>%
         column_to_rownames("GEN")

# Compute the covariance matrix
covmat <- cov(means)

# Compute the distance
dist <- mahala(means, covmat)

# Dendrogram
dend <- dist %>%
        as.dist() %>%
        hclust() %>%
        as.dendrogram()
plot(dend)
# }

Run the code above in your browser using DataLab