[R] metaMDS using Dissimilarity matrix

Birgit Lemcke birgit.lemcke at systbot.uzh.ch
Thu May 15 14:50:06 CEST 2008


Sorry for not translating, misspackaging (MASS) and not reading  
properly (zerodist).

I would like to implement the weighting in distance()

	foo <- function(x, method, ...)
                 as.dist(distance(x = x, method = method,  
weights=vectorname))

This seems to work but it would be much more elegant if I could call  
the weighting in metaMDS.

Is that the right way:

	foo <- function(x, method,weights, ...)
                as.dist(distance(x = x, method = method,  
weights=weights))
		metaMDS(train, distance = "mixed", distfun = foo, weights=vectorname)

Thanks again for help.

Birgit



And again
Am 15.05.2008 um 13:41 schrieb Gavin Simpson:
> On Thu, 2008-05-15 at 13:13 +0200, Birgit Lemcke wrote:
>> Hello R-user community!
>>
>> I am running R 2.7.0 on a Power Book (Tiger). (I am still R and
>> statistics beginner)
>>
>> Presently I try to run the function metaMDS (vegan) using an existing
>> dissimilarity-matrix.
>
> The help for metaMDS explicitly says that you can't do this; that is
> what the error message says. (which would have been better if  
> translated
> into English so I didn't have to resort to reading the sources to see
> what the error meant).
>
>>
>> As I would like to start with this matrix I thought I could just give
>> the matrix using the x=  -argument
>>
>> 	Test<-metaMDS(x=Dist.Gower)
>> 	Fehler in inherits(comm, "dist") : Argument "comm" fehlt (ohne
>> Standardwert)
>>
>> But obviously that is not the way it works.
>
> It is not immediately obvious to the new user how to get this to work
> where the distance function is not vegdist. (Jari or I should possibly
> look to see if we can get metaMDS to work when a dissimilarity  
> matrix is
> present - although writing a simple wrapper that works is quite  
> easy, so
> maybe we just need an example?) This is compounded by the fact  
> that, by
> design, analogue:::distance returns the full dissimilarity matrix (I
> should look to rectify that!)
>
> A solution is the following wrapper:
>
> foo <- function(x, method, ...)
>                 as.dist(distance(x = x, method = method))
>
> which creates a new local wrapper to distance that includes an  
> explicit
> call to as.dist().
>
> We then call metaMDS like so, using the simple example dataset 'train'
> from ?distance:
>
> train <- data.frame(matrix(abs(runif(200)), ncol = 10))
> rownames(train) <- LETTERS[1:20]
> colnames(train) <- as.character(1:10)
> metaMDS(train, distance = "mixed", distfun = foo)
>
> So you see it works now.
>
>>
>> The second problem is that it seems that I have zero distance value
>> between some objects what causes a problem in isoMDS (vegan)
>>
>> 	Test<-isoMDS(Dist.GowerTest) Fehler in isoMDS(Dist.GowerTest)
>> 	 : zero or negative distance between objects 240 and 241
>
> isoMDS is in package MASS, *not* vegan (credit where credit is due!)
>
> metaMDSdist contains argument 'zerodist' to handle this situation. If
> you do zerodist = "add", a small amount will be added to 0
> dissimilarities. metaMDS passes arguments to metaMDSdist so you could
> do:
>
> metaMDS(train, distance = "mixed", distfun = foo, zerodist = "add")
>
> Although be careful to understand the implications of doing this!
>
> HTH
>
> G
>
>>
>>
>> Sorry might be that I am just to stupid to understand the
>> documentation, but could somebody help me anyway.
>>
>> Thanks in advance
>>
>> B.
>>
>>
>> Birgit Lemcke
>> Institut für Systematische Botanik
>> Zollikerstrasse 107
>> CH-8008 Zürich
>> Switzerland
>> Ph: +41 (0)44 634 8351
>> birgit.lemcke at systbot.uzh.ch
>>
>> 175 Jahre UZH
>> «staunen.erleben.begreifen. Naturwissenschaft zum Anfassen.»
>> MNF-Jubiläumsevent für gross und klein.
>> 19. April 2008, 10.00 Uhr bis 02.00 Uhr
>> Campus Irchel, Winterthurerstrasse 190, 8057 Zürich
>> Weitere Informationen http://www.175jahre.uzh.ch/naturwissenschaft
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting- 
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> -- 
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>  Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
>  ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
>  Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
>  Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
>  UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>

Birgit Lemcke
Institut für Systematische Botanik
Zollikerstrasse 107
CH-8008 Zürich
Switzerland
Ph: +41 (0)44 634 8351
birgit.lemcke at systbot.uzh.ch

175 Jahre UZH
«staunen.erleben.begreifen. Naturwissenschaft zum Anfassen.»
MNF-Jubiläumsevent für gross und klein.
19. April 2008, 10.00 Uhr bis 02.00 Uhr
Campus Irchel, Winterthurerstrasse 190, 8057 Zürich
Weitere Informationen http://www.175jahre.uzh.ch/naturwissenschaft



More information about the R-help mailing list