x <- cbind(1:6, 1:3)
xbar <- colMeans(x)
S <- matrix(c(1,4,4,1), ncol = 2) # is negative definite
D2 <- mahalanobis(x, center = xbar, S)
all(D2 >= 0) # several distances are negative
## next command produces the following error:
## Covariance matrix is possibly not positive-definite
if (FALSE) D2 <- Mahalanobis(x, center = xbar, S)
Run the code above in your browser using DataLab