10.07.2015 Views

Multivariate Analysis of Ecological Communities in R: vegan tutorial

Multivariate Analysis of Ecological Communities in R: vegan tutorial

Multivariate Analysis of Ecological Communities in R: vegan tutorial

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.1 Non-metric Multidimensional scal<strong>in</strong>g 2 ORDINATION: BASIC METHODDim2−0.4 −0.2 0.0 0.2 0.45147131661822 1542025112332419122272810921−0.6 −0.4 −0.2 0.0 0.2 0.4Dim1Functions scores and ordiplot <strong>in</strong> <strong>vegan</strong> can be used to handle theresults <strong>of</strong> nmds:> ordiplot(vare.mds0, type = "t")Only site scores were shown, because dissimilarities did not have <strong>in</strong>formationabout species.The iterative search is very difficult <strong>in</strong> nmds, because <strong>of</strong> nonl<strong>in</strong>ear relationshipbetween ord<strong>in</strong>ation and orig<strong>in</strong>al dissimilarities. The iterationeasily gets trapped <strong>in</strong>to local optimum <strong>in</strong>stead <strong>of</strong> f<strong>in</strong>d<strong>in</strong>g the global optimum.Therefore it is recommended to use several random starts, andselect among similar solutions with smallest stresses. This may be tedious,but <strong>vegan</strong> has function metaMDS which does this, and many moreth<strong>in</strong>gs. The trac<strong>in</strong>g output is long, and we suppress it with trace = 0,but normally we want to see that someth<strong>in</strong>g happens, s<strong>in</strong>ce the analysiscan take a long time:> vare.mds vare.mdsNMDS2−0.5 0.0 0.5Cla.phyDic.polCet.isl 24Cla.ste112Cla.chlP<strong>in</strong>.sylBar.lyc12Cla.cer10 Poh.nut Pti.cil 21Cla.bot9Dic.spEmp.nig Vac.vit19234 Cla.ran Cla.uncPel.aphCla.cri Cla.graBet.pubPol.pilPle.sch6 13 2028Cet.nivCet.eri Cal.vul Cla.cor Cla.defCla.fimVac.myr15Led.pal3 18 Cla.sp 16Cla.arb Cla.coc22277Pol.junHyl.spl14Pol.comSte.spDes.fle5 Dip.monDic.fusVac.uli25Cla.amaIch.eriNep.arc−0.5 0.0 0.5 1.0NMDS1Call:metaMDS(comm = varespec, trace = FALSE)Nonmetric Multidimensional Scal<strong>in</strong>g us<strong>in</strong>g isoMDS (MASS package)Data: wiscons<strong>in</strong>(sqrt(varespec))Distance: brayDimensions: 2Stress: 18.26Two convergent solutions found after 8 triesScal<strong>in</strong>g: centr<strong>in</strong>g, PC rotation, halfchange scal<strong>in</strong>gSpecies: expanded scores based on ‘wiscons<strong>in</strong>(sqrt(varespec))’> plot(vare.mds, type = "t")We did not calculate dissimilarities <strong>in</strong> a separate step, but we gave theorig<strong>in</strong>al data matrix as <strong>in</strong>put. The result is more complicated than previously,and has quite a few components <strong>in</strong> addition to those <strong>in</strong> isoMDS results:po<strong>in</strong>ts, dims, stress, data, distance, converged, tries,species, call. The function wraps recommended procedures <strong>in</strong>to onecommand. So what happened here?1. The range <strong>of</strong> data values was so large that the data were square roottransformed, and then submitted to Wiscons<strong>in</strong> double standardization,or species divided by their maxima, and stands standardizedto equal totals. These two standardizations <strong>of</strong>ten improve the quality<strong>of</strong> ord<strong>in</strong>ations, but we forgot to th<strong>in</strong>k about them <strong>in</strong> the <strong>in</strong>itialanalysis.2. Function used Bray–Curtis dissimilarities.3. Function run isoMDS with several random starts, and stopped eitherafter a certa<strong>in</strong> number <strong>of</strong> tries, or after f<strong>in</strong>d<strong>in</strong>g two similarconfigurations with m<strong>in</strong>imum stress. In any case, it returned thebest solution.4


2 ORDINATION: BASIC METHOD 2.2 Community dissimilarities4. Function rotated the solution so that the largest variance <strong>of</strong> sitescores will be on the first axis.5. Function scaled the solution so that one unit corresponds to halv<strong>in</strong>g<strong>of</strong> community similarity from the replicate similarity.6. Function found species scores as weighted averages <strong>of</strong> site scores,but expanded them so that species and site scores have equal variances.This expansion can be undone us<strong>in</strong>g shr<strong>in</strong>k = TRUE <strong>in</strong> displaycommands.The help page for metaMDS will give more details, and po<strong>in</strong>t to explanation<strong>of</strong> functions used <strong>in</strong> the function.2.2 Community dissimilaritiesNon-metric multidimensional scal<strong>in</strong>g is a good ord<strong>in</strong>ation method becauseit can use ecologically mean<strong>in</strong>gful ways <strong>of</strong> measur<strong>in</strong>g communitydissimilarities. A good dissimilarity measure has a good rank order relationto distance along environmental gradients. Because nmds only usesrank <strong>in</strong>formation and maps ranks non-l<strong>in</strong>early onto ord<strong>in</strong>ation space, itcan handle non-l<strong>in</strong>ear species responses <strong>of</strong> any shape and effectively androbustly f<strong>in</strong>d the underly<strong>in</strong>g gradients.The most natural dissimilarity measure is Euclidean distance which is<strong>in</strong>herently used by eigenvector methods <strong>of</strong> ord<strong>in</strong>ation. It is the distance <strong>in</strong>species space. Species space means that each species is an axis orthogonalto all other species, and sites are po<strong>in</strong>ts <strong>in</strong> this multidimensional hyperspace.However, Euclidean distance is based on squared differences andstrongly dom<strong>in</strong>ated by s<strong>in</strong>gle large differences. Most ecologically mean<strong>in</strong>gfuldissimilarities are <strong>of</strong> Manhattan type, and use differences <strong>in</strong>stead <strong>of</strong>squared differences. Another feature <strong>in</strong> good dissimilarity <strong>in</strong>dices is thatthey are proportional: if two communities share no species, they have amaximum dissimilarity = 1. Euclidean and Manhattan dissimilaritieswill vary accord<strong>in</strong>g to total abundances even though there are no sharedspecies.Package <strong>vegan</strong> has function vegdist with Bray–Curtis, Jaccard andKulczyński <strong>in</strong>dices. All these are <strong>of</strong> the Manhattan type and useonly first order terms (sums and differences), and all are relativized bysite total and reach their maximum value (1) when there are no sharedspecies between two compared communities. Function vegdist is a drop<strong>in</strong>replacement for standard R function dist, and either <strong>of</strong> these functionscan be used <strong>in</strong> analyses <strong>of</strong> dissimilarities.There are many confus<strong>in</strong>g aspects <strong>in</strong> dissimilarity <strong>in</strong>dices. One is thatsame <strong>in</strong>dices can be written with very different look<strong>in</strong>g equations: twoalternative formulations <strong>of</strong> Manhattan dissimilarities <strong>in</strong> the marg<strong>in</strong> serveas an example. Another complication is nam<strong>in</strong>g. Function vegdist usescolloquial names which may not be strictly correct. The default <strong>in</strong>dex <strong>in</strong><strong>vegan</strong> is called Bray (or Bray–Curtis), but it probably should be calledSte<strong>in</strong>haus <strong>in</strong>dex. On the other hand, its correct name was supposed to beCzekanowski <strong>in</strong>dex some years ago (but now this is regarded as another<strong>in</strong>dex), and it is also known as Sørensen <strong>in</strong>dex (but usually misspelt).5∑d jk = √ N (x ij − x ik ) 2 Euclideand jk =i=1N∑|x ij − x ik | Manhattani=1N∑N∑A = x ij B =J =i=1N∑m<strong>in</strong>(x ij , x ik )i=1d jk = A + B − 2Jd jk = A + B − 2JA + Bd jk = A + B − 2JA + B − Jd jk = 1 − 1 ( J2 A + J )Bi=1x ikManhattanBrayJaccardKulczyński


2.2 Community dissimilarities 2 ORDINATION: BASIC METHODfor A = B d AB = 0for A ≠ B d AB > 0d AB = d BAd AB ≤ d Ax + d xBStrictly speak<strong>in</strong>g, Jaccard <strong>in</strong>dex is b<strong>in</strong>ary, and the quantitative variant<strong>in</strong> <strong>vegan</strong> should be called Ružička <strong>in</strong>dex. However, <strong>vegan</strong> f<strong>in</strong>ds eitherquantitative or b<strong>in</strong>ary variant <strong>of</strong> any <strong>in</strong>dex under the same name.These three basic <strong>in</strong>dices are regarded as good <strong>in</strong> detect<strong>in</strong>g gradients.In addition, vegdist function has <strong>in</strong>dices that should satisfy othercriteria. Morisita, Horn–Morisita, Raup–Cric, B<strong>in</strong>omial and Mountford<strong>in</strong>dices should be able to compare sampl<strong>in</strong>g units <strong>of</strong> different sizes. Euclidean,Canberra and Gower <strong>in</strong>dices should have better theoretical properties.Function metaMDS used Bray-Curtis dissimilarity as default, whichusually is a good choice. Jaccard (Ružička) <strong>in</strong>dex has identical rankorder, but has better metric properties, and probably should be preferred.Function rank<strong>in</strong>dex <strong>in</strong> <strong>vegan</strong> can be used to study which <strong>of</strong> the <strong>in</strong>dicesbest separates communities along known gradients us<strong>in</strong>g rank correlationas default. The follow<strong>in</strong>g example uses all environmental variables <strong>in</strong> dataset varechem, but standardizes these to unit variance:> data(varechem)> rank<strong>in</strong>dex(scale(varechem), varespec, c("euc", "man",+ "bray", "jac", "kul"))euc man bray jac kul0.2396 0.2735 0.2838 0.2838 0.2840are non-l<strong>in</strong>early related, but they have identical rank orders, and theirrank correlations are identical. In general, the three recommended <strong>in</strong>dicesare fairly equal.I took a very practical approach on <strong>in</strong>dices emphasiz<strong>in</strong>g their abilityto recover underly<strong>in</strong>g environmental gradients. Many textbooks emphasizemetric properties <strong>of</strong> <strong>in</strong>dices. These are important <strong>in</strong> some methods,but not <strong>in</strong> nmds which only uses rank order <strong>in</strong>formation. The metricproperties simply say that1. if two sites are identical, their distance is zero,2. if two sites are different, their distance is larger than zero,3. distances are symmetric, and4. the shortest distance between two sites is a l<strong>in</strong>e, and you cannotimprove by go<strong>in</strong>g through other sites.These all sound very natural conditions, but they are not fulfilled by alldissimilarities. Actually, only Euclidean distances – and probably Jaccard<strong>in</strong>dex – fulfill all conditions among the dissimilarities discussed here, andare metrics. Many other dissimilarities fulfill three first conditions andare semimetrics.There is a school that says that we should use metric <strong>in</strong>dices, andmost naturally, Euclidean distances. One <strong>of</strong> their drawbacks was thatthey have no fixed limit, but two sites with no shared species can vary<strong>in</strong> dissimilarities, and even look more similar than two sites shar<strong>in</strong>g somespecies. This can be cured by standardiz<strong>in</strong>g data. S<strong>in</strong>ce Euclidean distancesare based on squared differences, a natural transformation is tostandardize sites to equal sum <strong>of</strong> squares, or to their vector norm us<strong>in</strong>gfunction decostand:6


2 ORDINATION: BASIC METHOD 2.3 Compar<strong>in</strong>g ord<strong>in</strong>ations: Procrustes rotation> dis dis d d d


2 ORDINATION: BASIC METHOD 2.4 Eigenvector methodsInertia is varianceEigenvalues for unconstra<strong>in</strong>ed axes:PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8983.0 464.3 132.3 73.9 48.4 37.0 25.7 19.7(Showed only 8 <strong>of</strong> all 23 unconstra<strong>in</strong>ed eigenvalues)> plot(vare.pca)The output tells that the total <strong>in</strong>ertia is 1826, and the <strong>in</strong>ertia is variance.The sum <strong>of</strong> all 23 (rank) eigenvalues would be equal to the total<strong>in</strong>ertia. In other words, the solution decomposes the total variance <strong>in</strong>tol<strong>in</strong>ear components. We can easily see that the variance equals <strong>in</strong>ertia:> sum(apply(varespec, 2, var))PC2−6 −4 −2 0 2 4 6576Cla.ranCla.arb1318414Cal.vul Vac.uliSte.sp112016 Cla.unc Nep.arc Cla.ama Led.pal Dip.mon Pol.com Pol.jun Des.fle Cla.def Bet.pub Pel.aph Poh.nut Cla.coc Cla.gra Cla.phy Cla.cor Cla.bot Cla.cer Dic.pol Cla.fim Bar.lyc Cla.cri Cet.eri Cla.chl Cla.sp P<strong>in</strong>.syl Ich.eri Cet.isl Pol.pil Cet.niv Pti.cil23Dic.fusDic.sp Hyl.spl 21 Emp.nigVac.myr Vac.vit15 22192524Ple.sch 27283122109Cla.ste[1] 1826Function apply applies function var or variance to dimension 2 or columns(species), and then sum takes the sum <strong>of</strong> these values. Inertia is the sum<strong>of</strong> all species variances. The eigenvalues sum up to total <strong>in</strong>ertia. In otherwords, they each “expla<strong>in</strong>” a certa<strong>in</strong> proportion <strong>of</strong> total variance. Thefirst axis “expla<strong>in</strong>s” 983/ 1826 = 53.8˜% <strong>of</strong> total variance.The standard ord<strong>in</strong>ation plot command uses po<strong>in</strong>ts or labels forspecies and sites. Some people prefer to use biplot arrows for species<strong>in</strong> pca and possibly also for sites. There is a special biplot function forthis purpose:> biplot(vare.pca, scal<strong>in</strong>g = -1)For this graph we specified scal<strong>in</strong>g = -1. The results are scaled onlywhen they are accessed, and we can flexibly change the scal<strong>in</strong>g <strong>in</strong> plot,biplot and other commands. The negative values mean that speciesscores are divided by the species standard deviations so that abundantand scarce species will be approximately as far away from the orig<strong>in</strong>.The species ord<strong>in</strong>ation looks somewhat unsatisfactory: only re<strong>in</strong>deerlichens (Clad<strong>in</strong>a) and Pleurozium schreberi are visible, and all otherspecies are crowded at the orig<strong>in</strong>. This happens because <strong>in</strong>ertia was variance,and only abundant species with high variances are worth expla<strong>in</strong><strong>in</strong>g(but we could hide this <strong>in</strong> plot by sett<strong>in</strong>g negative scal<strong>in</strong>g). Standardiz<strong>in</strong>gall species to unit variance, or us<strong>in</strong>g correlation coefficients <strong>in</strong>stead<strong>of</strong> covariances will give a more balanced ord<strong>in</strong>ation:PC2−4 −2 0 2 4−4 −2 0 2 4 6 8 10PC1Cla.arb Cla.ranIch.eri 7Ste.sp56Vac.uliCla.ama Pol.pil Cla.cocCla.gra 1813 Dip.monCal.vulCet.niv4Cet.eriCla.fim314Cla.unc Cla.cerCla.def 201116 Cla.cri23Cla.cor Pel.aph Bet.pub Bar.lycCla.bot Pti.cil 212Pol.jun Nep.arc15 Dic.fus Dic.pol 19 Cla.spP<strong>in</strong>.syl1222 24 25Dic.spCet.isl Cla.chl Cla.phy Cla.ste10Led.pal Pol.comEmp.nig9Vac.vit Poh.nut27 Des.fleVac.myr28Hyl.splPle.sch−4 −2 0 2 4 6PC1> vare.pca vare.pcaCall: rda(X = varespec, scale = TRUE)Inertia RankTotal 44Unconstra<strong>in</strong>ed 44 23Inertia is correlationsEigenvalues for unconstra<strong>in</strong>ed axes:PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC88.90 4.76 4.26 3.73 2.96 2.88 2.73 2.18(Showed only 8 <strong>of</strong> all 23 unconstra<strong>in</strong>ed eigenvalues)> plot(vare.pca, scal<strong>in</strong>g = 3)9


2.4 Eigenvector methods 2 ORDINATION: BASIC METHODPC2CA2−2 −1 0 1−2.0 −1.5 −1.0 −0.5 0.0 0.5 1.0 1.511Cla.phy10Cla.cocCla.ste P<strong>in</strong>.sylCla.sp Cla.graPol.pil Cet.eri Cla.cri Cla.fim 23 12Cla.ran 1418Cla.def5 Cla.arb Ste.sp6 Dip.mon Cla.uncCla.ama Cla.corPel.aph13 24Ich.eri Cal.vul3Cet.niv7 1516 20Dic.sp4 Vac.uliCla.cer Dic.fusPol.jun2Nep.arc192225 Des.flePle.sch Hyl.spl289Poh.nutCla.chlCet.isl27Vac.vitEmp.nigPol.com Led.palVac.myrDic.polPti.cilBet.pub Bar.lycCla.bot−1 0 1 2 39102312Cla.phyCla.steCet.niv4Cet.islCla.chlP<strong>in</strong>.sylCla.spCla.cer11Dip.mon Cla.ranPol.pilCla.ama56Ste.sp 13719Cla.arb 18Vac.uli Cal.vulPC1Poh.nutEmp.nigVac.vitCla.cocPti.cil Vac.myrLed.palDic.polPol.com27Des.fleCla.bot−1 0 1 2CA121Bar.lycBet.pubPel.aphCla.fim Cla.cor 23Cla.graIch.eriCla.cri Cla.def 20Cet.eriPle.schDic.sp 2425Nep.arcPol.junCla.unc1415Dic.fus1622Hyl.spl2821Now <strong>in</strong>ertia is correlation, and the correlation <strong>of</strong> a variable with itself isone. Thus the total <strong>in</strong>ertia is equal to the number <strong>of</strong> variables (species).The rank or the total number <strong>of</strong> eigenvectors is the same as previously.The maximum possible rank is def<strong>in</strong>ed by the dimensions <strong>of</strong> the data: itis one less than smaller <strong>of</strong> number <strong>of</strong> species or number <strong>of</strong> sites:> dim(varespec)[1] 24 44If there are species or sites similar to each other, rank will be reducedeven from this.The percentage expla<strong>in</strong>ed by the first axis decreased from the previouspca. This is natural, s<strong>in</strong>ce previously we needed to “expla<strong>in</strong>” only theabundant species with high variances, but now we have to expla<strong>in</strong> allspecies equally. We should not look bl<strong>in</strong>dly at percentages, but the resultwe get.Correspondence analysis is very similar to pca:> vare.ca vare.caCall: cca(X = varespec)Inertia RankTotal 2.08Unconstra<strong>in</strong>ed 2.08 23Inertia is mean squared cont<strong>in</strong>gency coefficientEigenvalues for unconstra<strong>in</strong>ed axes:CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA80.525 0.357 0.234 0.195 0.178 0.122 0.115 0.089(Showed only 8 <strong>of</strong> all 23 unconstra<strong>in</strong>ed eigenvalues)> plot(vare.ca)Now the <strong>in</strong>ertia is called mean squared cont<strong>in</strong>gency coefficient. Correspondenceanalysis is based on Chi-squared distance, and the <strong>in</strong>ertia isthe Chi-squared statistic <strong>of</strong> a data matrix standardized to unit total:> chisq.test(varespec/sum(varespec))CA2−2 −1 0 1 2Cla.phyCla.steCet.nivCet.islCla.chlDip.monCla.ran 7Pol.pil 5Cla.arbVac.uli Cal.vulPti.cil Vac.myrLed.palDic.polPol.comDes.fleCla.bot−2 −1 0 1 2 3CA1Bar.lycBet.pub9212810P<strong>in</strong>.syl Poh.nutPle.sch2Cla.sp1227Emp.nig 19Vac.vitDic.spNep.arc3Pol.jun 24 25Cla.cer 11 Pel.aph 23Cla.fim Cla.cor 15 22204Cla.gra 16Cla.cri Cla.defCla.coc 18Dic.fusCet.eri146 13Cla.amaSte.spIch.eriCla.uncHyl.splPearson's Chi-squared testdata: varespec/sum(varespec)X-squared = 2.083, df = 989, p-value = 1You should not pay any attention to P -values which are certa<strong>in</strong>ly mislead<strong>in</strong>g,but notice that the reported X-squared is equal to the <strong>in</strong>ertiaabove.Correspondence analysis is a weighted averag<strong>in</strong>g method. In the graphabove species scores were weighted averages <strong>of</strong> site scores. With differentscal<strong>in</strong>g <strong>of</strong> results, we could display the site scores as weighted averages <strong>of</strong>species scores:> plot(vare.ca, scal<strong>in</strong>g = 1)We already saw an example <strong>of</strong> scal<strong>in</strong>g = 3 or symmetric scal<strong>in</strong>g <strong>in</strong> pca.The other two <strong>in</strong>tegers mean that either species are weighted averages <strong>of</strong>sites (2) or sites are weighted averages <strong>of</strong> species (1). When we take10


2 ORDINATION: BASIC METHOD 2.5 Detrended correspondence analysisweighted averages, the range <strong>of</strong> averages shr<strong>in</strong>ks from the orig<strong>in</strong>al values.The shr<strong>in</strong>kage factor is equal to the eigenvalue <strong>of</strong> ca, which has atheoretical maximum <strong>of</strong> 1.2.5 Detrended correspondence analysisCorrespondence analysis is a much better and more robust method forcommunity ord<strong>in</strong>ation than pr<strong>in</strong>cipal components analysis. However,with long ecological gradients it suffers from some drawbacks or “faults”which were corrected <strong>in</strong> detrended correspondence analysis (dca):• S<strong>in</strong>gle long gradients appear as curves or arcs <strong>in</strong> ord<strong>in</strong>ation (arceffect): the solution is to detrend the later axes by mak<strong>in</strong>g theirmeans equal along segments <strong>of</strong> previous axes.• Sites are packed more closely at gradient extremes than at the centre:the solution is to rescale the axes to equal variances <strong>of</strong> speciesscores.• Rare species seem to have an unduly high <strong>in</strong>fluence on the results:the solution iss to downweight rare species.All these three separate tricks are <strong>in</strong>corporated <strong>in</strong> function decoranawhich is a faithful port <strong>of</strong> Mark Hill’s orig<strong>in</strong>al programme with the samename. The usage is simple:> vare.dca vare.dca21Call:decorana(veg = varespec)Detrended correspondence analysis with 26 segments.Rescal<strong>in</strong>g <strong>of</strong> axes with 4 iterations.DCA1 DCA2 DCA3 DCA4Eigenvalues 0.524 0.325 0.2001 0.1918Decorana values 0.525 0.157 0.0967 0.0608Axis lengths 2.816 2.205 1.5465 1.6486> plot(vare.dca, display = "sites")DCA2−1.0 −0.5 0.0 0.5 1.01092 12282719311231824202515224616137514−1.0 −0.5 0.0 0.5 1.0 1.5DCA1Function decorana f<strong>in</strong>ds only four axes. Eigenvalues are def<strong>in</strong>ed as shr<strong>in</strong>kagevalues <strong>in</strong> weighted averages, similarly as <strong>in</strong> cca above. The “Decoranavalues” are the numbers that the orig<strong>in</strong>al programme returns as “eigenvalues”— I have no idea <strong>of</strong> their possible mean<strong>in</strong>g, and they should notbe used. Most <strong>of</strong>ten people comment on axis lengths, which sometimesare called “gradient lengths”. The etymology is obscure: these are notgradients, but ord<strong>in</strong>ation axes. It is <strong>of</strong>ten said that if the axis length isshorter than two units, the data are l<strong>in</strong>ear, and pca should be used. Thisis only folklore and not based on research which shows that ca is at leastas good as pca with short gradients, and usually better.The current data set is homogeneous, and the effects <strong>of</strong> dca are notvery large. In heterogeneous data with a clear arc effect the changes <strong>of</strong>ten11


2.6 Ord<strong>in</strong>ation graphics 2 ORDINATION: BASIC METHODare more dramatic. Rescal<strong>in</strong>g may have larger <strong>in</strong>fluence than detrend<strong>in</strong>g<strong>in</strong> many cases.The default analysis is without downweight<strong>in</strong>g <strong>of</strong> rare species: see helppages for the needed arguments. Actually, downweight is an <strong>in</strong>dependentfunction that can be used with cca as well.There is a school <strong>of</strong> thought that regards dca as the method <strong>of</strong> choice<strong>in</strong> unconstra<strong>in</strong>ed ord<strong>in</strong>ation. However, it seems to be a fragile and vagueback <strong>of</strong> tricks that is better avoided.2.6 Ord<strong>in</strong>ation graphicsWe have already seen many ord<strong>in</strong>ation diagrams <strong>in</strong> this <strong>tutorial</strong> with onefeature <strong>in</strong> common: they are cluttered and labels are difficult to read.Ord<strong>in</strong>ation diagrams are difficult to draw cleanly because we must put alarge number <strong>of</strong> labels <strong>in</strong> a small plot, and <strong>of</strong>ten it is impossible to drawclean plots with all items labelled. In this chapter we look at produc<strong>in</strong>gcleaner plots. For this we must look at the anatomy <strong>of</strong> plott<strong>in</strong>g functions<strong>in</strong> <strong>vegan</strong> and see how to ga<strong>in</strong> a better control <strong>of</strong> default functions.Ord<strong>in</strong>ation functions <strong>in</strong> <strong>vegan</strong> have their dedicated plot functionswhich provides a simple plot. For <strong>in</strong>stance, the result <strong>of</strong> decorana isdisplayed by function plot.decorana which beh<strong>in</strong>d the scenes is calledby our plot function. Alternatively, we can use function ordiplot whichalso works with many non-<strong>vegan</strong> ord<strong>in</strong>ation functions, but uses po<strong>in</strong>ts<strong>in</strong>stead <strong>of</strong> text as default. The plot.decorana function (or ordiplot)actually works <strong>in</strong> three stages:1. It draws an empty plot with labelled axes, but with no symbols forsites or species.2. It uses functions text or po<strong>in</strong>ts to add species to the empty frame.If the user does not ask specifically, the function will use text <strong>in</strong>small data sets and po<strong>in</strong>ts <strong>in</strong> large data sets.3. It adds the sites similarly.DCA2−4 −2 0 2 4++++ + + + ++ ++++ +++++++ + ++ ++++● ●● ●●+ ++ ++● + + + +●●●●+ ++ +●●●● ●●● ●● ● ● ●+++ ++ ++ ++ +●● ●●●+ + +●●++++ ++ +++ +++ +++++++++++++ ++++++ + +++++ ++++++ + +++ +++ ++++For better control <strong>of</strong> the plots we must repeat these stages by hand: drawan empty plot and then add sites and/or species as desired.In this chapter we study a difficult case: plott<strong>in</strong>g the Barro ColoradoIsland ord<strong>in</strong>ations.> data(BCI)This is a difficult data set for plott<strong>in</strong>g: it has 225 species and there is noway <strong>of</strong> labell<strong>in</strong>g them all cleanly – unless we use very large plott<strong>in</strong>g areawith small text. We must show only a selection <strong>of</strong> the species or smallparts <strong>of</strong> the plot. First an ord<strong>in</strong>ation with decorana and its default plot:−6 −4 −2 0 2 4 6DCA1> mod plot(mod)There is an additional problem <strong>in</strong> plott<strong>in</strong>g species ord<strong>in</strong>ation with thesedata:> names(BCI)[1:5]12


3 ENVIRONMENTAL INTERPRETATIONgraphics files. Moreover, the ordipo<strong>in</strong>tlabel ouput can be edited us<strong>in</strong>gorditkplot.Functions identify, orditorp, ordilabel and ordipo<strong>in</strong>tlabel mayprovide a quick and easy way to <strong>in</strong>spect ord<strong>in</strong>ation results. Often we needa better control <strong>of</strong> graphics, and judicuously select the labelled species.In that case we can first draw an empty plot (with type = "n"), andthen use select argument <strong>in</strong> ord<strong>in</strong>ation text and po<strong>in</strong>ts functions. Theselect argument can be a numeric vector that lists the <strong>in</strong>dices <strong>of</strong> selecteditems. Such <strong>in</strong>dices are displayed from identify functions which can beused to help <strong>in</strong> select<strong>in</strong>g the items. Alternatively, select can be a logicalvector which is TRUE to selected items. Such a list was produced <strong>in</strong>visiblyfrom orditorp. You cannot see <strong>in</strong>visible results directly from the method,but you can catch the result like we did above <strong>in</strong> the first orditorp call,and use this vector as a basis for fully controlled graphics. In this casethe first items were:> sel[1:14]Abarmacr Acacmela Acaldive Acalmacr Adeltril Aegipana AlchcostFALSE FALSE FALSE FALSE FALSE FALSE FALSEAlchlati Alibedul Allopsil Alseblac Amaicory Anacexce Andi<strong>in</strong>erTRUE FALSE FALSE FALSE TRUE TRUE FALSE3 Environmental <strong>in</strong>terpretationIt is <strong>of</strong>ten possible to “expla<strong>in</strong>” ord<strong>in</strong>ation us<strong>in</strong>g ecological knowledge onstudied sites, or knowledge on the ecological characteristics <strong>of</strong> species.Usually it is preferable to use external environmental variables to <strong>in</strong>terpretthe ord<strong>in</strong>ation. There are many ways <strong>of</strong> overlay<strong>in</strong>g environmental<strong>in</strong>formation onto ord<strong>in</strong>ation diagrams. One <strong>of</strong> the simplest is to changethe size <strong>of</strong> plott<strong>in</strong>g characters accord<strong>in</strong>g to an environmental variables(argument cex <strong>in</strong> plot functions). The <strong>vegan</strong> package has some usefulfunctions for fitt<strong>in</strong>g environmental variables.3.1 Vector fitt<strong>in</strong>gThe most commonly used method <strong>of</strong> <strong>in</strong>terpretation is to fit environmentalvectors onto ord<strong>in</strong>ation. The fitted vectors are arrows with the <strong>in</strong>terpretation:• The arrow po<strong>in</strong>ts to the direction <strong>of</strong> most rapid change <strong>in</strong> the theenvironmental variable. Often this is called the direction <strong>of</strong> thegradient.• The length <strong>of</strong> the arrow is proportional to the correlation betweenord<strong>in</strong>ation and environmental variable. Often this is called thestrength <strong>of</strong> the gradient.Fitt<strong>in</strong>g environmental vectors is easy us<strong>in</strong>g function envfit. Theexample uses the previous nmds result and environmental variables <strong>in</strong>the data set varechem:> data(varechem)> ef ef14


3 ENVIRONMENTAL INTERPRETATION 3.2 Surface fitt<strong>in</strong>g***VECTORSNMDS1 NMDS2 r2 Pr(>r)N -0.0573 -0.9984 0.25 0.041 *P 0.6197 0.7848 0.19 0.092 .K 0.7665 0.6423 0.18 0.109Ca 0.6852 0.7284 0.41 0.003 **Mg 0.6325 0.7745 0.43 0.003 **S 0.1914 0.9815 0.18 0.137Al -0.8716 0.4902 0.53 0.002 **Fe -0.9360 0.3519 0.45 0.004 **Mn 0.7987 -0.6017 0.52 0.001 ***Zn 0.6175 0.7865 0.19 0.104Mo -0.9031 0.4294 0.06 0.504Baresoil 0.9249 -0.3802 0.25 0.041 *Humdepth 0.9328 -0.3603 0.52 0.003 **pH -0.6480 0.7616 0.23 0.070 .---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1P values based on 999 permutations.The first two columns give direction cos<strong>in</strong>es <strong>of</strong> the vectors, and r2 givesthe squared correlation coefficient. For plott<strong>in</strong>g, the axes should be scaledby the square root <strong>of</strong> r2. The plot function does this automatically, andyou can extract the scaled values with scores(ef, "vectors"). Thesignificances (Pr>r), or P -values are based on random permutations <strong>of</strong>the data: if you <strong>of</strong>ten get as good or better R 2 with randomly permuteddata, your values are <strong>in</strong>significant.You can add the fitted vectors to an ord<strong>in</strong>ation us<strong>in</strong>g plot command.You can limit plott<strong>in</strong>g to most significant variables with argument p.max.As usual, more options can be found <strong>in</strong> the help pages.NMDS2−0.4 −0.2 0.0 0.2 0.4●●AlFe●●●pH●●●●●●●N●●●●●●P●●●MgCaBaresoilHumdepthMn●●●> plot(vare.mds, display = "sites")> plot(ef, p.max = 0.1)−0.4 −0.2 0.0 0.2 0.4 0.6NMDS13.2 Surface fitt<strong>in</strong>gVector fitt<strong>in</strong>g is popular, and it provides a compact way <strong>of</strong> simultaneouslydisplay<strong>in</strong>g a large number <strong>of</strong> environmental variables. However, it impliesa l<strong>in</strong>ear relationship between ord<strong>in</strong>ation and environment: direction andstrength are all you need to know. This may not always be appropriate.Function ordisurf fits surfaces <strong>of</strong> environmental variables to ord<strong>in</strong>ations.It uses generalized additive models <strong>in</strong> function gam <strong>of</strong> packagemgcv. Function gam uses th<strong>in</strong>plate spl<strong>in</strong>es <strong>in</strong> two dimensions, and automaticallyselects the degree <strong>of</strong> smooth<strong>in</strong>g by generalized cross-validation.If the response really is l<strong>in</strong>ear and vectors are appropriate, the fitted surfaceis a plane whose gradient is parallel to the arrow, and the fittedcontours are equally spaced parallel l<strong>in</strong>es perpendicular to the arrow.In the follow<strong>in</strong>g example I <strong>in</strong>troduce two new R features:• Function envfit can be called with formula <strong>in</strong>terface. Formulahas a special character tilde (∼), and the left-hand side gives theord<strong>in</strong>ation results, and the right-hand side lists the environmental15


3.3 Factors 3 ENVIRONMENTAL INTERPRETATIONvariables. In addition, we must def<strong>in</strong>e the name <strong>of</strong> the data conta<strong>in</strong><strong>in</strong>gthe fitted variables.• The variables <strong>in</strong> data frames are not visible to R session unless thedata frame is attached to the session. We may not want to make allvariables visible to the session, because there may be synonymousnames, and we may use wrong variables with the same name <strong>in</strong>some analyses. We can use function with which makes the givendata frame visible only to the follow<strong>in</strong>g command.Now we are ready for the example. We make vector fitt<strong>in</strong>g for selectedvariables and add fitted surfaces <strong>in</strong> the same plot.> ef plot(vare.mds, display = "sites")> plot(ef)> tmp


3 ENVIRONMENTAL INTERPRETATION 3.3 FactorsA1 0.9982 0.0606 0.31 0.043 *---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1P values based on 999 permutations.***FACTORS:Centroids:CA1 CA2Moisture1 -0.75 -0.14Moisture2 -0.47 -0.22Moisture4 0.18 -0.73Moisture5 1.11 0.57ManagementBF -0.73 -0.14ManagementHF -0.39 -0.30ManagementNM 0.65 1.44ManagementSF 0.34 -0.68UseHayfield -0.29 0.65UseHaypastu -0.07 -0.56UsePasture 0.52 0.05Manure0 0.65 1.44Manure1 -0.46 -0.17Manure2 -0.59 -0.36Manure3 0.52 -0.32Manure4 -0.21 -0.8819Goodness <strong>of</strong> fit:r2 Pr(>r)Moisture 0.41 0.006 **Management 0.44 0.003 **Use 0.18 0.085 .Manure 0.46 0.005 **---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1P values based on 999 permutations.CA2−1 0 1 2 317ManagementNMManure0UseHayfield 18Moisture51110 6 UsePastureManagementBFMoisture157Moisture2Manure1ManagementHF 8Manure2 Manure3UseHaypastu2 ManagementSF12Moisture44 9Manure4 13312015 1416A1> plot(dune.ca, display = "sites")> plot(ef)−2 −1 0 1 2CA1The names <strong>of</strong> factor centroids are formed by comb<strong>in</strong><strong>in</strong>g the name <strong>of</strong>the factor and the name <strong>of</strong> the level. Now the axes show the centroidsfor the level, and the R 2 values are for the whole factor, just like thesignificance test. The plot looks congested, and we may use tricks <strong>of</strong> §2.6(p. 12) to make cleaner plots, but obviously not all factors are necessary<strong>in</strong> <strong>in</strong>terpretation.Package <strong>vegan</strong> has several functions for graphical display <strong>of</strong> factors.Function ordihull draws an enclos<strong>in</strong>g convex hull for the items <strong>in</strong> aclass, ordispider comb<strong>in</strong>es items to their (weighted) class centroid, andordiellipse draws ellipses for class standard deviations, standard errorsor confidence areas. The example displays all these for Management type<strong>in</strong> the previous ord<strong>in</strong>ation:> plot(dune.ca, display = "sites", type = "p")> with(dune.env, ordiellipse(dune.ca, Management,+ k<strong>in</strong>d = "se", conf = 0.95))17


4 CONSTRAINED ORDINATION●> with(dune.env, ordispider(dune.ca, Management, col = "blue"))> with(dune.env, ordihull(dune.ca, Management, col = "blue",+ lty = 2))CA2−1 0 1 2 3●●●●●●●●●●●●● ●●●●−2 −1 0 1 2CA1Correspondence analysis is a weighted ord<strong>in</strong>ation method, and <strong>vegan</strong>functions envfit and ordisurf will do weighted fitt<strong>in</strong>g, unless the userspecifies equal weights.4 Constra<strong>in</strong>ed ord<strong>in</strong>ationIn unconstra<strong>in</strong>ed ord<strong>in</strong>ation we first f<strong>in</strong>d the major compositional variation,and then relate this variation to observed environmental variation.In constra<strong>in</strong>ed ord<strong>in</strong>ation we do not want to display all or even most <strong>of</strong>the compositional variation, but only the variation that can be expla<strong>in</strong>edby the used environmental variables, or constra<strong>in</strong>ts. Constra<strong>in</strong>ed ord<strong>in</strong>ationis <strong>of</strong>ten known as “canonical” ord<strong>in</strong>ation, but this name is mislead<strong>in</strong>g:there is noth<strong>in</strong>g particularly canonical <strong>in</strong> these methods (see your favoriteDictionary for the term). The name was taken <strong>in</strong>to use, because thereis one special statistical method, canonical correlations, but these <strong>in</strong>deedare canonical: they are correlations between two matrices regarded to besymmetrically dependent on each other. The constra<strong>in</strong>ed ord<strong>in</strong>ation isnon-symmetric: we have “<strong>in</strong>dependent” variables or constra<strong>in</strong>ts and wehave “dependent” variables or the community. Constra<strong>in</strong>ed ord<strong>in</strong>ationrather is related to multivariate l<strong>in</strong>ear models.The <strong>vegan</strong> package has three constra<strong>in</strong>ed ord<strong>in</strong>ation methods whichall are constra<strong>in</strong>ed versions <strong>of</strong> basic ord<strong>in</strong>ation methods:• Constra<strong>in</strong>ed analysis <strong>of</strong> proximities (cap) <strong>in</strong> function capscale isrelated to metric scal<strong>in</strong>g (cmdscale). It can handle any dissimilaritymeasures and performs a l<strong>in</strong>ear mapp<strong>in</strong>g.• Redundancy analysis (rda) <strong>in</strong> function rda is related to pr<strong>in</strong>cipalcomponents analysis. It is based on Euclidean distances and performsl<strong>in</strong>ear mapp<strong>in</strong>g.• Constra<strong>in</strong>ed correspondence analysis (cca) <strong>in</strong> function cca is relatedto correspondence analysis. It is based on Chi-squared distancesand performs weighted l<strong>in</strong>ear mapp<strong>in</strong>g.We have already used functions rda and cca for unconstra<strong>in</strong>ed ord<strong>in</strong>ation:they will perform the basic unconstra<strong>in</strong>ed method as a special case ifconstra<strong>in</strong>ts are not used.All these three <strong>vegan</strong> functions are very similar. The follow<strong>in</strong>g examplesma<strong>in</strong>ly use cca, but other methods can be used similarly. Actually,the results are similarly structured, and they <strong>in</strong>herit properties from eachother. For historical reasons, cca is the basic method, and rda <strong>in</strong>heritsproperties from it. Function capscale <strong>in</strong>herits directly from rda, andthrough this from cca. Many functions, are common with all these methods,and there are specific functions only if the method deviates from itsancestor. In <strong>vegan</strong> version 1.17-2 the follow<strong>in</strong>g class functions are def<strong>in</strong>edfor these methods:18


4 CONSTRAINED ORDINATION 4.1 Model specification• cca: add1, alias, anova, as.mlm, bstick, calibrate, coef, deviance,drop1, eigenvals, extractAIC, fitted, goodness, model.frame, model.matrix,permutest, plot, po<strong>in</strong>ts, predict, pr<strong>in</strong>t, residuals, RsquareAdj,scores, screeplot, simulate, summary, text, weights• rda: as.mlm, biplot, coef, deviance, fitted, goodness, predict,RsquareAdj, scores, simulate, weights• capscale: fitted, pr<strong>in</strong>t, simulate.Many <strong>of</strong> these methods are <strong>in</strong>ternal functions that users rarely need.4.1 Model specificationThe recommended way <strong>of</strong> def<strong>in</strong><strong>in</strong>g a constra<strong>in</strong>ed model is to use modelformula. Formula has a special character ∼, and on its left-hand sidegives the name <strong>of</strong> the community data, and right-hand gives the equationfor constra<strong>in</strong>ts. In addition, you should give the name <strong>of</strong> the data setwhere to f<strong>in</strong>d the constra<strong>in</strong>ts. This fits a cca for varespec constra<strong>in</strong>edby soil Al, K and P:> vare.cca vare.ccaCall: cca(formula = varespec ~ Al + P + K, data =varechem)Inertia RankTotal 2.083Constra<strong>in</strong>ed 0.644 3Unconstra<strong>in</strong>ed 1.439 20Inertia is mean squared cont<strong>in</strong>gency coefficientEigenvalues for constra<strong>in</strong>ed axes:CCA1 CCA2 CCA30.362 0.170 0.113Eigenvalues for unconstra<strong>in</strong>ed axes:CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA80.3500 0.2201 0.1851 0.1551 0.1351 0.1003 0.0773 0.0537(Showed only 8 <strong>of</strong> all 20 unconstra<strong>in</strong>ed eigenvalues)The output is similar as <strong>in</strong> unconstra<strong>in</strong>ed ord<strong>in</strong>ation. Now the total<strong>in</strong>ertia is decomposed <strong>in</strong>to constra<strong>in</strong>ed and unconstra<strong>in</strong>ed components.There were three constra<strong>in</strong>ts, and the rank <strong>of</strong> constra<strong>in</strong>ed componentis three. The rank <strong>of</strong> unconstra<strong>in</strong>ed component is 20, when it used tobe 23 <strong>in</strong> the previous analysis. The rank is the same as the number <strong>of</strong>axes: you have 3 constra<strong>in</strong>ed axes and 20 unconstra<strong>in</strong>ed axes. In somecases, the ranks may be lower than the number <strong>of</strong> constra<strong>in</strong>ts: some <strong>of</strong>the constra<strong>in</strong>ts are dependent on each other, and they are aliased <strong>in</strong> theanalysis, and an <strong>in</strong>formative message is pr<strong>in</strong>ted with the result.It is very common to calculate the proportion <strong>of</strong> constra<strong>in</strong>ed <strong>in</strong>ertiafrom the total <strong>in</strong>ertia. However, total <strong>in</strong>ertia does not have a clear mean<strong>in</strong>g<strong>in</strong> cca, and the mean<strong>in</strong>g <strong>of</strong> this proportion is just as obscure. In rdathis would be the proportion <strong>of</strong> variance (or correlation). This may havea clearer mean<strong>in</strong>g, but even <strong>in</strong> this case most <strong>of</strong> the total <strong>in</strong>ertia may be19


4.1 Model specification 4 CONSTRAINED ORDINATION13random noise. It may be better to concentrate on results <strong>in</strong>stead <strong>of</strong> theseproportions.Basic plott<strong>in</strong>g works just like earlier:CCA2−2 −1 0 1 2221614 Cal.vul7Bar.lycBet.pub5216Led.palDic.fus Cla.bot Pti.cil Ich.eri 1815 Pol.com23Cla.arbCla.cri Ste.sp Vac.uliVac.myrCla.fim20 Cla.def Emp.nig Cla.ranP<strong>in</strong>.syl Dip.monDes.fleDic.pol Cla.unc Cla.graCet.islCla.ama Cla.cocVac.vitPol.pilPle.schCla.corPol.jun Poh.nut Cet.eriCla.spCla.chl 11KNep.arcPel.aphCla.steAl27193Hyl.splCla.phy42528Dic.sp12 Cla.cer210 Cet.nivP924−3 −2 −1 0 1 2CCA1−1 0 1> plot(vare.cca)have similar <strong>in</strong>terpretation as fitted vectors: the arrow po<strong>in</strong>ts to the direction<strong>of</strong> the gradient, and its length <strong>in</strong>dicates the strength <strong>of</strong> the variable<strong>in</strong> this dimensionality <strong>of</strong> solution. The vectors will be <strong>of</strong> unit length <strong>in</strong>full rank solution, but they are projected to the plane used <strong>in</strong> the plot.There is also a primitive 3D plott<strong>in</strong>g function ordiplot3d (which needsuser <strong>in</strong>teraction for f<strong>in</strong>al graphs) that shows all arrows <strong>in</strong> full length:> ordiplot3d(vare.cca, type = "h")With function ordirgl you can also <strong>in</strong>spect 3D dynamic plots that canbe sp<strong>in</strong>ned or zoomed <strong>in</strong>to with your mouse.The formula <strong>in</strong>terface works with factor variables as well:> dune.cca plot(dune.cca)> dune.cca●Call: cca(formula = dune ~ Management, data = dune.env)CCA2CCA3−3 −2 −1 0 1 2 3 4−2 −1 0 1 2●● ●●●●●● ● ●●●●●●●●●●●●3●210−1−2−3 −2 −1 0 1 2CCA11710675ManagementBF 1118Viclat2AchmilManagementHFTripra BrohorPlalan191AntodoRumaceTrirepLolper LeoautHypradPoapraBelperBrarut JunartManagementNMEmpnig Salrep Potpal AirpraElyrep PoatriElepal RanflaJunbufSagproCalcus9AlogenAgrsto3814154ManagementSFChealb Cirarv20121316−2 −1 0 1 2 3CCA1CCA2Inertia RankTotal 2.115Constra<strong>in</strong>ed 0.604 3Unconstra<strong>in</strong>ed 1.511 16Inertia is mean squared cont<strong>in</strong>gency coefficientEigenvalues for constra<strong>in</strong>ed axes:CCA1 CCA2 CCA30.319 0.182 0.103Eigenvalues for unconstra<strong>in</strong>ed axes:CA1 CA2 CA3 CA4 CA5 CA6 CA70.44737 0.20300 0.16301 0.13457 0.12940 0.09494 0.07904CA8 CA9 CA10 CA11 CA12 CA13 CA140.06526 0.05004 0.04321 0.03870 0.02385 0.01773 0.00917CA15 CA160.00796 0.00416Factor variable Management had four levels (BF, HF, NM, SF). InternallyR expressed these four levels as three contrasts (sometimes called“dummyvariables”). The applied contrasts look like this:ManagementHF ManagementNM ManagementSFBF 0 0 0SF 0 0 1HF 1 0 0NM 0 1 0We do not need but three variables to express four levels: if there isnumber one <strong>in</strong> a column, the observation belongs to that level, and ifthere is a whole l<strong>in</strong>e <strong>of</strong> zeros, the observation must belong to the omittedlevel, or the first. The basic plot function displays class centroids <strong>in</strong>stead<strong>of</strong> vectors for factors.20


4 CONSTRAINED ORDINATION 4.2 Permutation testsIn addition to these ord<strong>in</strong>ary factors, R also knows ordered factors.Variable Moisture <strong>in</strong> dune.env is def<strong>in</strong>ed as an ordered four-level factor.In this case the contrasts look different:Moisture.L Moisture.Q Moisture.C1 -0.6708 0.5 -0.22362 -0.2236 -0.5 0.67084 0.2236 -0.5 -0.67085 0.6708 0.5 0.2236R uses polynomial contrasts: the l<strong>in</strong>ear term L is equal to treat<strong>in</strong>gMoisture as a cont<strong>in</strong>uous variable, and the quadratic Q and cubic C termsshow nonl<strong>in</strong>ear features. There were four dist<strong>in</strong>ct levels, and the number<strong>of</strong> contrasts is one less, just like with ord<strong>in</strong>ary contrasts. The ord<strong>in</strong>ationconfiguration, eigenvalues or rank do not change if the factor is unorderedor ordered, but the presentation <strong>of</strong> the factor <strong>in</strong> the results may change:> vare.cca plot(vare.cca)Now plot shows both the centroids <strong>of</strong> factor levels and the contrasts.If we could change the ordered factor to a cont<strong>in</strong>uous vector, only thel<strong>in</strong>ear effect arrow would be important. If the response to the variable isnonl<strong>in</strong>ear, the quadratic (and cubic) arrows would be long as well.I have expla<strong>in</strong>ed only the simplest usage <strong>of</strong> the formula <strong>in</strong>terface. Theformula is very powerful <strong>in</strong> model specification: you can transform yourcontrasts with<strong>in</strong> the formula, you can def<strong>in</strong>e <strong>in</strong>teractions, you can usepolynomial contrasts etc. However, models with <strong>in</strong>teractions or polynomialsmay be difficult to <strong>in</strong>terpret.CCA2−3 −2 −1 0 1 21017186 1116Empnig Ranfla Potpal ElepalTripraSalrep Chealb CalcusMoisture1Moisture55 PlalanHypradViclat7AchmilAirpraBrohor Belper LolperAntodoLeoautPoapra2BrarutCirarv TrirepPoatri Agrsto1 Moisture2RumaceJunart8Moisture.LElyrepSagpro Alogen43Moisture.Q19Moisture.C9Junbuf12−2 −1 0 1 2 313Moisture4CCA1141520−1 04.2 Permutation testsThe significance <strong>of</strong> all terms together can be assessed us<strong>in</strong>g permutationtests: the dat are permuted randomly and the model is refitted. Whenconstra<strong>in</strong>ed <strong>in</strong>ertia <strong>in</strong> permutations is nearly always lower than observedconstra<strong>in</strong>ed <strong>in</strong>ertia, we say that constra<strong>in</strong>ts are significant.The easiest way <strong>of</strong> runn<strong>in</strong>g permutation tests is to use the mock anovafunction <strong>in</strong> <strong>vegan</strong>:> anova(vare.cca)Permutation test for cca under reduced modelModel: cca(formula = dune ~ Moisture, data = dune.env)Df Chisq F N.Perm Pr(>F)Model 3 0.63 2.25 199 0.005 **Residual 16 1.49---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1The Model refers to the constra<strong>in</strong>ed component, and Residual to theunconstra<strong>in</strong>ed component <strong>of</strong> the ord<strong>in</strong>ation, Chisq is the correspond<strong>in</strong>g<strong>in</strong>ertia, and Df the correspond<strong>in</strong>g rank. The test statistic F, or morecorrectly “pseudo-F ” is def<strong>in</strong>ed as their ratio. You should not pay anyattention to its numeric values or to the numbers <strong>of</strong> degrees <strong>of</strong> freedom,s<strong>in</strong>ce this “pseudo-F ” has noth<strong>in</strong>g to do with the real F , and the only wayF = 0.628/31.487/16 = 2.25421


4.2 Permutation tests 4 CONSTRAINED ORDINATIONto assess its “significance” is permutation. In simple models like the onestudied here we could directly use <strong>in</strong>ertia <strong>in</strong> test<strong>in</strong>g, but the “pseudo-F ”is needed <strong>in</strong> more complicated model <strong>in</strong>clud<strong>in</strong>g “partialled” terms.The number <strong>of</strong> permutations was not specified <strong>in</strong> the mock anovafunction. The function tries to be lazy: it cont<strong>in</strong>ues permutations only aslong as it is uncerta<strong>in</strong> whether the f<strong>in</strong>al P -value will be below or abovethe critical value (usually P = 0.05). If the observed <strong>in</strong>ertia is neverreached <strong>in</strong> permutations, the function may stop after 200 permutations,and if it is very <strong>of</strong>ten exceeded, it may stop after 100 permutations.When we are close to the critical level, the permutations may cont<strong>in</strong>ue tothousands. In this way the calculations are fast when this is possible, butthey are cont<strong>in</strong>ued longer <strong>in</strong> uncerta<strong>in</strong> cases. If you want to have a fixednumber <strong>of</strong> iterations, you must specify that <strong>in</strong> anova call or directly usethe underly<strong>in</strong>g function permutest.ccaIn addition to the overall test for all constra<strong>in</strong>ts together, we canalso analyse s<strong>in</strong>gle terms or axes by sett<strong>in</strong>g argument by. The follow<strong>in</strong>gcommand analyses all terms separately <strong>in</strong> a sequential (“Type I”) test:> mod anova(mod, by = "term", step = 200)Permutation test for cca under reduced modelTerms added sequentially (first to last)Model: cca(formula = varespec ~ Al + P + K, data = varechem)Df Chisq F N.Perm Pr(>F)Al 1 0.30 4.14 199 0.005 **P 1 0.19 2.64 199 0.005 **K 1 0.16 2.17 199 0.020 *Residual 20 1.44---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1All terms are compared aga<strong>in</strong>st the same residuals, and there is no heuristicfor the number permutations. The test is sequential, and the order<strong>of</strong> terms will <strong>in</strong>fluence the results, unless the terms are uncorrelated. Inthis case the same number <strong>of</strong> permutations will be used for all terms.The sum <strong>of</strong> test statistics (Chisq) for terms is the same as the Model teststatistic <strong>in</strong> the overall test.“Type III” tests analyse the marg<strong>in</strong>al effects when each term is elim<strong>in</strong>atedfrom the model conta<strong>in</strong><strong>in</strong>g all other terms:> anova(mod, by = "marg<strong>in</strong>", perm = 500)Permutation test for cca under reduced modelMarg<strong>in</strong>al effects <strong>of</strong> termsModel: cca(formula = varespec ~ Al + P + K, data = varechem)Df Chisq F N.Perm Pr(>F)Al 1 0.31 4.33 199 0.005 **P 1 0.17 2.34 199 0.015 *K 1 0.16 2.17 399 0.025 *Residual 20 1.44---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 122


4 CONSTRAINED ORDINATION 4.3 Model build<strong>in</strong>gThe marg<strong>in</strong>al effects are <strong>in</strong>dependent <strong>of</strong> the order <strong>of</strong> the terms, but correlatedterms will get higher (“worse”) P -values. Now the the sum <strong>of</strong> teststatistics is not equal to the Model test statistic <strong>in</strong> the overall test, unlessthe terms are uncorrelated.We can also ask for a test <strong>of</strong> <strong>in</strong>dividual axes:> anova(mod, by = "axis", perm = 1000)Permutation test for cca under reduced modelModel: cca(formula = varespec ~ Al + P + K, data = varechem)Df Chisq F N.Perm Pr(>F)CCA1 1 0.36 5.02 199 0.005 **CCA2 1 0.17 2.36 999 0.042 *CCA3 1 0.11 1.57 99 0.140Residual 20 1.44---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 14.3 Model build<strong>in</strong>gIt is very popular to perform constra<strong>in</strong>ed ord<strong>in</strong>ation us<strong>in</strong>g all availableconstra<strong>in</strong>ts simultaneously. Increas<strong>in</strong>g the number <strong>of</strong> constra<strong>in</strong>ts actuallymeans relax<strong>in</strong>g constra<strong>in</strong>ts: the ord<strong>in</strong>ation becomes more similar to theunconstra<strong>in</strong>ed one. When the rank <strong>of</strong> unconstra<strong>in</strong>ed component reducestowards zero, there are absolutely no constra<strong>in</strong>ts. However, the relaxation<strong>of</strong> constra<strong>in</strong>ts <strong>of</strong>ten happens much earlier <strong>in</strong> first ord<strong>in</strong>ation axes. If wedo not have strict constra<strong>in</strong>ts, it may be better to use unconstra<strong>in</strong>edord<strong>in</strong>ation with vector fitt<strong>in</strong>g (or surface fitt<strong>in</strong>g), which allows detection<strong>of</strong> compositional variation for which we have not observed environmentalvariables. In constra<strong>in</strong>ed ord<strong>in</strong>ation it is best to reduce the number <strong>of</strong>constra<strong>in</strong>ts to just a few, say three to five.I do not want to encourage us<strong>in</strong>g all possible environmental variablestogether as constra<strong>in</strong>ts. However, there still is a shortcut for that purpose<strong>in</strong> formula <strong>in</strong>terface:> mod1 mod1Call: cca(formula = varespec ~ N + P + K + Ca + Mg + S+ Al + Fe + Mn + Zn + Mo + Baresoil + Humdepth + pH,data = varechem)Inertia RankTotal 2.083Constra<strong>in</strong>ed 1.441 14Unconstra<strong>in</strong>ed 0.642 9Inertia is mean squared cont<strong>in</strong>gency coefficientEigenvalues for constra<strong>in</strong>ed axes:CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA70.43887 0.29178 0.16285 0.14213 0.11795 0.08903 0.07029CCA8 CCA9 CCA10 CCA11 CCA12 CCA13 CCA140.05836 0.03114 0.01329 0.00836 0.00654 0.00616 0.0047323


4.3 Model build<strong>in</strong>g 4 CONSTRAINED ORDINATIONDimension 2−2.0 −1.5 −1.0 −0.5 0.0 0.5 1.0 1.5●●●●Procrustes errors●●●●●●●●● ●●●●●●●●●●●−1 0 1 2Dimension 1Eigenvalues for unconstra<strong>in</strong>ed axes:CA1 CA2 CA3 CA4 CA5 CA6 CA70.19776 0.14193 0.10117 0.07079 0.05330 0.03330 0.01887CA8 CA90.01510 0.00949This result probably is very similar to unconstra<strong>in</strong>ed ord<strong>in</strong>ation:> plot(procrustes(cca(varespec), mod1))For heuristic purposes we should reduce the number <strong>of</strong> constra<strong>in</strong>ts t<strong>of</strong><strong>in</strong>d important environmental variables. In pr<strong>in</strong>ciple, constra<strong>in</strong>ed ord<strong>in</strong>ationonly should be used with designed a priori constra<strong>in</strong>ts. All k<strong>in</strong>d <strong>of</strong>automatic tools <strong>of</strong> model selection are dangerous: There may be severalalternative models which are nearly equally good; Small changes <strong>in</strong> datacan cause large changes <strong>in</strong> selected models; There may be no route to thebest model with the adapted strategy; The model build<strong>in</strong>g has a history:one different step <strong>in</strong> the beg<strong>in</strong>n<strong>in</strong>g may lead <strong>in</strong>to wildly different f<strong>in</strong>almodels; Significance tests are biased, because the model is selected forthe best test performance.After all these warn<strong>in</strong>gs, I show how <strong>vegan</strong> can be used to automaticallyselect constra<strong>in</strong>ts <strong>in</strong>to model us<strong>in</strong>g standard R function step. Thestep uses Akaike’s <strong>in</strong>formation criterion (aic) as the selection criterion.Aic is a penalized goodness-<strong>of</strong>-fit measure: the goodness-<strong>of</strong>-fit is basicallyderived from the residual (unconstra<strong>in</strong>ed) <strong>in</strong>ertia penalized by therank <strong>of</strong> the constra<strong>in</strong>ts. In pr<strong>in</strong>ciple aic is based on log-Likelihood thatord<strong>in</strong>ation does not have. However, a deviance function changes theunconstra<strong>in</strong>ed <strong>in</strong>ertia to Chi-squared <strong>in</strong> cca or sum <strong>of</strong> squares <strong>in</strong> rdaand capscale. This deviance is treated like sum <strong>of</strong> squares <strong>in</strong> Gaussianmodels. If we have only cont<strong>in</strong>uous (or 1 d.f.) terms, this is the same asselect<strong>in</strong>g variables by their contributions to constra<strong>in</strong>ed eigenvalues (<strong>in</strong>ertia).With factors the situation is more tricky, because factors must bepenalized by their degrees <strong>of</strong> freedom, and there is no way <strong>of</strong> know<strong>in</strong>g themagnitude <strong>of</strong> penalty. The step function may still be useful <strong>in</strong> help<strong>in</strong>gto ga<strong>in</strong> <strong>in</strong>sight <strong>in</strong>to the data, but it should not be trusted bl<strong>in</strong>dly (or atall), but only regarded as an aid <strong>in</strong> model build<strong>in</strong>g.After this longish <strong>in</strong>troduction the example: us<strong>in</strong>g step is much simplerthan expla<strong>in</strong><strong>in</strong>g how it works. We need to give the model we startwith, and the scope <strong>of</strong> possible models <strong>in</strong>spected. For this we need anotherformula trick: formula with only 1 as the constra<strong>in</strong>t def<strong>in</strong>es anunconstra<strong>in</strong>ed model. We must def<strong>in</strong>e it like this so that we can add newterms to <strong>in</strong>itially unconstra<strong>in</strong>ed model. The aic used <strong>in</strong> model build<strong>in</strong>gis not based on a firm theory, and therefore we also ask for permutationtests at each step. In ideal case, all <strong>in</strong>cluded terms should be significantand all excluded terms <strong>in</strong>significant <strong>in</strong> the f<strong>in</strong>al model. The scope mustbe given as a list a formula, but we can extract this from fitted modelsus<strong>in</strong>g function formula. The model build<strong>in</strong>g should The follow<strong>in</strong>g examplebeg<strong>in</strong>s with an unconstra<strong>in</strong>ed model mod0 and steps towards thepreviously fitted maximum model mod1:> mod0 mod


4 CONSTRAINED ORDINATION 4.3 Model build<strong>in</strong>gDf AIC F N.Perm Pr(>F)+ Al 1 128.61 3.6749 199 0.005 **+ Mn 1 128.95 3.3115 199 0.005 **+ Humdepth 1 129.24 3.0072 199 0.010 **+ Baresoil 1 129.77 2.4574 199 0.020 *+ Fe 1 129.79 2.4360 199 0.005 **+ P 1 130.03 2.1926 199 0.035 *+ Zn 1 130.30 1.9278 199 0.020 * 130.31+ Mg 1 130.35 1.8749 199 0.040 *+ K 1 130.37 1.8609 199 0.065 .+ Ca 1 130.43 1.7959 199 0.065 .+ pH 1 130.57 1.6560 199 0.090 .+ S 1 130.72 1.5114 199 0.090 .+ N 1 130.77 1.4644 199 0.135+ Mo 1 131.19 1.0561 99 0.490---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Step: AIC=128.61varespec ~ AlDf AIC F N.Perm Pr(>F)+ P 1 127.91 2.5001 199 0.010 **+ K 1 128.09 2.3240 199 0.005 **+ S 1 128.26 2.1596 199 0.005 **+ Zn 1 128.44 1.9851 199 0.035 *+ Mn 1 128.53 1.8945 199 0.040 * 128.61+ Mg 1 128.70 1.7379 199 0.125+ N 1 128.85 1.5900 199 0.080 .+ Baresoil 1 128.88 1.5670 199 0.095 .+ Ca 1 129.04 1.4180 99 0.140+ Humdepth 1 129.08 1.3814 99 0.250+ Mo 1 129.50 0.9884 99 0.460+ pH 1 129.63 0.8753 99 0.520+ Fe 1 130.02 0.5222 99 0.850- Al 1 130.31 3.6749 199 0.005 **---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Step: AIC=127.91varespec ~ Al + PDf AIC F N.Perm Pr(>F)+ K 1 127.44 2.1688 199 0.040 * 127.91+ Baresoil 1 127.99 1.6606 199 0.065 .+ N 1 128.11 1.5543 99 0.140+ S 1 128.36 1.3351 99 0.230+ Mn 1 128.44 1.2641 99 0.180+ Zn 1 128.51 1.2002 99 0.300+ Humdepth 1 128.56 1.1536 99 0.39025


4.3 Model build<strong>in</strong>g 4 CONSTRAINED ORDINATION- P 1 128.61 2.5001 199 0.010 **+ Mo 1 128.75 0.9837 99 0.400+ Mg 1 128.79 0.9555 99 0.470+ pH 1 128.82 0.9247 99 0.510+ Fe 1 129.28 0.5253 99 0.850+ Ca 1 129.36 0.4648 99 0.890- Al 1 130.03 3.9401 199 0.005 **---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Step: AIC=127.44varespec ~ Al + P + KDf AIC F N.Perm Pr(>F) 127.44+ N 1 127.59 1.5148 99 0.140+ Baresoil 1 127.67 1.4544 99 0.180+ Zn 1 127.84 1.3067 99 0.200+ S 1 127.89 1.2604 99 0.250- K 1 127.91 2.1688 199 0.050 *+ Mo 1 127.92 1.2350 99 0.280- P 1 128.09 2.3362 199 0.010 **+ Mg 1 128.17 1.0300 99 0.390+ Mn 1 128.34 0.8879 99 0.460+ Humdepth 1 128.44 0.8056 99 0.600+ Fe 1 128.79 0.5215 99 0.930+ pH 1 128.81 0.5067 99 0.830+ Ca 1 128.89 0.4358 99 0.920- Al 1 130.14 4.3340 199 0.005 **---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1> modCall: cca(formula = varespec ~ Al + P + K, data =varechem)Inertia RankTotal 2.083Constra<strong>in</strong>ed 0.644 3Unconstra<strong>in</strong>ed 1.439 20Inertia is mean squared cont<strong>in</strong>gency coefficientEigenvalues for constra<strong>in</strong>ed axes:CCA1 CCA2 CCA30.362 0.170 0.113Eigenvalues for unconstra<strong>in</strong>ed axes:CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA80.3500 0.2201 0.1851 0.1551 0.1351 0.1003 0.0773 0.0537(Showed only 8 <strong>of</strong> all 20 unconstra<strong>in</strong>ed eigenvalues)We ended up with the same familiar model we have been us<strong>in</strong>g all the time(and now you know the reason why this model was used <strong>in</strong> the first place).The aic was based on deviance, and penalty for each added parameter26


4 CONSTRAINED ORDINATION 4.3 Model build<strong>in</strong>gwas 2 per degree <strong>of</strong> freedom. At every step the aic was evaluated for allpossible additions (+) and removals (-), and the variables are listed <strong>in</strong>the order <strong>of</strong> aic. The stepp<strong>in</strong>g stops when or the current modelis at the top.Model build<strong>in</strong>g with step is fragile, and the strategy <strong>of</strong> model build<strong>in</strong>gcan change the f<strong>in</strong>al model. If we start with the largest model (mod1),the f<strong>in</strong>al model will be different:> modb modbCall: cca(formula = varespec ~ P + K + Mg + S + Mn + Mo+ Baresoil + Humdepth, data = varechem)Inertia RankTotal 2.083Constra<strong>in</strong>ed 1.117 8Unconstra<strong>in</strong>ed 0.967 15Inertia is mean squared cont<strong>in</strong>gency coefficientEigenvalues for constra<strong>in</strong>ed axes:CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA7 CCA80.4007 0.2488 0.1488 0.1266 0.0875 0.0661 0.0250 0.0130Eigenvalues for unconstra<strong>in</strong>ed axes:CA1 CA2 CA3 CA4 CA5 CA6 CA70.25821 0.18813 0.11927 0.10204 0.08791 0.06085 0.04461CA8 CA9 CA10 CA11 CA12 CA13 CA140.02782 0.02691 0.01646 0.01364 0.00823 0.00655 0.00365CA150.00238The aic <strong>of</strong> this model is 127.89 which is higher (worse) than reached<strong>in</strong> forward selection (127.44). We supressed trac<strong>in</strong>g to save some pages<strong>of</strong> output, but step adds its history <strong>in</strong> the result:> modb$anovaStep Df Deviance Resid. Df Resid. Dev AIC1 NA NA -15 1551 130.12 - Fe 1 115.2 -14 1667 129.83 - Al 1 106.0 -13 1773 129.34 - N 1 117.5 -12 1890 128.85 - pH 1 140.4 -11 2031 128.56 - Ca 1 141.2 -10 2172 128.17 - Zn 1 165.3 -9 2337 127.9Variable Al was the first to be selected <strong>in</strong> the model <strong>in</strong> forward selection,but it was the second to be removed <strong>in</strong> backward elim<strong>in</strong>ation.Variable Al is strongly correlated with many other explanatory variables.This is obvious when look<strong>in</strong>g at the variance <strong>in</strong>flation factors (vif) <strong>in</strong> thefull model mod1:> vif.cca(mod1)N P K Ca Mg S Al1.982 6.029 12.009 9.926 9.811 18.379 21.19327


4.4 L<strong>in</strong>ear comb<strong>in</strong>ations and weighted averages 4 CONSTRAINED ORDINATIONFe Mn Zn Mo Baresoil Humdepth pH9.128 5.380 7.740 4.320 2.254 6.013 7.389A common rule <strong>of</strong> thumb is that vif > 10 <strong>in</strong>dicates that a variable isstrongly dependent on others and does not have <strong>in</strong>dependent <strong>in</strong>formation.On the other hand, it may not be the variable that should be removed,but alternatively some other variables may be removed. The vifs wereall modest <strong>in</strong> model found by forward selection, <strong>in</strong>clud<strong>in</strong>g Al:> vif.cca(mod)Al P K1.012 2.365 2.3794.4 L<strong>in</strong>ear comb<strong>in</strong>ations and weighted averagesThere are two k<strong>in</strong>d <strong>of</strong> site scores <strong>in</strong> constra<strong>in</strong>ed ord<strong>in</strong>ations:1. L<strong>in</strong>ear comb<strong>in</strong>ation scores lc which are l<strong>in</strong>ear comb<strong>in</strong>ations <strong>of</strong> constra<strong>in</strong><strong>in</strong>gvariables.2. Weighted averages scores wa which are weighted averages <strong>of</strong> speciesscores.These two scores are as similar as possible, and their (weighted) correlationis called the species–environment correlation:> spenvcor(mod)CCA1 CCA2 CCA30.8555 0.8133 0.8793Correlation coefficient is very sensitive to s<strong>in</strong>gle extreme values, like seemsto happen <strong>in</strong> the example above where axis 3 has the “best” correlationsimply because it has some extreme po<strong>in</strong>ts, and eigenvalue is a moreappropriate measure <strong>of</strong> similarity between lc and wa socres.The op<strong>in</strong>ions are divided on us<strong>in</strong>g lc or wa as primary results <strong>in</strong> ord<strong>in</strong>ationgraphics. The <strong>vegan</strong> package prefers wa scores, whereas the majorcommercial programme for cca prefers lc scores. The <strong>vegan</strong> packagecomes with a separate document (“<strong>vegan</strong> FAQ”) which studies the issue<strong>in</strong> more detail, but I will briefly discuss the subject here also, and showhow you can circumvent my decisions.The practical reason to prefer wa scores is that they are more robustaga<strong>in</strong>st random error <strong>in</strong> environmental variables. All ecological observationshave random error, and therefore it is better to use scores thatare resistant to this variation. Another po<strong>in</strong>t is that I see lc scores asconstra<strong>in</strong>ts: the scores are dependent only on environmental variables,and community composition does not <strong>in</strong>fluence them. The wa scoresare based on community composition, but so that they are as similar aspossible to the constra<strong>in</strong>ts. This duality is particularly clear when us<strong>in</strong>ga s<strong>in</strong>gle factor variable as constra<strong>in</strong>t: the lc scores are constant with<strong>in</strong>each level <strong>of</strong> the factor and fall <strong>in</strong> the same po<strong>in</strong>t. The wa scores showhow well we can predict the factor level from community composition.The <strong>vegan</strong> package has a graphical function ordispider which (amongother alternatives) will comb<strong>in</strong>e wa scores to the correspond<strong>in</strong>g lc score.With a s<strong>in</strong>gle factor constra<strong>in</strong>t:28


4 CONSTRAINED ORDINATION 4.5 Biplot arrows and environmental calibration> dune.cca plot(dune.cca, display = c("lc", "wa"), type = "p")> ordispider(dune.cca, col = "blue")The <strong>in</strong>terpretation is similar as <strong>in</strong> discrim<strong>in</strong>ant analysis: lc scores givethe predicted class centroids, and wa scores give the predicted values.For dist<strong>in</strong>ct classes, there is no overlap among groups. In general, thelength <strong>of</strong> ordispider segments is a visual image <strong>of</strong> species–environmentcorrelation.4.5 Biplot arrows and environmental calibrationBiplot arrows are an essential part <strong>of</strong> constra<strong>in</strong>ed ord<strong>in</strong>ation plots. Thearrows are based on (weighted) correlation <strong>of</strong> lc scores and environmentalvariables. They are scaled to unit length <strong>in</strong> the constra<strong>in</strong>ed ord<strong>in</strong>ation <strong>of</strong>full rank. When these arrows are projected onto 2D ord<strong>in</strong>ation plot, theylook shorter if they go <strong>of</strong>f the plane.In <strong>vegan</strong> the biplot arrows are always scaled similarly irrespective <strong>of</strong>scal<strong>in</strong>g <strong>of</strong> sites or species. With default scal<strong>in</strong>g = 2, the biplot arrowshave optimal relation to sites, but with scal<strong>in</strong>g = 1 they rather arerelated to species.The standard <strong>in</strong>terpretation <strong>of</strong> biplot arrows is that a site should beperpendicularly projected onto the arrow to predict the value <strong>of</strong> the variable.The arrow starts from the (weighted) mean <strong>of</strong> the environmentalvariable, and the values <strong>in</strong>crease towards the arrow head, and decrease tothe opposite direction. Then we still should figure out the unit <strong>of</strong> change.Function calibrate.cca performs this automatically <strong>in</strong> <strong>vegan</strong>. Let us<strong>in</strong>spect the result <strong>of</strong> the step function with three constra<strong>in</strong>ts:CCA2−2 −1 0 1 2●●●●●●●●●●●●●●●●●●●●−2 −1 0 1 2 3CCA1> pred head(pred)Al P K18 103.219 25.64 80.5715 30.661 47.25 190.9024 32.105 72.80 208.3427 7.178 64.44 241.8923 14.321 38.50 125.7319 136.568 54.39 182.60Actually, this is not based on biplot arrows, but on regression coefficientsused <strong>in</strong>ternally <strong>in</strong> constra<strong>in</strong>ed ord<strong>in</strong>ation. Biplot arrows should only beseen as a visual approximation. The fitt<strong>in</strong>g is done <strong>in</strong> full constra<strong>in</strong>ed rankas default and for all constra<strong>in</strong>ts simultaneously. The example draws aresidual plot <strong>of</strong> predictions:> with(varechem, plot(Al, pred[, "Al"] - Al, ylab = "Prediction Error"))> abl<strong>in</strong>e(h = 0, col = "grey")The <strong>vegan</strong> package provides function ordisurf which is based ongam <strong>in</strong> the mgcv package, and can automatically detect the degree <strong>of</strong>smoothness needed, and can be used to check the l<strong>in</strong>earity hypothesis <strong>of</strong>the biplot method. Function performs weighted fitt<strong>in</strong>g, and the modelshould be consistent with the one used <strong>in</strong> arrow fitt<strong>in</strong>g. Alum<strong>in</strong>ium wasthe most important <strong>of</strong> three constra<strong>in</strong>ts <strong>in</strong> our example. Now we shouldfit the model to the lc scores, just like the arrows:Prediction Error−150 −100 −50 0 50 100 150●●●●●●●●●●●●●●●●●●●●●0 100 200 300 400Al●29


4.6 Conditioned or partial models 4 CONSTRAINED ORDINATION1313> plot(mod, display = c("bp", "wa", "lc"))> ef dune.cca plot(dune.cca)> dune.ccaCall: cca(formula = dune ~ Management +Condition(Moisture), data = dune.env)CCA2−2 −1 0 1 265ManagementHFTripra7RumaceAntodoJunart Plalan 915810AirpraCirarv1916 Poatri ElyrepJunbufPoapraAchmil20Agrsto Lolper Elepal Ranfla BrarutTrirep Leoaut ManagementNMEmpnig PotpalAlogen Sagpro BrohorBelper Calcus Hyprad Salrep13ManagementSF34 12Chealb14Viclat1 ManagementBF21811−2 −1 0 1 2 3CCA117Inertia RankTotal 2.115Conditional 0.628 3Constra<strong>in</strong>ed 0.374 3Unconstra<strong>in</strong>ed 1.113 13Inertia is mean squared cont<strong>in</strong>gency coefficientEigenvalues for constra<strong>in</strong>ed axes:CCA1 CCA2 CCA30.2278 0.0849 0.0614Eigenvalues for unconstra<strong>in</strong>ed axes:CA1 CA2 CA3 CA4 CA5 CA6 CA70.35040 0.15206 0.12508 0.10984 0.09221 0.07711 0.05944CA8 CA9 CA10 CA11 CA12 CA130.04776 0.03696 0.02227 0.02070 0.01083 0.00825Now the total <strong>in</strong>ertia is decomposed <strong>in</strong>to three components: <strong>in</strong>ertia expla<strong>in</strong>edby conditions, <strong>in</strong>ertia expla<strong>in</strong>ed by constra<strong>in</strong>ts and the rema<strong>in</strong><strong>in</strong>g30


4 CONSTRAINED ORDINATION 4.6 Conditioned or partial modelsunconstra<strong>in</strong>ed <strong>in</strong>ertia. We previously fitted a model with Managementas the only constra<strong>in</strong>t, and <strong>in</strong> that case constra<strong>in</strong>ed <strong>in</strong>ertia was clearlyhigher than now. It seems that different Management was practised <strong>in</strong>different natural conditions, and the variation we previously attributedto Management may be due to Moisture.We can perform permutation tests for Management <strong>in</strong> conditionedmodel, and Management alone:> anova(dune.cca, perm.max = 2000)Permutation test for cca under reduced modelModel: cca(formula = dune ~ Management + Condition(Moisture), data = dune.env)Df Chisq F N.Perm Pr(>F)Model 3 0.37 1.46 1799 0.037 *Residual 13 1.11---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1> anova(cca(dune ~ Management, dune.env))Permutation test for cca under reduced modelModel: cca(formula = dune ~ Management, data = dune.env)Df Chisq F N.Perm Pr(>F)Model 3 0.60 2.13 199 0.01 **Residual 16 1.51---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Inspected alone, Management seemed to be very significant, but the situationis much less clear after remov<strong>in</strong>g the variation due to Moisture.The anova function (like any permutation test <strong>in</strong> <strong>vegan</strong>) can be restrictedso that permutation are made only with<strong>in</strong> strata or with<strong>in</strong> alevel <strong>of</strong> a factor variable:> with(dune.env, anova(dune.cca, strata = Moisture))Permutation test for cca under reduced modelPermutations stratified with<strong>in</strong> 'Moisture'Model: cca(formula = dune ~ Management + Condition(Moisture), data = dune.env)Df Chisq F N.Perm Pr(>F)Model 3 0.37 1.46 199 0.01 **Residual 13 1.11---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Conditioned or partial models are sometimes used for decomposition<strong>of</strong> <strong>in</strong>ertia <strong>in</strong>to various components attributed to different sets <strong>of</strong> environmentalvariables. In some cases this gives mean<strong>in</strong>gful results, but thegroups <strong>of</strong> environmental variables should be non-l<strong>in</strong>early <strong>in</strong>dependent forunbiased decomposition. If the groups <strong>of</strong> environmental variables havepolynomial dependencies, some <strong>of</strong> the components <strong>of</strong> <strong>in</strong>ertia may evenbecome negative (that should be impossible). That k<strong>in</strong>d <strong>of</strong> higher-orderdependencies are almost certa<strong>in</strong> to appear with high number <strong>of</strong> variablesand high number <strong>of</strong> groups. However, varpart performs decomposition<strong>of</strong> rda models among two to four components.31


5 DISSIMILARITIES AND ENVIRONMENT5 Dissimilarities and environmentWe already discussed environmental <strong>in</strong>terpretation <strong>of</strong> ord<strong>in</strong>ation and environmentallyconstra<strong>in</strong>ed ord<strong>in</strong>ation. These both reduce the variation <strong>in</strong>toan ord<strong>in</strong>ation space, and ma<strong>in</strong>ly <strong>in</strong>spect the first dimensions. Sometimeswe may wish to analyse vegetation–environment relationships without ord<strong>in</strong>ation,or <strong>in</strong> full space. Typically these methods use the dissimilaritymatrix <strong>in</strong> analysis. The recommended method <strong>in</strong> <strong>vegan</strong> is adonis whichimplements a multivariate analysis <strong>of</strong> variances us<strong>in</strong>g distance matrices.Function adonis can handle both cont<strong>in</strong>uous and factor predictors. Othermethods <strong>in</strong> <strong>vegan</strong> <strong>in</strong>clude multiresponse permutation procedure (mrpp)and analysis <strong>of</strong> similarities (anosim). Both <strong>of</strong> these handle only classpredictors, and they are less robust than adonis.5.1 adonis: <strong>Multivariate</strong> ANOVA based on dissimilaritiesS =kX zz =[log(2) − log(2a + b + c)+ log(a + b + c)]/ log(2)Function adonis partitions dissimilarities for the sources <strong>of</strong> variation, anduses permutation tests to <strong>in</strong>spect the significances <strong>of</strong> those partitions.With Euclidean distances the results are similar as <strong>in</strong> rda and its anovapermutation tests, but adonis can handle any dissimilarity objects.The example uses adonis to study beta diversity between Managementclasses <strong>in</strong> the dune meadow data. We def<strong>in</strong>e beta diversity as theslope <strong>of</strong> species-area curve, or the exponent z <strong>of</strong> the Arrhenius modelwhere the number <strong>of</strong> species S is dependent on the size X <strong>of</strong> the studyarea. For pairwise comparison <strong>of</strong> sites the slope z can be found from thenumber <strong>of</strong> species shared between two sites (a) and the number <strong>of</strong> speciesunique to each sites (b and c). It is commonly regarded that z ≈ 0.3implies random sampl<strong>in</strong>g variability, and only higher values mean realsystematic differences. The Arrhenius z can be directly found with functionbetadiver that also provided many other <strong>in</strong>dices <strong>of</strong> pairwise betadiversity.> betad adonis(betad ~ Management, dune.env, perm = 200)Call:adonis(formula = betad ~ Management, data = dune.env, permutations = 200)Df SumsOfSqs MeanSqs F.Model R2 Pr(>F)Management 3.000 1.236 0.412 2.362 0.31 0.01 **Residuals 16.000 2.790 0.174 0.69Total 19.000 4.026 1.00---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1The models can be more complicated, and sequential test <strong>of</strong> permutationalANOVA is performed if there are several parameters:> adonis(betad ~ A1 * Management, dune.env, perm = 200)32


5 DISSIMILARITIES AND ENVIRONMENT 5.2 Homogeneity <strong>of</strong> groups and beta diversityCall:adonis(formula = betad ~ A1 * Management, data = dune.env, permutations = 200)Df SumsOfSqs MeanSqs F.Model R2 Pr(>F)A1 1.000 0.655 0.655 4.134 0.16 0.005 **Management 3.000 1.001 0.334 2.107 0.25 0.045 *A1:Management 3.000 0.469 0.156 0.987 0.12 0.438Residuals 12.000 1.901 0.158 0.47Total 19.000 4.026 1.00---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 15.2 Homogeneity <strong>of</strong> groups and beta diversityFunction adonis studied the differences <strong>in</strong> the group means, but functionbetadisper studies the differences <strong>in</strong> group homogeneities. Functionadonis was analogous to multivariate analysis <strong>of</strong> variance, and betadisperis analogous to Levene’s test <strong>of</strong> the equality <strong>of</strong> variances.The example cont<strong>in</strong>ues the analysis <strong>of</strong> the previous section and <strong>in</strong>spectsthe beta diversity. The function can only use one factor as an<strong>in</strong>dependent variable, and it does not know the formula <strong>in</strong>terface, so thatwe need to attach the data frame or use with to make the factor visibleto the function:> mod modHomogeneity <strong>of</strong> multivariate dispersionsCall: betadisper(d = betad, group = Management)No. <strong>of</strong> Positive Eigenvalues: 12No. <strong>of</strong> Negative Eigenvalues: 7Average distance to centroid:BF HF NM SF0.260 0.257 0.442 0.367Eigenvalues for PCoA axes:PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 PCoA91.655 0.887 0.533 0.374 0.287 0.224 0.161 0.081 0.065PCoA10 PCoA11 PCoA12 PCoA13 PCoA14 PCoA15 PCoA16 PCoA17 PCoA180.035 0.018 0.004 -0.004 -0.019 -0.037 -0.043 -0.054 -0.060PCoA19-0.083The function has plot and boxplot methods for graphical display.PCoA 2−0.2 0.0 0.2 0.4●●●●●mod●●> plot(mod)> boxplot(mod)The significance <strong>of</strong> the fitted model can be analysed either us<strong>in</strong>g standardparametric anova or permutation tests (permutest):−0.2 0.0 0.2 0.4PCoA 1method = "beta.z"> anova(mod)<strong>Analysis</strong> <strong>of</strong> Variance Table33Distance to centroid0.1 0.2 0.3 0.4 0.5 0.6BF HF NM SF


5.3 Mantel test 5 DISSIMILARITIES AND ENVIRONMENTResponse: DistancesDf Sum Sq Mean Sq F value Pr(>F)Groups 3 0.120 0.0399 1.7 0.21Residuals 16 0.374 0.0234> permutest(mod)Permutation test for homogeneity <strong>of</strong> multivariatedispersionsNo. <strong>of</strong> permutations: 999Permutation type: freePermutations are unstratifiedMirrored permutations?: NoUse same permutation with<strong>in</strong> strata?: NoResponse: DistancesDf Sum Sq Mean Sq F N.Perm Pr(>F)Groups 3 0.120 0.0399 1.7 999 0.20Residuals 16 0.374 0.0234Moreover, it is possible to analyse pairwise differences between groupsus<strong>in</strong>g parametric Tukey’s HSD test:> TukeyHSD(mod)Tukey multiple comparisons <strong>of</strong> means95% family-wise confidence levelFit: aov(formula = distances ~ group, data = df)$groupdiff lwr upr p adjHF-BF -0.003039 -0.32253 0.3165 1.0000NM-BF 0.181909 -0.12744 0.4913 0.3643SF-BF 0.106716 -0.20263 0.4161 0.7588NM-HF 0.184948 -0.07996 0.4499 0.2298SF-HF 0.109755 -0.15515 0.3747 0.6443SF-NM -0.075193 -0.32777 0.1774 0.82915.3 Mantel testMantel test compares two sets <strong>of</strong> dissimilarities. Basically, it is the correlationbetween dissimilarity entries. As there are N(N − 1)/2 dissimilaritiesamong N objects, normal significance tests are not applicable.Mantel developed asymptotic test statistics, but <strong>vegan</strong> function manteluses permutation tests.In this example we study how well the lichen pastures (varespec) correspondto the environment. We have already used vector fitt<strong>in</strong>g after ord<strong>in</strong>ation.However, the ord<strong>in</strong>ation and environment may be non-l<strong>in</strong>earlyrelated, and we try now with function mantel. We first perform a pca <strong>of</strong>environmental variables, and then compute dissimilarities for first pr<strong>in</strong>cipalcomponents. We use standard R function prcomp, but pr<strong>in</strong>comp orrda will work as well. Function scores <strong>in</strong> <strong>vegan</strong> will work with all thesemethods. The follow<strong>in</strong>g uses the same standardizations for communitydissimilarities as previously used <strong>in</strong> metaMDS.34


5 DISSIMILARITIES AND ENVIRONMENT 5.4 Protest: Procrustes test> pc pc edis vare.dis mantel(vare.dis, edis)Mantel statistic based on Pearson's product-moment correlationCall:mantel(xdis = vare.dis, ydis = edis)Mantel statistic r: 0.381Significance: 0.001Empirical upper confidence limits <strong>of</strong> r:90% 95% 97.5% 99%0.150 0.185 0.221 0.261Based on 999 permutationsWe could use a selection <strong>of</strong> environmental variables <strong>in</strong> pca, or we coulduse standardized environmental variables directly without pca — tastesvary. Function bioenv gives an <strong>in</strong>trigu<strong>in</strong>g alternative for select<strong>in</strong>g optimalsubsets for compar<strong>in</strong>g ord<strong>in</strong>ation and environment. There also is a partialMantel test where we can remove the <strong>in</strong>fluence <strong>of</strong> third set dissimilaritiesfrom the analysis, but its results <strong>of</strong>ten are difficult to <strong>in</strong>terpret.Function mantel does not have diagnostic plot functions, but you candirectly plot two dissimilarity matrices aga<strong>in</strong>st each other:> plot(vare.dis, edis)Everyth<strong>in</strong>g is O.K. if the relationship is more or less monotonous, or evenl<strong>in</strong>ear and positive. In spatial models we even may observe a hump which<strong>in</strong>dicates spatial aggregation.edis2 4 6 8●●●●●●●●●●●●●●●●●●●●●●●●●● ●●●● ●●●●●● ● ●●●●●● ●●●●●●●● ● ● ●●●● ●● ●●● ● ●●● ●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ●●● ●●●●●●●●●●●●●●●●●● ●●● ● ● ●●● ●●●●●●●●●●●●● ●●●●●●●●● ●●●● ●●●●●● ●● ●●●●●●● ●●●●●●● ●●●●●●●●●●●●● ●●●● ●●●●●●●●●●0.2 0.3 0.4 0.5 0.6 0.7vare.dis●●●●●●●●●●●●●●●5.4 Protest: Procrustes testProcrustes test or protest compares two ord<strong>in</strong>ations us<strong>in</strong>g symmetricProcrustes analysis. It is an alternative to Mantel tests, but uses reducedspace <strong>in</strong>stead <strong>of</strong> complete dissimilarity matrices. We can repeat the previousanalysis, but now with the solution <strong>of</strong> metaMDS and two first pr<strong>in</strong>cipalcomponents <strong>of</strong> the environmental analysis:> pc pro plot(pro)> proCall:protest(X = vare.mds, Y = pc)Correlation <strong>in</strong> a symmetric Procrustes rotation: 0.683Significance: 0.001Based on 1000 permutations.Dimension 2−0.2 −0.1 0.0 0.1 0.2●●●●●Procrustes errors●●●●●●●●●●●●●●●●●●The significance is assessed by permutation tests. The statistic is nowProcrustes correlation r derived from the symmetric Procrustes residualm 2 . The correlation is clearly higher than the Mantel correlation−0.2 −0.1 0.0 0.1 0.2 0.3Dimension 135r = √ 1 − m 2


6 CLASSIFICATIONfor the correspond<strong>in</strong>g dissimilarities. In lower number <strong>of</strong> dimensions weremove noise from the data which may expla<strong>in</strong> higher correlations (aswell as different methods <strong>of</strong> calculat<strong>in</strong>g the correlation). However, bothmethods are about as significant. Significance <strong>of</strong>ten is not a significantconcept: even small deviations from randomness may be highly significant<strong>in</strong> large data sets. Function protest provides graphical presentations(“Procrustes superimposition plot”) which may be more useful <strong>in</strong>evaluat<strong>in</strong>g the congruence between configurations.Protest (as ord<strong>in</strong>ary Procrustes analysis) is <strong>of</strong>ten used <strong>in</strong> assess<strong>in</strong>gsimilarities between different community ord<strong>in</strong>ations. This is known asanalysis <strong>of</strong> congruence.6 ClassificationThe <strong>vegan</strong> ma<strong>in</strong>ly is a package for ord<strong>in</strong>ation and diversity analysis, andthere is only a scanty support to classification. There are several other Rpackages with more extensive classification functions. Among communityecological packages, labdsv package by Dave Roberts is particularly strong<strong>in</strong> classification functions.This chapter describes perform<strong>in</strong>g simple classification tasks <strong>in</strong> communityecology that are sufficient to many community ecologists.Cluster DendrogramHeightHeight0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.550.2 0.4 0.6 0.8 1.0171917191141118161152021011181312210dishclust (*, "s<strong>in</strong>gle")Cluster Dendrogram513126743567148916431520896.1 Cluster analysisHierarchic cluster<strong>in</strong>g can be perfomed us<strong>in</strong>g standard R function hclust.In addition, there are several other cluster<strong>in</strong>g packages, some <strong>of</strong> whichmay be compatible with hclust. Function hclust needs a dissimilaritiesas <strong>in</strong>put.Function hclust provides several alternative cluster<strong>in</strong>g strategies. Incommunity ecology, most popular are s<strong>in</strong>gle l<strong>in</strong>kage a.k.a. nearest neighbour,complete l<strong>in</strong>kage a.k.a. furthest neighbour, and various brands <strong>of</strong>average l<strong>in</strong>kage methods. These are best illustrated with examples:> dis clus plot(clus)Some people prefer s<strong>in</strong>gle l<strong>in</strong>kage, because it is conceptually related tom<strong>in</strong>imum spann<strong>in</strong>g tree which nicely can be represented <strong>in</strong> ord<strong>in</strong>ations,and it is able to f<strong>in</strong>d discont<strong>in</strong>uities <strong>in</strong> the data. However, s<strong>in</strong>gle l<strong>in</strong>kageis prone to cha<strong>in</strong> data so that s<strong>in</strong>gle sites are jo<strong>in</strong>ed to large clusters.> cluc plot(cluc)Some people prefer complete l<strong>in</strong>kage because it makes compact clusters.However, this is <strong>in</strong> part an artefact <strong>of</strong> the method: the clusters are notallowed to grow, because the complete l<strong>in</strong>kage criterion would be violated.> clua plot(clua)dishclust (*, "complete")36


6 CLASSIFICATION 6.2 Display and <strong>in</strong>terpretation <strong>of</strong> classesSome people (I <strong>in</strong>cluded) prefer average l<strong>in</strong>kage cluster<strong>in</strong>g, because itseems to be a compromise between the previous two extremes, and moreneutral <strong>in</strong> group<strong>in</strong>g. There are several alternative methods loosely connectedto “average l<strong>in</strong>kage” family. Ward’s method seems to be popular <strong>in</strong>publications. It approaches complete l<strong>in</strong>kage <strong>in</strong> its attempt to m<strong>in</strong>imizevariances <strong>in</strong> agglomeration. The default "average" method is the one<strong>of</strong>ten known as upgma which was popular <strong>in</strong> old-time genetics.All these cluster<strong>in</strong>g methods are agglomerative. They start with comb<strong>in</strong><strong>in</strong>gtwo most similar sites to each other. Then they proceed by comb<strong>in</strong><strong>in</strong>gpo<strong>in</strong>ts to po<strong>in</strong>ts or to groups, or groups to groups. The fusion criteriavary. The vertical axis <strong>in</strong> all graphs shows the level <strong>of</strong> fusion. The numbersvary among methods, but all are based on the same dissimilaritieswith range:> range(dis)[1] 0.2273 1.0000The first fusion is between the same two most similar sites <strong>in</strong> all examples,and at the same m<strong>in</strong>imum dissimilarity. In complete l<strong>in</strong>kage the lastfusion comb<strong>in</strong>es the two most dissimilar sites, and it is at the maximumdissimilarity. In s<strong>in</strong>gle l<strong>in</strong>kage the fusion level always is at the smallestgap between groups, and the reported levels are much lower than withcomplete l<strong>in</strong>kage. Average l<strong>in</strong>kage makes fusions between group centrepo<strong>in</strong>ts, and its fusion levels are between the previous two trees. Theestimated dissimilarity between two po<strong>in</strong>ts is the level where they arefused <strong>in</strong> a tree. Function cophenetic f<strong>in</strong>ds this estimated dissimilarityfrom a tree for evey pair <strong>of</strong> po<strong>in</strong>ts – the name <strong>of</strong> the function reflectsthe history <strong>of</strong> cluster<strong>in</strong>g <strong>in</strong> numerical taxonomy. Cophenetic correlationmeasures the similarity between orig<strong>in</strong>al dissimilarities and dissimilaritiesestimated from the tree. For our three example methods:> cor(dis, cophenetic(clus))Height0.2 0.3 0.4 0.5 0.6 0.7 0.8141615201719Cluster Dendrogram113128dishclust (*, "average")4391118521067[1] 0.6602> cor(dis, cophenetic(cluc))[1] 0.6707> cor(dis, cophenetic(clua))[1] 0.8169Approximat<strong>in</strong>g dissimilarities is the same task that ord<strong>in</strong>ations perform,and average l<strong>in</strong>kage is the best performer.6.2 Display and <strong>in</strong>terpretation <strong>of</strong> classesCluster analysis performs a hierarchic cluster<strong>in</strong>g, and its results can be<strong>in</strong>spected at as many levels as there are po<strong>in</strong>ts: the extremes are thatevery po<strong>in</strong>t is <strong>in</strong> its private cluster, or that all po<strong>in</strong>ts belong to the samecluster. We commonly want to <strong>in</strong>spect cluster<strong>in</strong>g at a certa<strong>in</strong> level, as anon-hierarchic system <strong>of</strong> certa<strong>in</strong> number <strong>of</strong> clusters. The flatten<strong>in</strong>g <strong>of</strong> thecluster<strong>in</strong>g happens by cutt<strong>in</strong>g the tree at some fusion level so that we geta desired number <strong>of</strong> clusters.Base R provides function rect.hclust to visualize the cutt<strong>in</strong>g, andfunction cutree to make a classification vector with certa<strong>in</strong> number <strong>of</strong>classes:37


6.2 Display and <strong>in</strong>terpretation <strong>of</strong> classes 6 CLASSIFICATIONHeight0.2 0.4 0.6 0.8 1.0171911181210Cluster Dendrogram5131267dishclust (*, "complete")431489161520> plot(cluc)> rect.hclust(cluc, 3)> grp boxplot(A1 ~ grp, data = dune.env, notch = TRUE)If we wish, we may use all normal statistical methods with factors, suchas functions lm or aov for formal test<strong>in</strong>g <strong>of</strong> “significance” <strong>of</strong> clusters.Classification can be compared aga<strong>in</strong>st external factor variables as well.However, <strong>vegan</strong> does not provide any tools for this. It may be best tosee the labdsv package and its <strong>tutorial</strong> for this purpose.The cluster<strong>in</strong>g results can be displayed <strong>in</strong> ord<strong>in</strong>ation diagrams. Allusual <strong>vegan</strong> functions for factors can be used: ordihull, ordispider,and ordiellipse. We shall see only the first as an example:4 6 8 10●●1 2 3> ord plot(ord, display = "sites")> ordihull(ord, grp, lty = 2, col = "red")It is said sometimes that overlay<strong>in</strong>g classification <strong>in</strong> ord<strong>in</strong>ation can beused as a cross-check: if the clusters look dist<strong>in</strong>ct <strong>in</strong> the ord<strong>in</strong>ation diagram,(both) analyses probably were adequate. However, the classes canoverlap and the analyses can still be good. It may be that you need threeor more axes to display the multivariate class structure. In addition, ord<strong>in</strong>ationand classification may use different criteria. In our example, causes weighted Chi-squared criteria, and the cluster<strong>in</strong>g uses Bray–Curtisdissimilarities which may be quite different. Function ordirgl with itssupport function orglspider can be used to <strong>in</strong>spect classification us<strong>in</strong>gdynamic 3D graphics.The <strong>vegan</strong> package has function ordicluster to overlay hclust tree<strong>in</strong> an ord<strong>in</strong>ation:CA2−1 0 1 2 31710 6571191121843−2 −1 0 1 291213CA182015 1416> plot(ord, display = "sites")> ordicluster(ord, cluc, col = "blue")The function comb<strong>in</strong>es po<strong>in</strong>ts and cluster midpo<strong>in</strong>ts similarly as <strong>in</strong> theorig<strong>in</strong>al cluster dendrogram.S<strong>in</strong>gle l<strong>in</strong>kage cluster<strong>in</strong>g is the method most <strong>of</strong>ten used with with ord<strong>in</strong>ationdiagrams. S<strong>in</strong>gle l<strong>in</strong>kage cluster<strong>in</strong>g is special among the cluster<strong>in</strong>galgorithms, because it always comb<strong>in</strong>es po<strong>in</strong>ts to po<strong>in</strong>ts: it is only thenearest po<strong>in</strong>t that is recognized and no <strong>in</strong>formation on its cluster membershipis used. The dendrogram, however, hides this <strong>in</strong>formation: itonly shows the fusions between clusters, but does not show which werethe actual po<strong>in</strong>ts that were jo<strong>in</strong>ed. The tree connect<strong>in</strong>g <strong>in</strong>dividual po<strong>in</strong>tsis called a m<strong>in</strong>imum spann<strong>in</strong>g tree (mst). In graph theory, ‘tree’ is aconnected graph with no loops, ‘spann<strong>in</strong>g tree’ is tree that connects allpo<strong>in</strong>ts, and m<strong>in</strong>imum spann<strong>in</strong>g tree is the one where the total length <strong>of</strong>connect<strong>in</strong>g segments is shortest. Function spantree <strong>in</strong> <strong>vegan</strong> f<strong>in</strong>d thistree, and it has a l<strong>in</strong>es function to overlay the tree onto ord<strong>in</strong>ation:CA2−1 0 1 2 31710 65711911218439121382015 1416> mst plot(mst, ord = ord, pch = 21, col = "red", bg = "yellow")38−2 −1 0 1 2


6 CLASSIFICATION 6.3 Classified community tablesIn our dissimilarity <strong>in</strong>dex, distance = 1 means that there is noth<strong>in</strong>g <strong>in</strong>common with two sample plots. Function spantree regards these maximumdissimilarities as miss<strong>in</strong>g data, and does not use them <strong>in</strong> build<strong>in</strong>gthe tree. If all po<strong>in</strong>ts cannot be connected because <strong>of</strong> these miss<strong>in</strong>g values,the result will consist <strong>of</strong> disconnected spann<strong>in</strong>g trees. In graph theory thisis known as a ‘forest’. Mst is used sometimes to cross-check ord<strong>in</strong>ation:if the tree is l<strong>in</strong>ear, the ord<strong>in</strong>ation might be good. A curved tree may<strong>in</strong>dicate arc or horseshoe artefacts, and a messy tree a bad ord<strong>in</strong>ation, ora need <strong>of</strong> higher number <strong>of</strong> dimensions. However, the results <strong>of</strong>ten aredifficult to <strong>in</strong>terpret.6.3 Classified community tablesThe aim <strong>of</strong> classification <strong>of</strong>ten is to make a classified community table.For this purpose, both sites and species should be arranged so that thetable looks structured. The orig<strong>in</strong>al cluster<strong>in</strong>g may not be ideally structured,because the order<strong>in</strong>g <strong>of</strong> sites is not strictly def<strong>in</strong>ed <strong>in</strong> the clusterdendrogram. You can take any branch and rotate it around its base, andthe cluster<strong>in</strong>g is the same. The tree draw<strong>in</strong>g algorithms use heuristicrules to make the tree look aesthetically pleas<strong>in</strong>g, but this order<strong>in</strong>g maynot be the best one for a structured community table.Base R has a general tree class called dendrogram which is <strong>in</strong>tended asa common base for any tree-like presentations. This class has a functionto reorder a tree accord<strong>in</strong>g to some external variable. The hclust resultcan be changed <strong>in</strong>to dendrogram with function as.dendrogram, and thiscan be reorderd with function reorder. The only cont<strong>in</strong>uous variable<strong>in</strong> the Dune data is the thickness <strong>of</strong> A1 horizon, and this could be usedto arrange the tree. However, for a nicely structured community tablewe use another trick: ca is an ord<strong>in</strong>ation method that structures tableoptimally <strong>in</strong>to a diagonal structure, and we can use its first axis to reorderthe tree:> wa den oden op plot(den)> plot(oden)> par(op)Function vegemite <strong>in</strong> <strong>vegan</strong> produces compact vegetation tables. Itcan take an argument use to arrange the sites (and species, if possible).This argument can be a vector used to arrange sites, or it can be anord<strong>in</strong>ation result, or it can be an hclust result or a dendrogram object.CA2−1 0 1 2 30.0 0.2 0.4 0.6 0.80.0 0.2 0.4 0.6 0.8●●●●●●●●●●●−2 −1 0 1 214161520171917191610157●13122●●CA11118●91118438349●●●2108121314152016567> vegemite(dune, use = oden, zero = "-")11 1 11 11112179157602183498234506Airpra 23------------------39


6.3 Classified community tables 6 CLASSIFICATIONEmpnig -2------------------Hyprad 25------2-----------Antodo 44-4234-------------Tripra ---225--------------Achmil 2-122243------------Plalan 2--5553-33----------Rumace ---536------2-2-----Brohor ---22-44---3--------Lolper --726665726524------Belper ---2--23-222--------Viclat ------1-21----------Elyrep --44---4--446-------Poapra 1-424344435444-2----Leoaut 26-3333555222322222-Trirep -2-225653221323261--Poatri --265447--655449---2Brarut -3-2262-4622224--444Sagpro -3------2--52242----Salrep -3-------3--------5-Cirarv -----------2--------Junbuf ----2-------4-43----Alogen -------2--723585---4Agrsto ----------4834454457Chealb ---------------1----Junart ------------44---343Potpal ----------------22--Ranfla -------------2-22242Elepal -------------4--4548Calcus ----------------4-33sites species20 30The dendrogram had no <strong>in</strong>formation on species, but it uses weigthedaverages to arrange them similarly as sites. This may not be optimal fora cluster<strong>in</strong>g results, but if the clusters are reorderd nicely, the results maybe very satisfactory with a nicely structured community table.The vegemite output is very compact (hence the name), and it usesonly one column for sites. In this case this was automatic, s<strong>in</strong>ce Dunemeadow data uses class scales. Percent cover scale can be transformed totraditional class scales, such as Braun-Blanquet, Dom<strong>in</strong> or Hult–Sernander–Du˜Rietz.Session Info• R version 2.10.1 (2009-12-14), i686-pc-l<strong>in</strong>ux-gnu• Locale: LC_CTYPE=en_GB.UTF-8, LC_NUMERIC=C, LC_TIME=en_GB.UTF-8,LC_COLLATE=en_GB.UTF-8, LC_MONETARY=C, LC_MESSAGES=en_GB.UTF-8,LC_PAPER=en_GB.UTF-8, LC_NAME=C, LC_ADDRESS=C, LC_TELEPHONE=C,LC_MEASUREMENT=en_GB.UTF-8, LC_IDENTIFICATION=C• Base packages: base, datasets, graphics, grDevices, methods, stats, utils• Other packages: MASS˜7.3-5, mgcv˜1.6-1, scatterplot3d˜0.3-30,<strong>vegan</strong>˜1.17-240


6 CLASSIFICATION 6.3 Classified community tables• Loaded via a namespace (and not attached): grid˜2.10.1, lattice˜0.18-3,Matrix˜0.999375-37, nlme˜3.1-96, tools˜2.10.141


Indexadonis, 32, 33AIC, 24, 26, 27anosim, 32anova, 21, 22, 31–33aov, 38apply, 9arc effect, 11as.dendrogram, 39attach, 16, 33beta diversity, 7, 32, 33betadisper, 33betadiver, 7, 32bioenv, 35biplot, 9calibrate.cca, 29capscale, 18, 24cca, 8, 11, 12, 18, 24cluster<strong>in</strong>g, 36–38cmdscale, 3, 18constra<strong>in</strong>ed analysis <strong>of</strong> proximities,18constra<strong>in</strong>ed correspondence analysis,18, 19constra<strong>in</strong>ed ord<strong>in</strong>ation, 18, 19, 21,23, 28contrasts, 20, 21cophenetic, 37correspondence analysis, 8, 10, 11,18, 39cutree, 37daisy, 7decorana, 11, 12decostand, 6dendrogram, 39, 40designdist, 7detrended correspondence analysis,11, 12deviance, 24dissimilarityArrhenius, 32b<strong>in</strong>omial, 6Bray-Curtis, 3–6Canberra, 6Chi-square, 8, 10, 18chord, 7Czekanowski, 5Euclidean, 5–8, 18, 32Gower, 6Hell<strong>in</strong>ger, 7Horn-Morisita, 6Jaccard, 5, 6Kulczyński, 5Manhattan, 5metric properties, 6Morisita, 6Mountford, 6Raup-Crick, 6Ružička, 6semimetric, 6Ste<strong>in</strong>haus, 3, 5Sørensen, 5, 7dist, 5, 7distance, 7downweight, 12downweight<strong>in</strong>g, 11, 12dsvdis, 7envfit, 14–16, 18factor fitt<strong>in</strong>g, 16formula, 15, 19, 21, 23, 24gam, 15, 16, 29half-change scal<strong>in</strong>g, 5hclust, 36, 38, 39identify, 8, 13, 14<strong>in</strong>ertia, 9, 10, 19, 21, 24isoMDS, 3, 4, 8LC scores, 28, 29Levene’s test, 33lm, 38local optimum, 4make.cepnames, 13mantel, 34, 35Mantel test, 34, 35partial, 35metaMDS, 4–8, 35metric scal<strong>in</strong>g, 3, 8, 1842


INDEXINDEXm<strong>in</strong>imum spann<strong>in</strong>g tree, 38mrpp, 32non-metric multidimensional scal<strong>in</strong>g,3–8, 14ordered factors, 21ordicluster, 38ordiellipse, 17, 38ordihull, 17, 38ordilabel, 13, 14ordiplot, 4, 12, 13ordiplot3d, 20ordipo<strong>in</strong>tlabel, 13, 14ordirgl, 20, 38ordispider, 17, 28, 38ordisurf, 15, 16, 18, 29orditkplot, 13, 14orditorp, 13, 14orglspider, 38packageanalogue, 7cluster, 7labdsv, 7, 36, 38MASS, 3mgcv, 15, 29partial ord<strong>in</strong>ation, 30permutation tests, 21, 32–35permutest, 33permutest.cca, 22po<strong>in</strong>ts, 12, 14prcomp, 8, 34pr<strong>in</strong>cipal components analysis, 8, 11,34pr<strong>in</strong>cipal coord<strong>in</strong>ates analysis, 8pr<strong>in</strong>comp, 8, 34procrustes, 7Procrustes analysis, 35Procrustes rotation, 7, 8protest, 35, 36rank<strong>in</strong>dex, 6rda, 8, 18, 24, 31, 32, 34rect.hclust, 37redundancy analysis, 18, 19reorder, 39scores, 4Shepard, 3spantree, 38, 39species space, 5species–environment correlation, 28,29spl<strong>in</strong>es, 15standardizationHell<strong>in</strong>ger, 7norm, 6Wiscons<strong>in</strong>, 4, 7step, 24, 27, 29stress, 3stressplot, 3surface fitt<strong>in</strong>g, 15Tcl/Tk, 13text, 12, 14transformationsquare root, 4, 7Tukey’s HSD, 34var, 9variance <strong>in</strong>flation factor, 27varpart, 31vector fitt<strong>in</strong>g, 14vegdist, 3, 5–7, 32vegemite, 39, 40WA scores, 28, 29weighted averages, 5, 10, 11, 28wiscons<strong>in</strong>, 7with, 16, 3343

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!