mahalDistC: Get squared Mahalanobis distances to centroid.

View source: R/mahalDist.R

mahalDistCR Documentation

Get squared Mahalanobis distances to centroid.

Description

For N points, in M dimensions, get squared Mahalanobis distances to center.

Usage

mahalDistC(
  m,
  scale = TRUE,
  use = "complete.obs",
  center = c("mean", "median"),
  ...
)

Arguments

m

A data.frame or matrix. Observations in rows.

scale

If TRUE, scale variables before getting mahalanobis distances.

use

Observations to use in computing covariance matrix. Gets passed to cov.

center

Type of univariate center for each variable in m; "mean" or "median"

...

additional arguments passed to mahalanobis, and possibly on to solve.

Details

For each of N points in M dimensions, get squared Mahalanobis distances to distribution centroid. This is useful for checking for outliers in a multivariate distribution. The squared Mahalanobis distances to center for an MV normal distribution with N dimensions will follow the chi square distribution with DF equal to N.

This function is a convenience wrapper around mahalanobis, which see. Variables are optionally scaled before distances are computed. Incomplete observations will return NA.

Value

A list with additional class "mahalDist" containing elements:

  1. D2: A vector of squared Mahalanobis distances for observations (rows) in m. Incomplete observations return NA.

  2. vars: A character vector with the column names from m.

  3. dim: The number of columns of m.

Author(s)

Dave Braze davebraze@gmail.com

See Also

mahalanobis

cov

solve

Examples

m <- matrix(rnorm(400, m=.8, s=.05), nrow=100)
md <- mahalDistC(m)
md$D2
hist(md$D2)
rug(md$D2)


davebraze/FDButils documentation built on Feb. 24, 2023, 12:14 a.m.