Re: [R] metaMDS in vegan: zero stress
Mia Bengtsson gmail.com> writes: > > Dear R and vegan package users, > > I have been experiencing problems with the metaMDS function when working on a dataset (euk) consisting of 9 > "sites" (RNA extracts of 9 biofilms samples) and 340 "species" (microbial taxa based on rRNA sequences). > The problem is that I get nMDS ordinations with overlapping points, so that it looks like 6 samples are > identical, while the remaining 3 are well separated. The dataset is rather large, and quite complex so I do > not think that this is a correct representation of dissimilarities. Every time this happens, I get the > warning message: > > "In metaMDS(t(euk_red), distance = "bray") : > Stress is (nearly) zero - you may have insufficient data" > > Removing relatively rare species using: > > euk_red<-euk[rowSums(euk)>100,] Nine (9) points is not a "rather large" data set, but it is very small. You have 9*8/2 = 36 pairwise dissimilarities among your nine points, and you try to estimate 2*9 = 18 coordinates in mononotonic regression. No wonder you get a warning of insufficient data. You may use vegan::stressplot() function to inspect the result and see how it fails. My guess is that your three points are well separated from others, and probably have some disjunction with microbial taxa that do not occur in the rest. I suggest you do not use nonmetric MDS with nine (9) points. It may be that metric scaling (cmdscale in R or wcmdscale in vegan) works better. Cheers, Jari Oksanen __ R-help@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.
[R] metaMDS in vegan: zero stress
Dear R and vegan package users, I have been experiencing problems with the metaMDS function when working on a dataset (euk) consisting of 9 "sites" (RNA extracts of 9 biofilms samples) and 340 "species" (microbial taxa based on rRNA sequences). The problem is that I get nMDS ordinations with overlapping points, so that it looks like 6 samples are identical, while the remaining 3 are well separated. The dataset is rather large, and quite complex so I do not think that this is a correct representation of dissimilarities. Every time this happens, I get the warning message: "In metaMDS(t(euk_red), distance = "bray") : Stress is (nearly) zero - you may have insufficient data" Removing relatively rare species using: euk_red<-euk[rowSums(euk)>100,] results in an nMDS ordination with scattered points that looks more reasonable. However, removing even more rare species (<1000) results in a different, but similarly uncomplex ordination and the same warning message. Changing the distance metric to euclidean seems even more sensitive to this problem, yielding uncomplex ordinations with almost any rare species cutoff. The code I am using is: euk_MDS<-metaMDS(t(euk_red), distance="bray") ordiplot(euk_MDS, display="sites") I have tried the arguments engine=isoMDS, and changing maxit and trymax without noticeable effect. Generating the distance matrices separately in vegdist yields distance matrices that look normal to my eye. It seems like a similar problem to a recent thread in the R-help (Fabian Boetzl, Feb 2014), but my dataset has many species that are shared between all sites. I would be happy to provide the dataset if this may help in figuring out what the problem is. I am using R version 3.1.0 for MacOS, coupled to R-studio (version 0.98.510). Thanks in advance and best regards! Mia M. Bengtsson, University of Vienna [[alternative HTML version deleted]] __ R-help@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.
[R] metaMDS Error, Nan similar or negative values
H ello R-experts, I want to do ordination plots using vegan metaMDS. I have a where many cells have zero values. Data structure: X[1:10,1:14] Height.1 Height.2 Height.3 Height.4 Height.5 Height.6 Height.7 Height.8 Height.9 Height.10 Height.11 Height.12 Height.13 D30I1A 46000000 00 039 098 D30I1B 46000000 00 039 098 D30I1C 70000000 00 0 085 0 D30I2A 47000000 00 049 0 105 D30I2B 68000000 00 083 0 214 D30I2C0 7500000 00 0 083 0 D30I3A 48000000 00 042 0 107 D30I3B 64000000 00 072 0 177 D30I3C 72000000 00 0 096 0 D30M1A 60000000 00 074 0 169 When I tried to perform metaMDS, it was not working, with the error > ord1 <- metaMDS( X ="bray") Square root transformation Wisconsin double standardization Error in if (any(dist < -sqrt(.Machine$double.eps))) warning("some dissimilarities are negative -- is this intentional?") : missing value where TRUE/FALSE needed In addition: Warning messages: 1: In distfun(comm, method = distance, ...) : you have empty rows: their dissimilarities may be meaningless in method bray 2: In distfun(comm, method = distance, ...) : missing values in results I realised some of the values are either zero or similar. I tried to check it with distance X .dist <- metaMDSdist( X , method="bray") got the error: Square root transformation Wisconsin double standardization Error in distfun(comm, method = distance, ...) : formal argument "method" matched by multiple actual arguments When I checked the distance I see some of the distances are NaN as for example some rows of dist matrix: D3M1A NaN 1.0 1.0 1.0 1.0 1.0 NaN 1.0 1.0 NaN D3R1A NaN 1.0 1.0 1.0 1.0 1.0 NaN 1.0 1.0 NaN I searched all the details of metaMDS where it is suggested to avail the argument 'zerodist' So I tried both X.dist1 <- metaMDSdist(X, method="bray",zerodist = "ignore") X.dist2 <- metaMDSdist(X, method="bray",zerodist = "add") But for both the cases I still have those NaN values in some distances. I have read, one of the discussion says modify zero dissimilarities as: If there is a good reason, and you want to include all samples, then you'll need to come up with a means for handling them. metaMDSdist allow you to add a small value to the zero dissimilarities. The details are in the code, but effectively all zero distances are replaced by half the smallest non zero distance. You could do a similar replacement yourself if you feel this is warranted and/or justified. minDij <- min(Dij[Dij > 0) / 2 Dij[Dij <= 0] <- minDij But still I don't understand how can I modify the NaN values. In my data I don't have any NA values. All the cells are either +ve or zero. Please help me with this. Should I just replace all the NaN values with zero? Please advice. Thanks a lot, Mitra [[alternative HTML version deleted]] __ R-help@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.
Re: [R] metaMDS with large dataset produces 'insufficient data' warning
Raeanne Miller sams.ac.uk> writes: > > Greetings everyone, > > I am running MDS on a very large dataset (12 x 25071 - 12 model runs with 25071 output values each), and also on a > very much reduced version of the dataset (randomly select 1000 of the 25071 output values). I would like to > look at similarities/dissimilarities between the 12 model runs. When I use metaMDS on the full dataset, I > get a warning message: > > Warning message: > In metaMDS(MDSdata, distance = "bray", k = 2, autotransform = FALSE) : > Stress is (nearly) zero - you may have insufficient data > > I don't think I have insufficient data, with 12 x 25071 data points, and when I reduce the dataset to only 1000 > values per model run (so only 12 x 1000) I don't get this warning (though the final stress is now only just > below 0.2 - my desired value). > > Is this warning because I have insufficient data? Or is it because of the nature of a large dataset? > Twelve points is not a large data set, but pretty small. Or that depends on how to interpret your message. It is the number of points that defines the data set size -- columns do not count. Further, it is a warning to alert you on possible problems. Everything may be OK, but you should have a look at the results. If it really is so that reducing the number of variables from 25071 to 1000 changes the results so that stress increases from 0 to 0.2, then you probably managed to remove some very influential variables from your data. It may be that there are only some few dominant variables that mostly define the dissimilarities and these give such a simple data structure that you get the warning when they are included. With default options, you get zero stress with six points, so that you should be on the safe side. Probably it is something funny in your data. Cheers, Jari Oksanen on possible problems. It is up to you see if there are problems or not. __ R-help@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.
[R] metaMDS with large dataset produces 'insufficient data' warning
Greetings everyone, I am running MDS on a very large dataset (12 x 25071 - 12 model runs with 25071 output values each), and also on a very much reduced version of the dataset (randomly select 1000 of the 25071 output values). I would like to look at similarities/dissimilarities between the 12 model runs. When I use metaMDS on the full dataset, I get a warning message: Warning message: In metaMDS(MDSdata, distance = "bray", k = 2, autotransform = FALSE) : Stress is (nearly) zero - you may have insufficient data I don't think I have insufficient data, with 12 x 25071 data points, and when I reduce the dataset to only 1000 values per model run (so only 12 x 1000) I don't get this warning (though the final stress is now only just below 0.2 - my desired value). Is this warning because I have insufficient data? Or is it because of the nature of a large dataset? I can supply a dataset in .txt format by email, if that would be helpful. Thanks for your help, Raeanne The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206). SAMS has an actively trading wholly owned subsidiary company: SAMS Research Services Ltd a Limited Company (SC224404). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA. The content of this message may contain personal views which are not the views of SAMS unless specifically stated. Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] metaMDS
On Fri, 2011-09-23 at 12:43 -0500, Jean V Adams wrote: > Lineth Contreras wrote on 09/23/2011 11:35:10 AM: > > > > Hello R-user community, > > > > I am applying the function metaMDS. However, I would like to know if > there > > is any option to export the data I got from the axis as a data frame. > > > > I have tried as.data.frame.list but is not working. Any suggestion? > > > > Thank you in advance for your help, > > > > Lineth > > > When you say "the data I got from the axis" do you mean the coordinates > contained in the $points of the resulting object? If so, something like > this should work (using the example provide in ?metaMDS): You would be better off with the scores() method for metaMDS objects: data(dune) sol <- metaMDS(dune) scrs <- scores(sol) `scrs` is a matrix: > class(scrs) [1] "matrix" which can be exported via say `write.csv()`: write.csv(scrs, "filenames.csv") If you want a data frame in R, then SCRS <- as.data.frame(scrs) will work, but there is little reason to convert to a data frame just to export it out of R. HTH G > data(dune) > library(MASS) > sol <- metaMDS(dune) > df <- as.data.frame(sol$points) > > Jean > [[alternative HTML version deleted]] > > __ > R-help@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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@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.
Re: [R] metaMDS
Lineth Contreras wrote on 09/23/2011 11:35:10 AM: > > Hello R-user community, > > I am applying the function metaMDS. However, I would like to know if there > is any option to export the data I got from the axis as a data frame. > > I have tried as.data.frame.list but is not working. Any suggestion? > > Thank you in advance for your help, > > Lineth When you say "the data I got from the axis" do you mean the coordinates contained in the $points of the resulting object? If so, something like this should work (using the example provide in ?metaMDS): data(dune) library(MASS) sol <- metaMDS(dune) df <- as.data.frame(sol$points) Jean [[alternative HTML version deleted]] __ R-help@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.
[R] metaMDS
Hello R-user community, I am applying the function metaMDS. However, I would like to know if there is any option to export the data I got from the axis as a data frame. I have tried as.data.frame.list but is not working. Any suggestion? Thank you in advance for your help, Lineth [[alternative HTML version deleted]] __ R-help@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.
Re: [R] metaMDS and envfit: Help reading output
Hi Katie, This is probably a bit late given the date of your post, but I was having similar problems with my own work and thought I'd respond anyway. I'm not sure that the script you've written here will fit 3D vectors for your 3D nmds. I tried it and it doesn't seem to work for me - it only gives 2D for the vectors. I found this: nmds3d <- metaMDS(varespec, k = 3, distance = 'bray', autotransform = FALSE) # run nmds with 3 dimensions nmds3d$stress# stress drops fit3d <- envfit(nmds3d, varechem[ ,1:4], choices = 1:3) # fit environmental vectors to 3d space ordirgl(nmds3d, envfit = fit3d) # dynamic 3D graph at http://en.wikibooks.org/wiki/R_Programming/Ordination ordirgl (in package rgl) gives a very nifty interactive 3d plot, or ordiplot3d is a static version. I hope this is useful. Kind regards, Briony -- View this message in context: http://r.789695.n4.nabble.com/metaMDS-and-envfit-Help-reading-output-tp3513052p3798043.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] metaMDS and envfit: Help reading output
On Wed, 2011-05-11 at 07:07 -0400, Michael Denslow wrote: > Hi Katie, > > On Tue, May 10, 2011 at 4:51 PM, Songer, Katherine B - DNR > wrote: > > Hello R experts, > > > > I've used metaMDS to run NMDS on some fish abundance data, and am also > > working on correlating environmental data to the NMDS coordinates. I'm > > fairly new to metaMDS and NMDS in general, so I have what are probably some > > very basic questions. My fish abundance data consists of 66 sites for which > > up to 20 species of fish were identified and counted. I ran metaMDS on this > > data in 3 dimensions (after using a scree plot to check for stress levels > > in the different dimensions). I then used envfit to correlate a predictor > > dataset of environmental variables with the NMDS results, using the > > following code. > > > >>Fish<-as.data.frame(read.csv("Fish.csv",header=TRUE, sep = ",")) > >>Fish.mds<-metaMDS(Fish,zerodist = "add",k=3,trymax=20) > > > >>Predictors<-as.data.frame(read.csv("Predictors.csv",header=TRUE, sep = ",")) > >>Fish.fit <- envfit(Fish.mds$points, Predictors, k=3, 1000, na.rm = TRUE) > > Have a look at the choices argument in envfit, etc. This is how you > specify which axes you want to plot. > > ord <- metaMDS(varespec, k=3) > fit <- envfit(ord, varechem, > perm = 999, choices=c(1:3)) Indeed, this is an essential step because we probably shouldn't interpret the "axes" of nMDS as separate components a la PCA/CA... > fit > plot(ord, choices=c(1,3)) > plot(fit, choices=c(1,3)) ...as such, a 3-d plot might be better (for some definition of "better"). See ?ordirgl G > >>Fish.fit > > > > The output of Fish.fit was as follows (table truncated): > > > >Dim1Dim2r2 Pr(>r) > > DrainArea -0.5923233 -0.8057004 0.7674 0.000999 *** > > Flow-0.5283236 -0.8490431 0.7847 0.000999 *** > > StrmWidth -0.6993457 -0.7147836 0.6759 0.000999 *** > > Gradient0.4541225 0.8909392 0.2085 0.010989 * > > > > I'd like to better understand how to read this table. I understand that > > Dim1 and Dim2 refer to the dimensions of the vectors produced by envfit, > > and r2 is the r-squared of those vectors. But how do I visualize these > > vectors in a 3-d plot? To which of the 3 NMDS dimensions are these vectors > > being correlated? Is there code to produce the x, y, and z coordinates of > > each of the sites in Fish.mds? > > > > Thanks very much. > > Katie > > > > > >[[alternative HTML version deleted]] > > > > __ > > R-help@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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@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.
Re: [R] metaMDS and envfit: Help reading output
Thank you Michael; this was helpful! Katie -Original Message- From: Michael Denslow [mailto:michael.dens...@gmail.com] Sent: Wednesday, May 11, 2011 06:07 AM To: Songer, Katherine B - DNR Cc: r-help@r-project.org Subject: Re: [R] metaMDS and envfit: Help reading output Hi Katie, On Tue, May 10, 2011 at 4:51 PM, Songer, Katherine B - DNR wrote: > Hello R experts, > > I've used metaMDS to run NMDS on some fish abundance data, and am also > working on correlating environmental data to the NMDS coordinates. I'm fairly > new to metaMDS and NMDS in general, so I have what are probably some very > basic questions. My fish abundance data consists of 66 sites for which up to > 20 species of fish were identified and counted. I ran metaMDS on this data in > 3 dimensions (after using a scree plot to check for stress levels in the > different dimensions). I then used envfit to correlate a predictor dataset of > environmental variables with the NMDS results, using the following code. > >>Fish<-as.data.frame(read.csv("Fish.csv",header=TRUE, sep = ",")) >>Fish.mds<-metaMDS(Fish,zerodist = "add",k=3,trymax=20) > >>Predictors<-as.data.frame(read.csv("Predictors.csv",header=TRUE, sep = >>",")) Fish.fit <- envfit(Fish.mds$points, Predictors, k=3, 1000, na.rm >>= TRUE) Have a look at the choices argument in envfit, etc. This is how you specify which axes you want to plot. ord <- metaMDS(varespec, k=3) fit <- envfit(ord, varechem, perm = 999, choices=c(1:3)) fit plot(ord, choices=c(1,3)) plot(fit, choices=c(1,3)) >>Fish.fit > > The output of Fish.fit was as follows (table truncated): > > Dim1 Dim2 r2 Pr(>r) > DrainArea -0.5923233 -0.8057004 0.7674 0.000999 *** > Flow -0.5283236 -0.8490431 0.7847 0.000999 *** > StrmWidth -0.6993457 -0.7147836 0.6759 0.000999 *** > Gradient 0.4541225 0.8909392 0.2085 0.010989 * > > I'd like to better understand how to read this table. I understand that Dim1 > and Dim2 refer to the dimensions of the vectors produced by envfit, and r2 is > the r-squared of those vectors. But how do I visualize these vectors in a 3-d > plot? To which of the 3 NMDS dimensions are these vectors being correlated? > Is there code to produce the x, y, and z coordinates of each of the sites in > Fish.mds? > > Thanks very much. > Katie > > > [[alternative HTML version deleted]] > > __ > R-help@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. > -- Michael Denslow I.W. Carpenter Jr. Herbarium [BOON] Department of Biology Appalachian State University Boone, North Carolina U.S.A. -- AND -- Communications Manager Southeast Regional Network of Expertise and Collections sernec.org 36.214177, -81.681480 +/- 3103 meters __ R-help@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.
Re: [R] metaMDS and envfit: Help reading output
Scott, Thanks very much! That thread was especially helpful. Katie P Katie Songer Water Resources Management Specialist Wisconsin Department of Natural Resources (*) phone: (608)264-8947 (*) e-mail: katherine.son...@wisconsin.gov From: Scott Chamberlain [mailto:scttchamberla...@gmail.com] Sent: Tuesday, May 10, 2011 05:56 PM To: Songer, Katherine B - DNR Cc: r-help@r-project.org Subject: Re: [R] metaMDS and envfit: Help reading output Here is a thread I found on this issue:http://www.mail-archive.com/r-sig-ecology@r-project.org/msg00755.html It's not a simple correlation apparently, but I can't figure out how they get the output from envfit using lm(Y ~ scores1 + scores2). You can plot the data like: library(MASS); require(vegan) data(varespec) data(varechem) ord <- metaMDS(varespec) fit <- envfit(ord, varechem) plot(ord) plot(fit) <http://www.mail-archive.com/r-sig-ecology@r-project.org/msg00755.html> On Tuesday, May 10, 2011 at 3:51 PM, Songer, Katherine B - DNR wrote: Hello R experts, I've used metaMDS to run NMDS on some fish abundance data, and am also working on correlating environmental data to the NMDS coordinates. I'm fairly new to metaMDS and NMDS in general, so I have what are probably some very basic questions. My fish abundance data consists of 66 sites for which up to 20 species of fish were identified and counted. I ran metaMDS on this data in 3 dimensions (after using a scree plot to check for stress levels in the different dimensions). I then used envfit to correlate a predictor dataset of environmental variables with the NMDS results, using the following code. Fish<-as.data.frame(read.csv("Fish.csv",header=TRUE, sep = ",")) Fish.mds<-metaMDS(Fish,zerodist = "add",k=3,trymax=20) Predictors<-as.data.frame(read.csv("Predictors.csv",header=TRUE, sep = ",")) Fish.fit <- envfit(Fish.mds$points, Predictors, k=3, 1000, na.rm = TRUE) Fish.fit The output of Fish.fit was as follows (table truncated): Dim1 Dim2 r2 Pr(>r) DrainArea -0.5923233 -0.8057004 0.7674 0.000999 *** Flow -0.5283236 -0.8490431 0.7847 0.000999 *** StrmWidth -0.6993457 -0.7147836 0.6759 0.000999 *** Gradient 0.4541225 0.8909392 0.2085 0.010989 * I'd like to better understaand how to read this table. I understand that Dim1 and Dim2 refer to the dimensions of the vectors produced by envfit, and r2 is the r-squared of those vectors. But how do I visualize these vectors in a 3-d plot? To which of the 3 NMDS dimensions are these vectors being correlated? Is there code to produce the x, y, and z coordinates of each of the sites in Fish.mds? Thanks very much. Katie [[alternative HTML version deleted]] __ R-help@r-project.org<mailto:R-help@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. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] metaMDS and envfit: Help reading output
Hi Katie, On Tue, May 10, 2011 at 4:51 PM, Songer, Katherine B - DNR wrote: > Hello R experts, > > I've used metaMDS to run NMDS on some fish abundance data, and am also > working on correlating environmental data to the NMDS coordinates. I'm fairly > new to metaMDS and NMDS in general, so I have what are probably some very > basic questions. My fish abundance data consists of 66 sites for which up to > 20 species of fish were identified and counted. I ran metaMDS on this data in > 3 dimensions (after using a scree plot to check for stress levels in the > different dimensions). I then used envfit to correlate a predictor dataset of > environmental variables with the NMDS results, using the following code. > >>Fish<-as.data.frame(read.csv("Fish.csv",header=TRUE, sep = ",")) >>Fish.mds<-metaMDS(Fish,zerodist = "add",k=3,trymax=20) > >>Predictors<-as.data.frame(read.csv("Predictors.csv",header=TRUE, sep = ",")) >>Fish.fit <- envfit(Fish.mds$points, Predictors, k=3, 1000, na.rm = TRUE) Have a look at the choices argument in envfit, etc. This is how you specify which axes you want to plot. ord <- metaMDS(varespec, k=3) fit <- envfit(ord, varechem, perm = 999, choices=c(1:3)) fit plot(ord, choices=c(1,3)) plot(fit, choices=c(1,3)) >>Fish.fit > > The output of Fish.fit was as follows (table truncated): > > Dim1 Dim2 r2 Pr(>r) > DrainArea -0.5923233 -0.8057004 0.7674 0.000999 *** > Flow -0.5283236 -0.8490431 0.7847 0.000999 *** > StrmWidth -0.6993457 -0.7147836 0.6759 0.000999 *** > Gradient 0.4541225 0.8909392 0.2085 0.010989 * > > I'd like to better understand how to read this table. I understand that Dim1 > and Dim2 refer to the dimensions of the vectors produced by envfit, and r2 is > the r-squared of those vectors. But how do I visualize these vectors in a 3-d > plot? To which of the 3 NMDS dimensions are these vectors being correlated? > Is there code to produce the x, y, and z coordinates of each of the sites in > Fish.mds? > > Thanks very much. > Katie > > > [[alternative HTML version deleted]] > > __ > R-help@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. > -- Michael Denslow I.W. Carpenter Jr. Herbarium [BOON] Department of Biology Appalachian State University Boone, North Carolina U.S.A. -- AND -- Communications Manager Southeast Regional Network of Expertise and Collections sernec.org 36.214177, -81.681480 +/- 3103 meters __ R-help@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.
Re: [R] metaMDS and envfit: Help reading output
Here is a thread I found on this issue:http://www.mail-archive.com/r-sig-ecology@r-project.org/msg00755.html It's not a simple correlation apparently, but I can't figure out how they get the output from envfit using lm(Y ~ scores1 + scores2). You can plot the data like: library(MASS); require(vegan) data(varespec) data(varechem) ord <- metaMDS(varespec) fit <- envfit(ord, varechem) plot(ord) plot(fit) On Tuesday, May 10, 2011 at 3:51 PM, Songer, Katherine B - DNR wrote: > Hello R experts, > > I've used metaMDS to run NMDS on some fish abundance data, and am also > working on correlating environmental data to the NMDS coordinates. I'm fairly > new to metaMDS and NMDS in general, so I have what are probably some very > basic questions. My fish abundance data consists of 66 sites for which up to > 20 species of fish were identified and counted. I ran metaMDS on this data in > 3 dimensions (after using a scree plot to check for stress levels in the > different dimensions). I then used envfit to correlate a predictor dataset of > environmental variables with the NMDS results, using the following code. > > > Fish<-as.data.frame(read.csv("Fish.csv",header=TRUE, sep = ",")) > > Fish.mds<-metaMDS(Fish,zerodist = "add",k=3,trymax=20) > > > Predictors<-as.data.frame(read.csv("Predictors.csv",header=TRUE, sep = ",")) > > Fish.fit <- envfit(Fish.mds$points, Predictors, k=3, 1000, na.rm = TRUE) > > Fish.fit > > The output of Fish.fit was as follows (table truncated): > > Dim1 Dim2 r2 Pr(>r) > DrainArea -0.5923233 -0.8057004 0.7674 0.000999 *** > Flow -0.5283236 -0.8490431 0.7847 0.000999 *** > StrmWidth -0.6993457 -0.7147836 0.6759 0.000999 *** > Gradient 0.4541225 0.8909392 0.2085 0.010989 * > > I'd like to better understand how to read this table. I understand that Dim1 > and Dim2 refer to the dimensions of the vectors produced by envfit, and r2 is > the r-squared of those vectors. But how do I visualize these vectors in a 3-d > plot? To which of the 3 NMDS dimensions are these vectors being correlated? > Is there code to produce the x, y, and z coordinates of each of the sites in > Fish.mds? > > Thanks very much. > Katie > > > [[alternative HTML version deleted]] > > __ > R-help@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. > [[alternative HTML version deleted]] __ R-help@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.
[R] metaMDS and envfit: Help reading output
Hello R experts, I've used metaMDS to run NMDS on some fish abundance data, and am also working on correlating environmental data to the NMDS coordinates. I'm fairly new to metaMDS and NMDS in general, so I have what are probably some very basic questions. My fish abundance data consists of 66 sites for which up to 20 species of fish were identified and counted. I ran metaMDS on this data in 3 dimensions (after using a scree plot to check for stress levels in the different dimensions). I then used envfit to correlate a predictor dataset of environmental variables with the NMDS results, using the following code. >Fish<-as.data.frame(read.csv("Fish.csv",header=TRUE, sep = ",")) >Fish.mds<-metaMDS(Fish,zerodist = "add",k=3,trymax=20) >Predictors<-as.data.frame(read.csv("Predictors.csv",header=TRUE, sep = ",")) >Fish.fit <- envfit(Fish.mds$points, Predictors, k=3, 1000, na.rm = TRUE) >Fish.fit The output of Fish.fit was as follows (table truncated): Dim1Dim2r2 Pr(>r) DrainArea -0.5923233 -0.8057004 0.7674 0.000999 *** Flow-0.5283236 -0.8490431 0.7847 0.000999 *** StrmWidth -0.6993457 -0.7147836 0.6759 0.000999 *** Gradient0.4541225 0.8909392 0.2085 0.010989 * I'd like to better understand how to read this table. I understand that Dim1 and Dim2 refer to the dimensions of the vectors produced by envfit, and r2 is the r-squared of those vectors. But how do I visualize these vectors in a 3-d plot? To which of the 3 NMDS dimensions are these vectors being correlated? Is there code to produce the x, y, and z coordinates of each of the sites in Fish.mds? Thanks very much. Katie [[alternative HTML version deleted]] __ R-help@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.
Re: [R] metaMDS NMDS: use of alternative distances?
Kim Vanselow gmx.de> writes: > > Dear r-helpers! > How can I integrate other distances (in the form of a dist object) into function metaMDS? The problem: > metaMDS needs the original data.frame for the calculation and only the default distances of function > vegdist are allowed. > Any suggestions are greatly appreciated! > Thank you, > Kim > Kim, A small addition to Gavin's reply: the option of having your own dissimilarities was added in the latest release version (1.15-4). If you do not have that in your version of vegan, you should upgrade. Cheers, Jari Oksanen __ R-help@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.
Re: [R] metaMDS NMDS: use of alternative distances?
On Wed, 2009-10-14 at 16:57 +0200, Kim Vanselow wrote: > Dear r-helpers! > How can I integrate other distances (in the form of a dist object) > into function metaMDS? The problem: metaMDS needs the original > data.frame for the calculation and only the default distances of > function vegdist are allowed. > Any suggestions are greatly appreciated! > Thank you, > Kim Read the help page for metaMDS more closely? ;-) the first argument of metaMDS is 'comm'; this is documented as: comm: Community data. Alternatively, dissimilarities either as a 'dist' structure or as a symmetric square matrix. In the latter case all other stages are skipped except random starts and centring and pc rotation of axes. notice the bit about dissimilarities - which can either by square symmetric matrices or objects of class 'dist'. When you supply your own distances, not all the transformations and other options in metaMDS are turned on, so you may want to check the effects of transformations etc yourself, which you would apply before computing the dissimilarity matrix. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% 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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@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.
[R] metaMDS NMDS: use of alternative distances?
Dear r-helpers! How can I integrate other distances (in the form of a dist object) into function metaMDS? The problem: metaMDS needs the original data.frame for the calculation and only the default distances of function vegdist are allowed. Any suggestions are greatly appreciated! Thank you, Kim -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser __ R-help@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.
Re: [R] metaMDS using Dissimilarity matrix
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 [EMAIL PROTECTED] 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@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 [EMAIL PROTECTED] 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R
Re: [R] metaMDS using Dissimilarity matrix
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 > [EMAIL PROTECTED] > > 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@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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@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.
[R] metaMDS using Dissimilarity matrix
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. 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. 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 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 [EMAIL PROTECTED] 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@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.