add_mahalanobis: Add Mahalanobis distance

View source: R/distances.R

add_mahalanobisR Documentation

Add Mahalanobis distance

Description

Add a mahalanobis distance to the end of a data frame.

Usage

add_mahalanobis(
  df,
  ...,
  .inverted = FALSE,
  .name = "md",
  .p = "p_value",
  tolerance = .Machine$double.eps
)

Arguments

df

A data.frame

...

Columns to select

.inverted

Logical. If TRUE, covariance matrix (p x p) of the distribution is supposed to contain the inverse of the covariance matrix.

.name

The name of the new column for the distance value

.p

The name for the new column for the p-value calculation

tolerance

'tol' in [base::solve()]

Examples

df <- head(iris)
add_mahalanobis(df, Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
df[1, ] <- NA_real_
add_mahalanobis(df, Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)

jmbarbone/jordanExtra documentation built on Aug. 4, 2023, 5:37 p.m.