Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

designMD

Design Matrix Mahalanobis Distance


Description

Returns the squared Mahalanobis distance of all rows in the design (model) matrix X and the sample mean vector μ of the columns of X with respect to the sample covariance matrix Σ. This is (for vector x' a row of X) defined as

d^{2} = (x - μ)' Σ^{-1} (x - μ)

where

μ = colMeans(X)

and

Σ = cov(X).

Usage

designMD(object, ...)

Arguments

object

a fitted model object with a model.matrix method.

...

additional arguments are ignored.

Value

a numeric vector containing the squared Mahalanobis distances.

Examples

stack.lm <- lm(stack.loss ~ ., data = stackloss)

# Mahalanobis distance (not squared)
sqrt(designMD(stack.lm))

fit.models

Compare Fitted Models

v0.64
GPL
Authors
Kjell Konis [aut, cre]
Initial release
2020-08-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.