designMD: Design Matrix Mahalanobis Distance

Description Usage Arguments Value Examples

View source: R/designMD.R

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

1
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

1
2
3
4
stack.lm <- lm(stack.loss ~ ., data = stackloss)

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

Example output

        1         2         3         4         5         6         7         8 
2.2536034 2.3247448 1.5937124 1.2718978 0.3033573 0.7728947 1.8526614 1.8526614 
        9        10        11        12        13        14        15        16 
1.3606218 1.7459966 1.4657021 1.8415044 1.4826491 1.7787851 1.6902415 1.2919339 
       17        18        19        20        21 
2.7000165 1.5031545 1.5932205 0.8070539 2.1767610 

fit.models documentation built on Aug. 2, 2020, 5:06 p.m.