[R] NMDS QUESTION

arun smartpink111 at yahoo.com
Sun Sep 1 17:34:09 CEST 2013



HI,
It is better to use ?dput() to show the reproducible example.  

dput(korma)
structure(list(T = c(0L, 0L, 1L, 1L, 0L, 1L), C = c(0L, 1L, 1L, 
0L, 0L, 0L), M = c(0L, 0L, 0L, 1L, 0L, 1L), B = c(1L, 0L, 1L, 
1L, 1L, 1L)), .Names = c("T", "C", "M", "B"), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6"))


korma<- 

structure(list(T = c(0L, 0L, 1L, 1L, 0L, 1L), C = c(0L, 1L, 1L, 
0L, 0L, 0L), M = c(0L, 0L, 0L, 1L, 0L, 1L), B = c(1L, 0L, 1L, 
1L, 1L, 1L)), .Names = c("T", "C", "M", "B"), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6"))
korma.dist<- dist(korma)

Assuming that ?isoMDS() is from library(MASS)

library(MASS)
isoMDS(korma.dist)
#Error in isoMDS(korma.dist) : 
 # zero or negative distance between objects 1 and 5

 korma.dist
         1        2        3        4        5
#2 1.414214                                    
#3 1.414214 1.414214                           
#4 1.414214 2.000000 1.414214                  
#5 0.000000 1.414214 1.414214 1.414214         
#6 1.414214 2.000000 1.414214 0.000000 1.414214 ###0 distance.

#changing some values with 0 distance to 

 korma.dist[4]<- 1.854
 korma.dist[14]<- 1.854




korma.MDS<- isoMDS(korma.dist) #works
#initial  value 21.518932 
#iter   5 value 15.443139
#iter  10 value 14.291766
#final  value 13.701871 #converged

So, it would be better to do:


korma.dist<- dist(unique(korma))
 korma.dist
#         1        2        3
#2 1.414214                  
#3 1.414214 1.414214         
#4 1.414214 2.000000 1.414214

korma.MDS<- isoMDS(korma.dist) #works
#initial  value 4.736717 
#iter   5 value 0.140638
#iter   5 value 0.000000
#iter   5 value 0.000000
#final  value 0.000000 
#converged
A.K.



_______________________________
From: Simona Augyte <simona.augyte at uconn.edu>
To: Berend Hasselman <bhh at xs4all.nl>; smartpink111 at yahoo.com 
Cc: r-help at r-project.org 
Sent: Sunday, September 1, 2013 9:34 AM
Subject: Re: [R] NMDS QUESTION



Ok, thanks, that helps. 

What about running the same code on a bit of a different set of data, ex.;
korma<- read.csv(text="
GR  TCMB
10001
20100
31101
41011
50001
61011...
",sep="",row.names=1,header=TRUE)


str(korma)
dist(korma)
korma.dist<- dist(korma)
 korma.mds <- isoMDS(korma.dist)
#Error in isoMDS(korma.dist) :   zero or negative distance between objects 1 and 5
# What do I need to do to my data to avoid the error message?





On Sun, Sep 1, 2013 at 3:03 AM, Berend Hasselman <bhh at xs4all.nl> wrote:


>On 01-09-2013, at 00:30, Simona Augyte <simona.augyte at uconn.edu> wrote:
>
>> I'm trying to run a very simple non-metric multidimensional scaling code on
>> a 8x5 character matrix.
>> gr T C M B
>> arcor 6 4 6 5
>> corfo 24 21 23 24
>> corma 25 15 26 17
>> crust 3 2 6 5
>> fil 15 12 15 15
>> fol 11 9 6 8
>> leat 10 11 13 13
>> seag 2 2 2 2
>>
>> My code is as follows;
>> coma<-read.csv("coma.csv",header=TRUE)
>> coma.x<-as.matrix(coma)
>> coma.dist <- dist(coma.x) # right here I get a warning message -> In
>> dist(coma.x) : NAs introduced by coercion
>>
>> WHAT DOES THAT MEAN??? the table has values and there are not NAs. Could
>> this be a by product of the way I inserted the data?
>>
>
>Yes.
>Your table contains characters and not numbers.
>
>Tell read.csv that the first column contains row names (assuming that that is indeed the case).
>
>coma<- read.csv(text="
>
>gr T C M B
>arcor 6 4 6 5
>corfo 24 21 23 24
>corma 25 15 26 17
>crust 3 2 6 5
>fil 15 12 15 15
>fol 11 9 6 8
>leat 10 11 13 13
>seag 2 2 2 2
>",sep="",row.names=1,header=TRUE)
>
>coma
>str(coma)
>dist(coma)
>
>Berend
>
>
>
>> Please help.
>>
>> --
>>
>> Simona Augyte, MS
>> PhD student
>> Ecology and Evolutionary Biology
>> University of Connecticut
>> cell 707-832-7007
>>
>
>>       [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>
>


-- 

Simona Augyte, MS
PhD student
Ecology and Evolutionary Biology
University of Connecticut
cell 707-832-7007



More information about the R-help mailing list