Skip to content

distance coefficient for amatrix with ngative valus

3 messages · R. Michael Weylandt, Rolf Turner

#
Comments inline:

On Mon, Oct 3, 2011 at 11:27 PM, dilshan benaragama
<benaragamad at yahoo.com> wrote:
No, you did not state your problem. I have replied to everything you
have actually included to this point. Admittedly, I have failed to
reply to things you did not say...
This is now the 7th email in this chain. You should mention the
packages and functions you are using in the FIRST email of the chain.
This is mentioned in the posting guide which you apparently have still
not yet read.
They all work for any data I put in. This is perhaps when that minimal
working example, which you also should have included, is necessary.
The append at the end of each of the 7 emails in this chain that tells
you to read the posting guide also asks for this, as did I explicitly.
No, they each give warnings. Warnings are not errors. They are
warnings and they say "warning". Perhaps unsurprisingly, errors say
"error". If you are using an old version of vegan that throws an
error, you should always update before seeking help.Not surprisingly,
a certain document suggests this.
Actually read the warning message: it warns you that you have given
negative data to an ecological function and suggests this might be a
point you look into as this usually suggests a user-end problem. It
does not fail to work in any sense of the word as evidence by the
output of distances. If  negative data is nonsense, you should heed
this warning; if you know its not, disregard it.

More importantly, as I said in my initial response, any distance
metric worth its salt is translation invariant. To wit,

x <- matrix(rnorm(50),5)

d1 = vegdist(x, method="gower")
d2 = vegdist(x + abs(min(x))*3, method="gower")

all.equal(as.numeric(d1), as.numeric(d2))
TRUE

In fairness, I'll admit this does not seem to work for the bray
distance. I am not an ecologist and I do not know why this would be --
it does leave me somewhat confused as to what sort of space motivates
the bray metric, but that's a discussion for another time and place --
but the function still returns a valid dist object for both d1 and d2.
You will note that I include the r-help list on each email on this
chain while you have not; this is mentioned in the posting guide.
Would you care to elaborate further as to what the actual problem
entails, with a minimal working example?

More generally, might I suggest you learn how these metrics work and
then apply the most appropriate one rather than groping blindly after
something solely on the criterion of it being non-Euclidean. If you
need other metrics, look into the various p-norms, all of which are
implemented directly in R by way of the dist() function as are a few
other norms with which I am not immediately familiar.

Regards,

Michael Weylandt
#
On 04/10/11 17:05, R. Michael Weylandt wrote:
<SNIP>
<SNIP>

Point of order, Mr. Chairman.  (This is really *toadally* off topic;
my apologies, but I couldn't resist --- I trained as a pure mathematician).

A *metric* need not in general be translation invariant.  Indeed a metric
need not be defined on a space in which translation makes any sense.

A metric defined in terms of a *norm* (on a normed vector space)  by
rho(x,y) = ||x - y|| is of course by definition translation invariant, 
and that's
what most of us think in terms of.

But there are perfectly ``reasonable''  metrics, defined on vector spaces,
which are not translation invariant.  Whether these are ``worth their salt''
is I suppose a matter of taste.  (You should pardon the expression. :-) )

A simple e.g. of a non-translation-invariant metric is

     rho(x,y) = |x - y|/(1 + |x| + |y|)

(defined on the real line).  It is easily checked that rho(.,.) 
satisfies the
four conditions that a metric must satisfy.  (Exercise for the interested
reader.)

Note that rho(1,2) = 1/4  but rho(2,3) = 1/6, ergo not translation 
invariant.

     cheers,

         Rolf Turner
#
You are, of course, entirely correct and, once again, I tip my hat to
the erudition of those who comment on this list. My initial
formulation, for a distance on a normed space inherited from the norm,
stands trivially, but as you rightly point out, I'm excluding many
interesting and possibly useful norms.

Follies of youth and all that....

Michael
On Tue, Oct 4, 2011 at 2:06 AM, Rolf Turner <rolf.turner at xtra.co.nz> wrote: