Description Usage Arguments Details Value Author(s) References Examples
compute weighted Mahalanobis distance between two samples
1 | wmahalanobis(x, center, cov, weight)
|
x |
vector or matrix of data with, say, p columns. |
center |
mean vector of the distribution or second data vector of length p |
cov |
covariance matrix (p x p) of the distribution |
weight |
the weight of the parameters |
the weight of parameters is defined by users;if you do not define the weight,the corresponding percent contributions of the parameters based on the principal component analysis scheme will be used instead
weighted Mahalanobis distance will be returned
Bingpei Wu
passage: "APPLICATION OF WEIGHTED MAHALANOBIS DISTANCE DISCRIMINANT ANALYSIS METHOD TO CLASSIFICATION OF ROCK MASS QUALITY",whose author is YAO Yinpei
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
x=iris[1:50,1:4]
center=colMeans(x)
cov=var(x)
weight=diag(rep(0.25,4))
wmahalanobis(x,center,cov,weight)
## The function is currently defined as
function (x, center, cov, weight)
{
if (is.vector(x))
x = matrix(x, ncol = length(x))
else x=as.matrix(x)
x <- sweep(x, 2, center)
cov <- weight %*% solve(cov)
retval <- diag(x %*% cov %*% t(x))
retval
}
|
1 2 3 4 5 6 7
0.11227845 0.52027354 0.32108378 0.42655174 0.19042135 0.92816184 0.85604903
8 9 10 11 12 13 14
0.08585981 0.74911912 0.80002148 0.47273815 0.50371984 0.73683328 1.76005248
15 16 17 18 19 20 21
2.55551925 1.91345081 1.43559218 0.15906369 1.29644367 0.40310318 1.33726468
22 23 24 25 26 27 28
0.68058880 2.76110699 1.80759383 2.43699346 0.94262760 0.63142180 0.20728231
29 30 31 32 33 34 35
0.33075371 0.54359893 0.49862653 1.22227788 1.92481960 1.31200598 0.31674524
36 37 38 39 40 41 42
0.82545609 1.43031746 0.77141225 0.81756152 0.14733683 0.42121179 3.08190967
43 44 45 46 47 48 49
1.05025964 3.07751443 2.15028994 0.54866294 0.68893557 0.37221693 0.31318194
50
0.12368898
function (x, center, cov, weight)
{
if (is.vector(x))
x = matrix(x, ncol = length(x))
else x = as.matrix(x)
x <- sweep(x, 2, center)
cov <- weight %*% solve(cov)
retval <- diag(x %*% cov %*% t(x))
retval
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.