mahalanobis_distance {OutliersLearn} | R Documentation |
mahalanobis_distance
Description
Calculates the mahalanobis_distance given the input data
Usage
mahalanobis_distance(value, sample_mean, sample_covariance_matrix)
Arguments
value |
Point to calculate the mahalanobis_distance |
sample_mean |
Sample mean |
sample_covariance_matrix |
Sample Covariance Matrix |
Value
Mahalanobis distance associated to the point
Author(s)
Andres Missiego Manjon
Examples
inputData = t(matrix(c(3,2,3.5,12,4.7,4.1,5.2,
4.9,7.1,6.1,6.2,5.2,14,5.3),2,7,dimnames=list(c("r","d"))));
inputData = data.frame(inputData);
inputData = as.matrix(inputData);
sampleMeans = c();
for(i in 1:ncol(inputData)){
column = inputData[,i];
calculatedMean = sum(column)/length(column);
print(sprintf("Calculated mean for column %d: %f", i, calculatedMean))
sampleMeans = c(sampleMeans, calculatedMean);
}
covariance_matrix = cov(inputData);
distance = mahalanobis_distance(inputData[3,], sampleMeans, covariance_matrix);
[Package OutliersLearn version 1.0.0 Index]