A function to perform discriminant analysis based on the squared generalized Mahalanobis distance (D2) of the observations to the center of the groups.

# S3 method for default
D2.disc(data, grouping, pooled.cov = NULL)
# S3 method for D2.disc
print(x, ...)
# S3 method for D2.disc
predict(object, newdata = NULL, ...)

Arguments

data

a numeric data.frame or matrix (n x p).

grouping

a vector of length n containing the class of each observation (row) in data.

pooled.cov

a grouping-pooled covariance matrix (p x p). If NULL (default), D2.disc will automatically compute a pooled covariance matrix.

x, object

an object of class "D2.disc".

newdata

numeric data.frame or matrix of observations to be classified. If NULL (default), the input data used as argument in D2.disc will be used.

...

further arguments.

Value

A list of

call

the call which produced the result.

data

numeric matrix; the input data.

D2

a matrix containing the Mahalanobis distances between each row of data and the center of each class of grouping. In addition, the original and the predicted (lowest distance) class are displayed, as well as a chacater vector indicating where the misclassification has occured.

means

a matrix containing the vector of means of each class in grouping.

pooled

the pooled covariance matrix.

confusion.matrix

an object of class confusionmatrix.

References

Manly, B.F.J. (2004) Multivariate statistical methods: a primer. CRC Press. (p. 105-106).

Mahalanobis, P.C. (1936) On the generalized distance in statistics. Proceedings of The National Institute of Sciences of India, 12:49-55.

Author

Anderson Rodrigo da Silva <anderson.agro@hotmail.com>

See also

Examples

data(iris) (disc <- D2.disc(iris[, -5], iris[, 5]))
#> #> Call: #> D2.disc.default(data = iris[, -5], grouping = iris[, 5]) #> #> Mahalanobis distances from each class and class prediction (first 6 rows): #> setosa versicolor virginica grouping pred misclass #> 1 0.2910898 98.88475 191.7886 setosa setosa #> 2 2.0313451 80.97126 169.1870 setosa setosa #> 3 0.5532814 87.28938 177.0701 setosa setosa #> 4 2.0866979 75.29369 160.7244 setosa setosa #> 5 0.5956300 100.92317 193.8540 setosa setosa #> 6 1.9447533 95.93997 183.1140 setosa setosa #> #> Class means: #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> setosa 5.006 3.428 1.462 0.246 #> versicolor 5.936 2.770 4.260 1.326 #> virginica 6.588 2.974 5.552 2.026 #> #> Confusion matrix: #> new setosa new versicolor new virginica #> setosa 50 0 0 #> versicolor 0 48 2 #> virginica 0 1 49
first10 <- iris[1:10, -5] predict(disc, first10)
#> $class #> 1 2 3 4 5 6 7 8 9 10 #> setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa #> Levels: setosa versicolor virginica #> #> $D2 #> setosa versicolor virginica #> 1 0.2910898 98.88475 191.7886 #> 2 2.0313451 80.97126 169.1870 #> 3 0.5532814 87.28938 177.0701 #> 4 2.0866979 75.29369 160.7244 #> 5 0.5956300 100.92317 193.8540 #> 6 1.9447533 95.93997 183.1140 #> 7 1.3336882 84.01179 170.0569 #> 8 0.1174084 89.51039 179.5753 #> 9 3.8501173 71.64100 155.9269 #> 10 1.4419412 84.12304 174.4342 #>
predict(disc, iris[, -5])$class
#> [1] setosa setosa setosa setosa setosa setosa #> [7] setosa setosa setosa setosa setosa setosa #> [13] setosa setosa setosa setosa setosa setosa #> [19] setosa setosa setosa setosa setosa setosa #> [25] setosa setosa setosa setosa setosa setosa #> [31] setosa setosa setosa setosa setosa setosa #> [37] setosa setosa setosa setosa setosa setosa #> [43] setosa setosa setosa setosa setosa setosa #> [49] setosa setosa versicolor versicolor versicolor versicolor #> [55] versicolor versicolor versicolor versicolor versicolor versicolor #> [61] versicolor versicolor versicolor versicolor versicolor versicolor #> [67] versicolor versicolor versicolor versicolor virginica versicolor #> [73] versicolor versicolor versicolor versicolor versicolor versicolor #> [79] versicolor versicolor versicolor versicolor versicolor virginica #> [85] versicolor versicolor versicolor versicolor versicolor versicolor #> [91] versicolor versicolor versicolor versicolor versicolor versicolor #> [97] versicolor versicolor versicolor versicolor virginica virginica #> [103] virginica virginica virginica virginica virginica virginica #> [109] virginica virginica virginica virginica virginica virginica #> [115] virginica virginica virginica virginica virginica virginica #> [121] virginica virginica virginica virginica virginica virginica #> [127] virginica virginica virginica virginica virginica virginica #> [133] virginica versicolor virginica virginica virginica virginica #> [139] virginica virginica virginica virginica virginica virginica #> [145] virginica virginica virginica virginica virginica virginica #> Levels: setosa versicolor virginica
# End (not run)