Reputation: 747
I'm studying pattern recognition and statistics.I like to use direct functions in R rather than explicitly writing codes. My question is that in a three class 2-dimensional problem, my feature vectors for each class are normally distributed with covariance matrix
s <- matrix(c(1.2,0.4,0.4,8),nrow=2)
and mean vectors for each class are
m1 <- t(c(0.1, 0.1));m2 <- t(c(2.1, 1.9));m3 <- t(c(-1.5, 2.0))
Assuming that classes are equally probable, I want to classify the feature vector
x <- t(c(1.6,1.5))
according to the Bayes Minimum Error Probability Classifier which i did successfully and Now i want to draw the curves of Mahalanobis distance.
I tried with mahalanobis(x, center, cov, inverted = FALSE, ...)
function within {stats}
package. But i get confuse because i have already mean and var-cov matrix in my problem and mahalanobis()
function doesn't provide facility for my problem!or it does? i don't know!
Kindly anyone please guide me how to calculate Mahalanobis distance with reference to my problem in particular and to draw curves of Mahalanobis distance. Thanks in Advance!
A specimen of above problem is
Upvotes: 1
Views: 754
Reputation: 3194
I'm not sure exactly what you are looking for with curves, but with regard to using the mahalanobis function, simply put the mean and covariance matrix in as arguments.
dat <- iris[,-5]
mahal <- mahalanobis(x = dat, center = colMeans(dat), cov = cov(dat))
Upvotes: 0