Learn R Programming

fit.models (version 0.64)

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 \(\mu\) of the columns of \(X\) with respect to the sample covariance matrix \(\Sigma\). This is (for vector \(x'\) a row of \(X\)) defined as $$d^{2} = (x - \mu)' \Sigma^{-1} (x - \mu)$$ where $$\mu = colMeans(X)$$ and $$\Sigma = 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

Run this code
# NOT RUN {
stack.lm <- lm(stack.loss ~ ., data = stackloss)

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

Run the code above in your browser using DataLab