Hello,
a proposed solution of Bill Venables is archieved on the S-News mailing
list:
http://www.biostat.wustl.edu/archives/html/s-news/2001-07/msg00035.html
and if I remember it correctly (and if the variance matrix is estimated
from the data), another similar way is simply to use the Euclidean
I think we now have a very good R function here.
Thanks for all Gabor!
JCFaria
Gabor Grothendieck wrote:
> This one adds the labels:
>
>
> D2Mah4 = function(y, x) {
>
> stopifnot(is.data.frame(y), !missing(x))
> stopifnot(dim(y)[1] != dim(x)[1])
> y= as.matrix(y)
> x= as.factor(x)
This one adds the labels:
D2Mah4 = function(y, x) {
stopifnot(is.data.frame(y), !missing(x))
stopifnot(dim(y)[1] != dim(x)[1])
y= as.matrix(y)
x= as.factor(x)
man = manova(y ~ x)
E= summary(man)$SS[2] #Matrix E
S= as.matrix(E$Residuals)/man$df.residual
InvS = solve(S)
m
Indeed, it is very nice Gabor (as always)!
So, a doubt: how to preserve the 'rowname' and 'colname' of D2, like in the
first function? I think it is useful to posterior analyzes (as cluster, for
example).
Regards,
# A small correction (reference to gtools was eliminated)
D2Mah2 = function(y, x
And here is one more simplification using the buildin mahalanobis
function:
D2Mah3 = function(y, x) {
stopifnot(is.data.frame(y), !missing(x))
stopifnot(dim(y)[1] != dim(x)[1])
y= as.matrix(y)
x= as.factor(x)
man = manova(y ~ x)
E= summary(man)$SS[2] #Matrix E
S= as.matrix
I think you could simplify this by replacing everything after the
nObjects = nrow(mds) line with just these two statements.
f <- function(a,b) mapply(function(a,b)
(mds[a,] - mds[b,])%*%InvS%*%(mds[a,] - mds[b,]), a,b)
D2 <- outer(seq(nObjects), seq(nObjects), f)
This also eliminates dep
Well, as I did not get a satisfactory reply to the original question I tried to
make a basic function that, I find, solve the question.
I think it is not the better function, but it is working.
So, perhaps it can be useful to other people.
#
# Calculate the matrix of Mahalanobis Distances betwe
Christian Hennig wrote:
> Dear Jose,
>
> normal mixture clustering (mclust) operates on points times variables data
> and not on a distance matrix. Therefore
> it doesn't make sense to compute Mahalanobis distances before using
> mclust.
> Furthermore, cluster analysis based on distance matrices
Dear Jose,
normal mixture clustering (mclust) operates on points times variables data
and not on a distance matrix. Therefore
it doesn't make sense to compute Mahalanobis distances before using
mclust.
Furthermore, cluster analysis based on distance matrices (hclust or pam,
say) operates on a poin
Dear R list,
I'm trying to calculate Mahalanobis distances for 'Species' of 'iris' data
as obtained below:
Squared Distance to Species From Species:
Setosa Versicolor Virginica
Setosa 0 89.86419 179.38471
Versicolor 89.86419 0 17.20107
Virginica 179.38471
10 matches
Mail list logo