metan (version 1.2.1)

mahala: Mahalanobis Distance

Description

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)

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.

Value

A symmetric matrix with the Mahalanobis' distance.

Examples

Run this code
# NOT RUN {
library(metan)
library(dplyr)
# Compute the mean for genotypes
means = data_ge %>%
        select(-c(ENV, REP)) %>%
        group_by(GEN) %>%
        summarise_all(mean) %>%
        select(-GEN)

# Compute the covariance matrix
covmat = cov(means)

# Compute the distance
dist = mahala(means, covmat)

# Dendrogram
dend = as.dendrogram(hclust(as.dist(dist)))
plot(dend)

# }

Run the code above in your browser using DataCamp Workspace