Songer, Katherine B - DNR
2011-May-10 20:51 UTC
[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.fitThe 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]]
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]]
Hi Katie, On Tue, May 10, 2011 at 4:51 PM, Songer, Katherine B - DNR <Katherine.Songer at wisconsin.gov> 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 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. >-- 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
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.