cmahalanobis: Calculate the Mahalanobis distance for each species.

View source: R/cmahalanobis.R

cmahalanobisR Documentation

Calculate the Mahalanobis distance for each species.

Description

This function takes a dataframe and a factor in input, and returns a matrix with the Mahalanobis distances about it.

Usage

cmahalanobis(
  dataset,
  formula,
  plot = TRUE,
  plot_title = "Mahalanobis Distance Between Groups"
)

Arguments

dataset

A dataframe.

formula

A factor which you want to calculate the Mahalanobis distances matrix.

plot

Logical, if TRUE, a plot of Mahalanobis distances matrix is displayed.

plot_title

The title to be used for the plot if plot is TRUE.

Value

A matrix containing Mahalanobis distances between each pair of groups and the plot.

Examples

# Example with the iris dataset

data(iris)

# Calculate the Mahalanobis distance with the cmahalanobis function
cmahalanobis(iris, ~Species, plot = TRUE, plot_title = "Mahalanobis Distance Between Groups")

# Example with the mtcars dataset
data(mtcars)

# Calculate the Mahalanobis distance with the cmahalanobis function
cmahalanobis(mtcars, ~am, plot = TRUE, plot_title = "Mahalanobis Distance Between Groups")


cmahalanobis documentation built on April 3, 2025, 8:51 p.m.