mahalanobis.dist: Mahanalobis Distance

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/clusterDistances.R

Description

Compute the Mahalanobis distance between a pair of normally distributed clusters.

Usage

1
mahalanobis.dist(mean1, mean2, cov1, cov2, n1, n2)

Arguments

mean1

mean vector of length p for cluster 1, where p is the dimension of the clusters.

mean2

mean vector of length p for cluster 2.

cov1

pxp covariance matrix for cluster 1.

cov2

pxp covariance matrix for cluster 2.

n1

number of cells (points) in cluster 1.

n2

number of cells (points) in cluster 2.

Details

Consider two p-dimensional, normally distributed clusters with centers μ1, μ2 and covariance matrices Σ1, Σ2. Assume the size of the clusters are n1 and n2 respectively. We compute the Mahalanobis distance d12 between the clusters as follows:

Σ = ( (n1-1) * Σ1 + (n2-1) * Σ2) / (n1+n2-2)

d12 = sqrt( t(μ1-μ2) * Σ^(-1) * (μ1-μ2))

The dimension of the clusters must be same.

Value

mahalanobis.dist returns a numeric value measuring the Mahalanobis distance between a pair of normally distributed clusters.

Author(s)

Ariful Azad

References

McLachlan, GJ (1999) Mahalanobis distance; Journal of Resonance 4(6), 20–26.

See Also

symmetric.KL, dist.cluster

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## ------------------------------------------------
## load data and retrieve a sample
## ------------------------------------------------

library(healthyFlowData)
data(hd)
sample = exprs(hd.flowSet[[1]])


## ------------------------------------------------
## cluster sample using kmeans algorithm
## ------------------------------------------------

km = kmeans(sample, centers=4, nstart=20)
cluster.labels = km$cluster

## ------------------------------------------------
## Create ClusteredSample object  
## and compute mahalanobis distance between two clsuters
## ------------------------------------------------

clustSample = ClusteredSample(labels=cluster.labels, sample=sample)
mean1 = get.center(get.clusters(clustSample)[[1]])
mean2 = get.center(get.clusters(clustSample)[[2]])
cov1 = get.cov(get.clusters(clustSample)[[1]])
cov2 = get.cov(get.clusters(clustSample)[[2]])
n1 = get.size(get.clusters(clustSample)[[1]])
n2 = get.size(get.clusters(clustSample)[[2]])
mahalanobis.dist(mean1, mean2, cov1, cov2, n1, n2)

Example output

Loading required package: Rcpp
Loading required package: flowCore
[1] 7.658469

flowMatch documentation built on Nov. 8, 2020, 8:02 p.m.