[R] I cannot get species scores to plot with site scores in MDS when I use a distance matrix as input. Problems with NA's?

Edwin elebrija at hotmail.com
Thu Dec 1 12:15:41 CET 2011


Dear Gavin,
Thanks a lot for your reply. I am still not sure if your suggestion can help
me or not because I have got different types of errors while trying it. I
have tried my best to troubleshoot them and made some progress, but I have
reached a dead end (I don’t know how to go on). Below I am copping my TinnR
script. It contains not only the R script but also the errors returned in
the R console. I apologize that the script is still not really reproducible
but I just do not know how to create a sample data frame for it. Thanks
again for your help.  Edwin.
##Load required packages##
library(vegan)
library(MASS)
library (FD)
library(dummies)
##Load full table of species traits and taxonomic data##
AllTraits<-read.delim("SpeciesTraitsFullTbl.txt",header=T)
##Edit data##
row.names(AllTraits)<-AllTraits$species.code
TraitsNMDS<-AllTraits[,c(8:12,14:18,23,25,30)]
##Check variable class using function "allClass" from
http://gettinggeneticsdone.blogspot.com/2010   
/08/quickly-find-class-of-dataframe-vectors.html##
    allClass <- function(x) {unlist(lapply(unclass(x),class))} 
    allClass(TraitsNMDS)
##Change variables to fulfill requirements for gowdis() function##
  #Define ordinal variables#
      TraitsNMDS$leaf.type<-ordered(TraitsNMDS$leaf.type, levels =
c("simple", "pinnate", "bipinnate"))
      TraitsNMDS$dispersal.rank<-ordered(TraitsNMDS$dispersal.rank, levels =
c("s_disp","m_disp","l_disp"))
    #<coerce integer an binary variables to numeric# 
    TraitsNMDS$max.height<-as.numeric(TraitsNMDS$max.height)
    TraitsNMDS$heterospory<-as.numeric(TraitsNMDS$heterospory)
##Test wrapper function##
wrapper<- function(x, method, ...) {gowdis(x, ...)}
WrapTest1<-metaMDS(TraitsNMDS, distfun = wrapper, x=TraitsNMDS, asym.bin =
"heterospory", ord = "podani")
##Returned error: 'Error in if (any(autotransform, noshare > 0, wascores) &&
any(comm < 0)) { :   missing value where TRUE/FALSE needed'##
  #Set autotransform, noshare and wascores to FALSE (even if TRUE is
desired) to see if problems is with metaMDS function#
  WrapTest2<-metaMDS(TraitsNMDS, distfun = wrapper, x=TraitsNMDS, asym.bin =
"heterospory", ord= "podani", autotransform =FALSE, noshare = FALSE,
wascores = FALSE)
  #Returned error: 'Error in FUN(X[[1L]], ...) : only defined on a data
frame with all numeric variables'#
  #transform factors to dummies and numeric#
  TraitsNMDSCompleteDumm<-dummy.data.frame(TraitsNMDSComplete,
c("leaf.type","dispersal.rank"))
 
TraitsNMDSCompleteDumm$leaf.typesimple<-as.numeric(TraitsNMDSCompleteDumm$leaf.typesimple)
 
TraitsNMDSCompleteDumm$leaf.typepinnate<-as.numeric(TraitsNMDSCompleteDumm$leaf.typepinnate)
 
TraitsNMDSCompleteDumm$leaf.typebipinnate<-as.numeric(TraitsNMDSCompleteDumm$leaf.typebipinnate)
 
TraitsNMDSCompleteDumm$dispersal.ranks_disp<-as.numeric(TraitsNMDSCompleteDumm$dispersal.ranks_disp)
 
TraitsNMDSCompleteDumm$dispersal.rankm_disp<-as.numeric(TraitsNMDSCompleteDumm$dispersal.rankm_disp)
 
TraitsNMDSCompleteDumm$dispersal.rankl_disp<-as.numeric(TraitsNMDSCompleteDumm$dispersal.rankl_disp)
  
##Re-test wrapping function##
WrapTest3<-metaMDS(TraitsNMDSCompleteDumm, distfun = wrapper,
x=TraitsNMDSCompleteDumm,asym.bin =    "heterospory", ord = "podani")
  #The function runs but returns an error related to the gowdis() function
after the transformation of the data is done:  
  #'Square root transformation Wisconsin double standardization. Error in
gowdis(x, ...) : w needs to be a numeric vector of length = number of
variables in x'
 # But testing the wrapper alone does work!#
DistMatrixWrapper<-wrapper(x=TraitsNMDSCompleteDumm,asym.bin =
"heterospory", ord = "podani")
class(DistMatrixWrapper)
[1] "dist"
 # I do not know why the error is produced


--
View this message in context: http://r.789695.n4.nabble.com/I-cannot-get-species-scores-to-plot-with-site-scores-in-MDS-when-I-use-a-distance-matrix-as-input-Pr-tp4103699p4127949.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list