[R-sig-eco] using two distance metrices in formula

Jari Oksanen jari.oksanen at oulu.fi
Tue Oct 13 17:03:31 CEST 2009



On 13/10/2009 17:51, "Sarah Goslee" <sarah.goslee at gmail.com> wrote:

> Jens,
> 
> You can make your imported dissimilarities into a dist object quite easily.
> 
> Say D is your imported dissimilarity data. It needs to be in lower-triangular
> format (assuming you imported it as a symmetric square matrix).
> 
> D <- as.matrix(D)
> D <- D[col(D) < row(D)]
> attr(D, "Size") <- N # number of samples (# of rows and cols)
> attr(D, "Labels") <- 1:N # or names of samples, of length N
> attr(D, "Diag") <- FALSE
> attr(D, "Upper") <- FALSE
> attr(D, "method") <- "imported" # name of index, or NULL
> class(D) <- "dist"
> 
There is still easier way:

D <- as.dist(D), or
D <- as.dist(as.matrix(D))

which actually does exactly those things Sarah list above.


> On Tue, Oct 13, 2009 at 10:20 AM, Jens Oldeland <oldeland at gmx.de> wrote:
>> Dear R-sig-ecology group,
>> 
>> is there a way to use two self-made dissimilarity matrices for the left-hand
>> side (LHS) and right hand side (RHS) in vegan functions such as capscale or
>> adonis?
>> I created those matrices in a GIS using 3D-information therefore I don´t
>> want to simply use distances between 2D-coordinates. But as I found out,
>> there is only the possibility to use a dist object for LHS.
>> 
>> Can anyone suggest a solution or had similar problems?

However, vegan functions such as capscale or adonis do not accept
dissimilarities on both sides of the formula. The RHS always must be
rectangular data. There are some functions that take dist objects on both
sides, but they are less powerful, and in general, I wouldn't recommend
their use except in special situations (although they are available in
vegan). 

It is difficult to suggest a solution when we do not know what you want to
solve. Why would you want to have dissimilarities on both sides of the
formula? You can do that with, say, Mantel tests available in several
packages in R, but what are the things you want to solve by using
dissimilarities?

Cheers, Jari Oksanen



More information about the R-sig-ecology mailing list