Plotted envfit vectors not matching NMDS scores

南楼画角 提交于 2020-05-09 07:11:00

问题


I made a NMDS plot and plotted my envfit like follows

dataframe for mytable

sites=c("Site A","Site B","Site C","Site D","Site E","Site F","Site 
G","Site H","Site I","Site J","Site K","Site L","Site M","Site N","Site O","Site P","Site Q","Site R","Site S","Site T","Site U")
american.elm=c(41.91,10.11,2.62,5.31,7.51,9.72,17.44,9.06,19.83,30.81,62.6,21.29,20.7,28.68,27.69,34.89,35.65,3.87,12.68,1.58,2.97)
white.birch=c(7.07,15.89,26.77,15.61,14.59,6.33,2.23,11.66,21.49,20.15,7.61,23.29,0,0,0,0,0,0,0,56.09,42.34)
red.oak=c(0,0,0,0,0,0,0,0,0,0,0,6.02,0,0,0,0,0,0,0,0,0.05)
populus.grand=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.11,0)
beech=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.36,5.45)
sugar.maple=c(0.49,2.64,3.35,4.6,3.37,2,1.32,4.21,4.13,3.61,0.34,1.2,0,0,0,0,0,0,0,2.19,0.09)

mytable <- data.frame(sites,american.elm,red.oak,populus.grand,beech,sugar.maple)
mytable<-mytable[,2:ncol(mytable)]

Then

library(vegan)

mytable.NMDS=metaMDS(mytable, distance = "jaccard", k = 4, trymax = 2000, autotransform=FALSE)

plot.mytable<-data.frame(mytable.NMDS$points)
plot.mytable
par(mar=c(3,3,2,5) ,mgp=c(1.8,0.75,0))
plot(plot.mytable$MDS1, plot.mytable$MDS2, pch=16, cex=1, col="black",
     xlab="NMDS1", ylab="NMDS2", cex.lab=1, cex.axis=1, main="", bty="L",
     mai=c(0,0,2,10), xlim=c(-1.5,1.3), ylim=c(-0.9,1))

fit <- envfit(mytable.NMDS, mytable, choices=c(1,2,3))
fit.plot = plot(fit, cex=1.3, col="red", xlim=c(-1.5,1.3), ylim=c(-1.2,1.2),
                xlab="NMDS1",ylab="NMDS2")

This hows the trees' NMDS score

fit
# Table of the NMDS score of the trees
Trees=c("american.elm","red.oak","populus.grand","beech","sugar.maple")
Tree.NMDS1=c(-0.76538,-0.1533,0.36065,0.25411,0.49583)
Tree.NMDS2=c(-0.27961,0.06605,-0.51345,-0.79497,0.84299)
Tree.NMDS.scores=data.frame(Trees,Tree.NMDS1,Tree.NMDS2)
# Overlay the NMDS score on the plot
points(Tree.NMDS.scores$Tree.NMDS1,Tree.NMDS.scores$Tree.NMDS2,
       col="red", pch=16)

I would like to know why the end of the vector arrows are not matching the NMDS scores given out by the envfit() function?


回答1:


The values that you see in the table are the normalised coefficients from the linear regression used to project the vectors into the ordination. These are directions for arrows of unit length. When plotted we scale these arrows by the square root of their correlation. As such arrows with small correlations are represented by shorter arrows than those with stronger correlations. You can get these scaled arrow lengths using the scores() method:

> scores(fit, "vectors")
                    NMDS1       NMDS2      NMDS3
american.elm  -0.73129278 -0.26985224 -0.5479775
red.oak       -0.06624995  0.03042562  0.4270764
populus.grand  0.21774166 -0.31045377  0.4862402
beech          0.22772624 -0.70982231  0.4990966
sugar.maple    0.33541356  0.56604306 -0.1245767

Note however that these aren't the actual coordinates of the arrow heads in the plot either. As these are simply directions, even after we have scaled the length of the individual arrows by the strength of their correlation with the ordination axes, we can scale all the arrows by the same amount to make them better fill the plot space.

This is all explained in ?envfit. Here's the relevant section:

The printed output of continuous variables (vectors) gives the direction cosines which are the coordinates of the heads of unit length vectors. In plot these are scaled by their correlation (square root of the column r2) so that weak predictors have shorter arrows than strong predictors. You can see the scaled relative lengths using command scores. The plotted (and scaled) arrows are further adjusted to the current graph using a constant multiplier: this will keep the relative r2-scaled lengths of the arrows but tries to fill the current plot. You can see the multiplier using ordiArrowMul(result_of_envfit), and set it with the argument arrow.mul.

If we follow the advice we see:

> ordiArrowMul(fit)
[1] 1.031244

Implying that we multiply the scaled arrows by about 3%.

> scrs <- scores(fit, "vectors", choices = 1:2)
> scrs * ordiArrowMul(fit)
                    NMDS1      NMDS2
american.elm  -0.73819522 -0.2723993
red.oak       -0.06687526  0.0307128
populus.grand  0.21979686 -0.3133840
beech          0.22987567 -0.7165221
sugar.maple    0.33857942  0.5713858

Putting this all together with your plotting code, here's how we arrive at the arrow heads drawn by plot.envfit:

plot(mytable.NMDS, display = "sites", type = "n")
points(mytable.NMDS, display = "sites", pch = 19, col = "black")
plot(fit, col = 'red')

## add the locations of arrow heads as blue points to see if the correspond
points(scrs * ordiArrowMul(fit), col = "blue")

And this is what we get


Note how I used the existing plot methods and extractor functions like scores() to work with objects produced by vegan and build plots up from constituent parts. Doing things this way avoids you i) having to type out information that is already available to you, and ii) getting bitten when we change the internal representation of vegan objects or where the values stored internally are really working data that needs subsequent transformation/processing to yield valid or interpretable values. Wherever possible, avoid using $ to rummage around in objects.



来源:https://stackoverflow.com/questions/59290350/plotted-envfit-vectors-not-matching-nmds-scores

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!