[R] Error on distance matrix

Jari Oksanen jari.oksanen at oulu.fi
Thu Jan 10 15:06:42 CET 2008


Jari Oksanen <jari.oksanen <at> oulu.fi> writes:

> 
> Marc Moragues <Marc.Moragues <at> scri.ac.uk> writes:
> 
> > 
> > Hi,
> > 
> > I am trying to calculate a distance matrix on a binary data frame using
> > dist.binary() {ade4}. This is the code I run and the error I get:
> > 
> > > sjlc.dist <- dist.binary(as.data.frame(data), method=2) #D = (a+d) /
> > (a+b+c+d)
> > Error in if (any(df < 0)) stop("non negative value expected in df") :
> >  missing value where TRUE/FALSE needed
> > 
> > I don't know if the problem are the missing values in my data. If so how
> > can I handle them?
> > 
> Dear Marc Moragues,
> 
> At least adding NA to a data.frame gave the same error message as you report
> above. Odds are good for NA being responsible (but we cannot know: we only
> guess). 
...clip...
> One solution is to use function designdist in vegan where you can with some
> acrobary design your own dissimilarity indices. 

It is a bad habit to comment on yourself, but if you write stupid things, you
should tell so: that designdist() "handles" missing values is accidental,
unintentional and dangerous. Now you still should figure out *how* they are
handled, and the function should warn users if they supply data with missing
values. I hope that will be changed. 

>Function designdist uses
> different notations, because its author hates that misleading and dangerous 2x2
> contingency table notation. The following, however, seems to define the same
> index as ade4:
> 
> designdist(data, "sqrt(1-(2*J+P-A-B)/P)")
> 
You can make this cuter:

designdist(data, "sqrt((A+B-2*J)/P)")

Cheers, Jari Oksanen




More information about the R-help mailing list