[R-sig-eco] scaling issues with vegan's envfit()

Arnaud Duranel arnaud.duranel.09 at ucl.ac.uk
Mon Sep 22 22:19:35 CEST 2014


That's great, many thanks for your help Gavin.
Best wishes
Arnaud

On 22/09/2014 19:12, Gavin Simpson wrote:
> If I understand correctly Arnaud, you just need `predict()`:
>
> predict(pca1, newdata = varechem, type = "sp", scaling = 1)[, 1:2]
>
> where you set newdata to be the data frame of new variables you want 
> to add. This will add so-called passive species to the plot base on 
> the linear combinations of the site scores produced from the 
> ordination of the original data. Hence the new data need to be 
> measured on the same sites and have the same row names as the data 
> used to fit the PCA (as that is how vegan identifies them).
>
> Using the example you gave I get:
>
> > scores(pca1, scaling = 1, choices = 1:2, display = "sp")
>                 PC1        PC2
> N         0.4008477  0.5267927
> P        -1.5075888 -0.8781843
> K        -1.5384951 -0.6850869
> Ca       -1.5239497 -0.3582552
> Mg       -1.4922949 -0.4141239
> S        -1.4083631 -1.2567985
> Al        0.4893605 -2.0353607
> Fe        0.8599106 -1.6224771
> Mn       -1.2181461  0.8183585
> Zn       -1.4658174 -0.6861639
> Mo       -0.1759892 -0.9685048
> Baresoil -0.6925869  1.3373455
> Humdepth -0.9968279  1.4290890
> pH        0.7037755 -1.3647204
> attr(,"const")
> [1] 4.236078
> > predict(pca1, varechem, type = "sp", scaling = 1)[, 1:2]
>                 PC1        PC2
> N         0.4008477  0.5267927
> P        -1.5075888 -0.8781843
> K        -1.5384951 -0.6850869
> Ca       -1.5239497 -0.3582552
> Mg       -1.4922949 -0.4141239
> S        -1.4083631 -1.2567985
> Al        0.4893605 -2.0353607
> Fe        0.8599106 -1.6224771
> Mn       -1.2181461  0.8183585
> Zn       -1.4658174 -0.6861639
> Mo       -0.1759892 -0.9685048
> Baresoil -0.6925869  1.3373455
> Humdepth -0.9968279  1.4290890
> pH        0.7037755 -1.3647204
>
> So we are able to recover exactly the correct scores - you just need 
> to draw arrows (perhaps using ordiArrow()) from (0,0) to those 
> coordinates.
>
> I don't think `evnfit()` is the right approach here, especially trying 
> to fake this via `ordiArrowMul()` as that is trying to fill the space 
> and in scaling 1 you need to scale variables independently.
>
> HTH
>
> Gavin
>
> On 12 September 2014 12:06, ADuranel <arnaud.duranel.09 at ucl.ac.uk 
> <mailto:arnaud.duranel.09 at ucl.ac.uk>> wrote:
>
>     Hello
>
>     I am running a PCA of some environmental variables. I have a
>     second set of
>     environmental variables that I would like to project passively
>     onto the
>     ordination plot, but with the same arrow length scaling as that
>     used for the
>     first dataset. I used envfit() in vegan for that purpose. To check
>     that I
>     get the same arrow length scaling in plot.envfit() as in plot.cca(), I
>     fitted the same dataset:
>
>     require(vegan)
>     data(varechem)
>     pca1<-rda(varechem, scale=T)
>
>     ef<-envfit(pca1, scale(varechem))
>     plot(pca1, type="points")
>     sp.sc <http://sp.sc><-scores(pca1, display="species")
>     ef.sc <http://ef.sc><-scores(ef, display="vectors")
>     plot(ef, arrow.mul=abs(sp.sc <http://sp.sc>[1,1]/ef.sc
>     <http://ef.sc>[1,1]), col="red")
>     # equivalent to:
>     plot(ef, arrow.mul=vegan:::ordiArrowMul(ef.sc
>     <http://ef.sc>)/vegan:::ordiArrowMul(sp.sc <http://sp.sc>))
>
>     The last two lines are the only two ways I managed to get the same
>     length
>     scaling for the plot.cca() "species" and plot.envfit() vectors.
>     However if I want to use another scaling (scaling=1 or 3) for the
>     PCA plot,
>     I can't get similar coordinates for the plot.cca() "species" and
>     plot.envfit() vectors:
>
>     ef1<-envfit(pca1, scale(varechem), scaling=1)
>     plot(pca1, scaling=1, type="points")
>     sp.sc1<-scores(pca1, scaling=1, display="species")
>     ef.sc1<-scores(ef1, scaling=1, display="vectors")
>     plot(ef1, arrow.mul=abs(sp.sc1[1,1]/ef.sc1[1,1]), col="red") #
>     wrong: the
>     ratio sp.sc/ef.sc <http://sp.sc/ef.sc> varies according to
>     "species" in this case...
>     plot(ef1,
>     arrow.mul=vegan:::ordiArrowMul(ef.sc1)/vegan:::ordiArrowMul(sp.sc1))
>     # the
>     arrow length scaling varies according to "species".
>
>     Can somebody tell me what I am doing wrong here?
>
>     I use R version 3.1.1 (2014-07-10) with vegan_2.0-10
>     Platform: x86_64-w64-mingw32/x64 (64-bit)
>
>     Many thanks
>
>     Arnaud
>
>
>
>
>
>     --
>     View this message in context:
>     http://r-sig-ecology.471788.n2.nabble.com/scaling-issues-with-vegan-s-envfit-tp7579076.html
>     Sent from the r-sig-ecology mailing list archive at Nabble.com.
>
>     _______________________________________________
>     R-sig-ecology mailing list
>     R-sig-ecology at r-project.org <mailto:R-sig-ecology at r-project.org>
>     https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
>
>
>
> -- 
> Gavin Simpson, PhD


	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list