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
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Multivariate</strong> <strong>Analysis</strong> <strong>of</strong> <strong>Ecological</strong><br />
<strong>Communities</strong> <strong>in</strong> R: <strong>vegan</strong> <strong>tutorial</strong><br />
Jari Oksanen<br />
February 8, 2013<br />
Abstract<br />
This <strong>tutorial</strong> demostrates the use <strong>of</strong> ord<strong>in</strong>ation methods <strong>in</strong> R package<br />
<strong>vegan</strong>. The <strong>tutorial</strong> assumes familiarity both with R and<br />
with community ord<strong>in</strong>ation. Package <strong>vegan</strong> supports all basic ord<strong>in</strong>ation<br />
methods, <strong>in</strong>clud<strong>in</strong>g non-metric multidimensional scal<strong>in</strong>g.<br />
The constra<strong>in</strong>ed ord<strong>in</strong>ation methods <strong>in</strong>clude constra<strong>in</strong>ed analysis <strong>of</strong><br />
proximities, redundancy analysis and constra<strong>in</strong>ed correspondence<br />
analysis. Package <strong>vegan</strong> also has support functions for fitt<strong>in</strong>g environmental<br />
variables and for ord<strong>in</strong>ation graphics.<br />
Contents<br />
1 Introduction 2<br />
2 Ord<strong>in</strong>ation: basic method 3<br />
2.1 Non-metric Multidimensional scal<strong>in</strong>g . . . . . . . . . . . . 3<br />
2.2 Community dissimilarities . . . . . . . . . . . . . . . . . . 5<br />
2.3 Compar<strong>in</strong>g ord<strong>in</strong>ations: Procrustes rotation . . . . . . . . 8<br />
2.4 Eigenvector methods . . . . . . . . . . . . . . . . . . . . . 8<br />
2.5 Detrended correspondence analysis . . . . . . . . . . . . . 11<br />
2.6 Ord<strong>in</strong>ation graphics . . . . . . . . . . . . . . . . . . . . . 12<br />
3 Environmental <strong>in</strong>terpretation 14<br />
3.1 Vector fitt<strong>in</strong>g . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
3.2 Surface fitt<strong>in</strong>g . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
3.3 Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
4 Constra<strong>in</strong>ed ord<strong>in</strong>ation 18<br />
4.1 Model specification . . . . . . . . . . . . . . . . . . . . . . 19<br />
4.2 Permutation tests . . . . . . . . . . . . . . . . . . . . . . . 21<br />
4.3 Model build<strong>in</strong>g . . . . . . . . . . . . . . . . . . . . . . . . 23<br />
4.4 L<strong>in</strong>ear comb<strong>in</strong>ations and weighted averages . . . . . . . . 28<br />
4.5 Biplot arrows and environmental calibration . . . . . . . . 29<br />
4.6 Conditioned or partial models . . . . . . . . . . . . . . . . 30<br />
1
1 INTRODUCTION<br />
5 Dissimilarities and environment 32<br />
5.1 adonis: <strong>Multivariate</strong> ANOVA based on dissimilarities . . . 32<br />
5.2 Homogeneity <strong>of</strong> groups and beta diversity . . . . . . . . . 33<br />
5.3 Mantel test . . . . . . . . . . . . . . . . . . . . . . . . . . 35<br />
5.4 Protest: Procrustes test . . . . . . . . . . . . . . . . . . . 36<br />
6 Classification 36<br />
6.1 Cluster analysis . . . . . . . . . . . . . . . . . . . . . . . . 36<br />
6.2 Display and <strong>in</strong>terpretation <strong>of</strong> classes . . . . . . . . . . . . 38<br />
6.3 Classified community tables . . . . . . . . . . . . . . . . . 39<br />
1 Introduction<br />
This <strong>tutorial</strong> demonstrates typical work flows <strong>in</strong> multivariate ord<strong>in</strong>ation<br />
analysis <strong>of</strong> biological communities. The <strong>tutorial</strong> first discusses basic unconstra<strong>in</strong>ed<br />
analysis and environmental <strong>in</strong>terpretation <strong>of</strong> their results.<br />
Then it <strong>in</strong>troduces constra<strong>in</strong>ed ord<strong>in</strong>ation us<strong>in</strong>g constra<strong>in</strong>ed correspondence<br />
analysis as an example: alternative methods such as constra<strong>in</strong>ed<br />
analysis <strong>of</strong> proximities and redundancy analysis can be used (almost)<br />
similarly. F<strong>in</strong>ally the <strong>tutorial</strong> describes analysis <strong>of</strong> species–environment<br />
relations without ord<strong>in</strong>ation, and briefly touches classification <strong>of</strong> communities.<br />
The examples <strong>in</strong> this <strong>tutorial</strong> are tested: This is a Sweave document.<br />
The orig<strong>in</strong>al source file conta<strong>in</strong>s only text and R commands: their output<br />
and graphics are generated while runn<strong>in</strong>g the source through Sweave.<br />
However, you may need a recent version <strong>of</strong> <strong>vegan</strong>. This document was<br />
generetated us<strong>in</strong>g <strong>vegan</strong> version 2.0-6 and R version 2.15.1 (2012-06-22).<br />
The manual covers ord<strong>in</strong>ation methods <strong>in</strong> <strong>vegan</strong>. It does not discuss<br />
many other methods <strong>in</strong> <strong>vegan</strong>. For <strong>in</strong>stance, there are several functions<br />
for analysis <strong>of</strong> biodiversity: diversity <strong>in</strong>dices (diversity, renyi,<br />
fisher.alpha), extrapolated species richness (specpool, estimateR),<br />
species accumulation curves (specaccum), species abundance models (radfit,<br />
fisherfit, prestonfit) etc. Neither is <strong>vegan</strong> the only R package<br />
for ecological community ord<strong>in</strong>ation. Base R has standard statistical<br />
tools, labdsv complements <strong>vegan</strong> with some advanced methods and provides<br />
alternative versions <strong>of</strong> some methods, and ade4 provides an alternative<br />
implementation for the whole gamme <strong>of</strong> ord<strong>in</strong>ation methods.<br />
The <strong>tutorial</strong> expla<strong>in</strong>s only the most important methods and shows<br />
typical work flows. I see ord<strong>in</strong>ation primarily as a graphical tool, and I<br />
do not show too much exact numerical results. Instead, there are small<br />
vignettes <strong>of</strong> plott<strong>in</strong>g results <strong>in</strong> the marg<strong>in</strong>s close to the place where you<br />
see a plot command. I suggest that you repeat the analysis, try different<br />
alternatives and <strong>in</strong>spect the results more thoroughly at your leisure. The<br />
functions are expla<strong>in</strong>ed only briefly, and it is very useful to check the correspond<strong>in</strong>g<br />
help pages for a more thorough explanation <strong>of</strong> methods. The<br />
methods also are only briefly expla<strong>in</strong>ed. It is best to consult a textbook<br />
on ord<strong>in</strong>ation methods, or my lectures, for firmer theoretical background.<br />
2
2 ORDINATION: BASIC METHOD<br />
2 Ord<strong>in</strong>ation: basic method<br />
2.1 Non-metric Multidimensional scal<strong>in</strong>g<br />
Non-metric multidimensional scal<strong>in</strong>g can be performed us<strong>in</strong>g isoMDS function<br />
<strong>in</strong> the MASS package. This function needs dissimilarities as <strong>in</strong>put.<br />
Function vegdist <strong>in</strong> <strong>vegan</strong> conta<strong>in</strong>s dissimilarities which are found good<br />
<strong>in</strong> community ecology. The default is Bray-Curtis dissimilarity, nowadays<br />
<strong>of</strong>ten known as Ste<strong>in</strong>haus dissimilarity, or <strong>in</strong> F<strong>in</strong>land as Sørensen <strong>in</strong>dex.<br />
The basic steps are:<br />
> library(<strong>vegan</strong>)<br />
> library(MASS)<br />
> data(varespec)<br />
> vare.dis vare.mds0 stressplot(vare.mds0, vare.dis)<br />
Function stressplot draws a Shepard plot where ord<strong>in</strong>ation distances<br />
are plotted aga<strong>in</strong>st community dissimilarities, and the fit is shown as a<br />
monotone step l<strong>in</strong>e. In addition, stressplot shows two correlation like<br />
statistics <strong>of</strong> goodness <strong>of</strong> fit. The correlation based on stress is R 2 = 1−S 2 .<br />
The “fit-based R 2 ” is the correlation between the fitted values θ(d) and<br />
ord<strong>in</strong>ation distances ˜ d, or between the step l<strong>in</strong>e and the po<strong>in</strong>ts. This<br />
should be l<strong>in</strong>ear even when the fit is strongly curved and is <strong>of</strong>ten known<br />
as the “l<strong>in</strong>ear fit”. These two correlations are both based on the residuals<br />
<strong>in</strong> the Shepard plot, but they differ <strong>in</strong> their null models. In l<strong>in</strong>ear fit, the<br />
null model is that all ord<strong>in</strong>ation distances are equal, and the fit is a flat<br />
horizontal l<strong>in</strong>e. This sounds sensible, but you need N − 1 dimensions for<br />
the null model <strong>of</strong> N po<strong>in</strong>ts, and this null model is geometrically impossible<br />
<strong>in</strong> the ord<strong>in</strong>ation space. The basic stress uses the null model where all<br />
observations are put <strong>in</strong> the same po<strong>in</strong>t, which is geometrically possible.<br />
F<strong>in</strong>ally a word <strong>of</strong> warn<strong>in</strong>g: you sometimes see that people use correlation<br />
between community dissimilarities and ord<strong>in</strong>ation distances. This is dangerous<br />
and mislead<strong>in</strong>g s<strong>in</strong>ce nmds is a nonl<strong>in</strong>ear method: an improved<br />
3<br />
Ord<strong>in</strong>ation Distance<br />
0.2 0.4 0.6 0.8 1.0<br />
<br />
<br />
<br />
S = i=j [θ(dij) − ˜ dij] 2<br />
<br />
i=j ˜ d2 ij<br />
Non−metric fit, R2 = 0.99<br />
L<strong>in</strong>ear fit, R2 = 0.943<br />
●<br />
●<br />
● ●●●<br />
● ● ●<br />
●<br />
● ●<br />
● ● ● ●<br />
● ●<br />
●<br />
● ●<br />
● ● ●<br />
●<br />
●<br />
●<br />
● ●<br />
●●<br />
●<br />
● ● ● ●<br />
● ●<br />
● ●<br />
● ●<br />
●<br />
● ●●<br />
●<br />
● ● ● ●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
● ● ●<br />
● ●●<br />
●<br />
●<br />
●<br />
● ● ● ●<br />
● ●<br />
●<br />
●<br />
●<br />
● ●<br />
●● ●<br />
● ●<br />
●<br />
● ● ●<br />
●<br />
●●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
●●<br />
● ●<br />
●<br />
● ●<br />
●<br />
●●<br />
●<br />
●<br />
●<br />
● ●●<br />
● ●<br />
●<br />
●<br />
●<br />
●<br />
●●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
● ● ●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
●●<br />
●<br />
●<br />
●<br />
●<br />
● ●<br />
●●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
0.2 0.4 0.6 0.8<br />
Observed Dissimilarity<br />
●
Dim2<br />
NMDS2<br />
−0.4 −0.2 0.0 0.2 0.4<br />
−0.5 0.0 0.5<br />
2.1 Non-metric Multidimensional scal<strong>in</strong>g 2 ORDINATION: BASIC METHOD<br />
28<br />
25<br />
24<br />
22<br />
27<br />
15<br />
14<br />
16<br />
20<br />
23<br />
−0.6 −0.4 −0.2 0.0 0.2 0.4<br />
19<br />
21<br />
Dim1<br />
18<br />
11<br />
7<br />
13<br />
6<br />
Cla.ste<br />
2<br />
Dic.pol<br />
Cet.isl 24<br />
11<br />
Cla.chl<br />
P<strong>in</strong>.syl<br />
12<br />
Bar.lyc<br />
Cla.cer<br />
10<br />
9<br />
Poh.nut Pti.cil 21<br />
Cla.bot<br />
Dic.sp<br />
Cet.niv<br />
Emp.nig Vac.vit<br />
1923<br />
4 Cla.ran Cla.unc<br />
Pel.aph<br />
Cla.cri Cla.gra<br />
Pol.pil<br />
Ple.sch<br />
Cet.eri Cal.vul 6 13 Cla.cor Cla.def 20<br />
Cla.fim 15<br />
3 18 Cla.sp 16<br />
Cla.arb Cla.coc<br />
22<br />
7<br />
Pol.jun<br />
14<br />
Bet.pub<br />
28<br />
Vac.myr Led.pal<br />
27<br />
Pol.com Hyl.spl<br />
Ste.sp<br />
5 Dip.mon<br />
Dic.fus<br />
Des.fle<br />
Cla.ama<br />
Ich.eri<br />
Cla.phy<br />
Vac.uli<br />
Nep.arc<br />
25<br />
−0.5 0.0 0.5 1.0<br />
NMDS1<br />
12<br />
10<br />
9<br />
5<br />
4<br />
3<br />
2<br />
ord<strong>in</strong>ation with more nonl<strong>in</strong>ear relationship would appear worse with this<br />
criterion.<br />
Functions scores and ordiplot <strong>in</strong> <strong>vegan</strong> can be used to handle the<br />
results <strong>of</strong> nmds:<br />
> ordiplot(vare.mds0, type = "t")<br />
Only site scores were shown, because dissimilarities did not have <strong>in</strong>formation<br />
about species.<br />
The iterative search is very difficult <strong>in</strong> nmds, because <strong>of</strong> nonl<strong>in</strong>ear relationship<br />
between ord<strong>in</strong>ation and orig<strong>in</strong>al dissimilarities. The iteration<br />
easily 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.<br />
Therefore it is recommended to use several random starts, and<br />
select among similar solutions with smallest stresses. This may be tedious,<br />
but <strong>vegan</strong> has function metaMDS which does this, and many more<br />
th<strong>in</strong>gs. The trac<strong>in</strong>g output is long, and we suppress it with trace = 0,<br />
but normally we want to see that someth<strong>in</strong>g happens, s<strong>in</strong>ce the analysis<br />
can take a long time:<br />
> vare.mds vare.mds<br />
Call:<br />
metaMDS(comm = varespec, trace = FALSE)<br />
global Multidimensional Scal<strong>in</strong>g us<strong>in</strong>g monoMDS<br />
Data: wiscons<strong>in</strong>(sqrt(varespec))<br />
Distance: bray<br />
Dimensions: 2<br />
Stress: 0.1826<br />
Stress type 1, weak ties<br />
Two convergent solutions found after 20 tries<br />
Scal<strong>in</strong>g: centr<strong>in</strong>g, PC rotation, halfchange scal<strong>in</strong>g<br />
Species: expanded scores based on ‘wiscons<strong>in</strong>(sqrt(varespec))’<br />
> plot(vare.mds, type = "t")<br />
We did not calculate dissimilarities <strong>in</strong> a separate step, but we gave the<br />
orig<strong>in</strong>al data matrix as <strong>in</strong>put. The result is more complicated than previously,<br />
and has quite a few components <strong>in</strong> addition to those <strong>in</strong> isoMDS results:<br />
nobj, nfix, ndim, ndis, ngrp, diss, iidx, jidx, x<strong>in</strong>it, istart,<br />
isform, ities, iregn, iscal, maxits, sratmx, strm<strong>in</strong>, sfgrmn,<br />
dist, dhat, po<strong>in</strong>ts, stress, grstress, iters, icause, call,<br />
model, distmethod, distcall, data, distance, converged, tries,<br />
eng<strong>in</strong>e, species. The function wraps recommended procedures <strong>in</strong>to one<br />
command. So what happened here?<br />
1. The range <strong>of</strong> data values was so large that the data were square root<br />
transformed, and then submitted to Wiscons<strong>in</strong> double standardization,<br />
or species divided by their maxima, and stands standardized<br />
to equal totals. These two standardizations <strong>of</strong>ten improve the quality<br />
<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>itial<br />
analysis.<br />
4
2 ORDINATION: BASIC METHOD 2.2 Community dissimilarities<br />
2. Function used Bray–Curtis dissimilarities.<br />
3. Function run isoMDS with several random starts, and stopped either<br />
after a certa<strong>in</strong> number <strong>of</strong> tries, or after f<strong>in</strong>d<strong>in</strong>g two similar<br />
configurations with m<strong>in</strong>imum stress. In any case, it returned the<br />
best solution.<br />
4. Function rotated the solution so that the largest variance <strong>of</strong> site<br />
scores will be on the first axis.<br />
5. Function scaled the solution so that one unit corresponds to halv<strong>in</strong>g<br />
<strong>of</strong> community similarity from the replicate similarity.<br />
6. Function found species scores as weighted averages <strong>of</strong> site scores,<br />
but expanded them so that species and site scores have equal variances.<br />
This expansion can be undone us<strong>in</strong>g shr<strong>in</strong>k = TRUE <strong>in</strong> display<br />
commands.<br />
The help page for metaMDS will give more details, and po<strong>in</strong>t to explanation<br />
<strong>of</strong> functions used <strong>in</strong> the function.<br />
2.2 Community dissimilarities<br />
Non-metric multidimensional scal<strong>in</strong>g is a good ord<strong>in</strong>ation method because<br />
it can use ecologically mean<strong>in</strong>gful ways <strong>of</strong> measur<strong>in</strong>g community<br />
dissimilarities. A good dissimilarity measure has a good rank order relation<br />
to distance along environmental gradients. Because nmds only uses<br />
rank <strong>in</strong>formation and maps ranks non-l<strong>in</strong>early onto ord<strong>in</strong>ation space, it<br />
can handle non-l<strong>in</strong>ear species responses <strong>of</strong> any shape and effectively and<br />
robustly f<strong>in</strong>d the underly<strong>in</strong>g gradients.<br />
The most natural dissimilarity measure is Euclidean distance which is<br />
<strong>in</strong>herently used by eigenvector methods <strong>of</strong> ord<strong>in</strong>ation. It is the distance <strong>in</strong><br />
species space. Species space means that each species is an axis orthogonal<br />
to all other species, and sites are po<strong>in</strong>ts <strong>in</strong> this multidimensional hyperspace.<br />
However, Euclidean distance is based on squared differences and<br />
strongly dom<strong>in</strong>ated by s<strong>in</strong>gle large differences. Most ecologically mean<strong>in</strong>gful<br />
dissimilarities are <strong>of</strong> Manhattan type, and use differences <strong>in</strong>stead <strong>of</strong><br />
squared differences. Another feature <strong>in</strong> good dissimilarity <strong>in</strong>dices is that<br />
they are proportional: if two communities share no species, they have a<br />
maximum dissimilarity = 1. Euclidean and Manhattan dissimilarities<br />
will vary accord<strong>in</strong>g to total abundances even though there are no shared<br />
species.<br />
Package <strong>vegan</strong> has function vegdist with Bray–Curtis, Jaccard and<br />
Kulczyński <strong>in</strong>dices. All these are <strong>of</strong> the Manhattan type and use only<br />
first order terms (sums and differences), and all are relativized by site total<br />
and reach their maximum value (1) when there are no shared species<br />
between two compared communities. Function vegdist is a drop-<strong>in</strong> replacement<br />
for standard R function dist, and either <strong>of</strong> these functions can<br />
be used <strong>in</strong> analyses <strong>of</strong> dissimilarities.<br />
There are many confus<strong>in</strong>g aspects <strong>in</strong> dissimilarity <strong>in</strong>dices. One is that<br />
same <strong>in</strong>dices can be written with very different look<strong>in</strong>g equations: two<br />
alternative formulations <strong>of</strong> Manhattan dissimilarities <strong>in</strong> the marg<strong>in</strong> serve<br />
5<br />
<br />
<br />
<br />
djk = N <br />
djk =<br />
A =<br />
J =<br />
i=1<br />
(xij − xik) 2 Euclidean<br />
N<br />
|xij − xik| Manhattan<br />
i=1<br />
N<br />
i=1<br />
xij<br />
N<br />
m<strong>in</strong>(xij, xik)<br />
i=1<br />
B =<br />
N<br />
i=1<br />
xik<br />
djk = A + B − 2J Manhattan<br />
A + B − 2J<br />
djk =<br />
A + B<br />
A + B − 2J<br />
djk =<br />
A + B − J<br />
djk = 1 − 1<br />
<br />
J J<br />
+<br />
2 A B<br />
Bray<br />
Jaccard<br />
Kulczyński
2.2 Community dissimilarities 2 ORDINATION: BASIC METHOD<br />
for A = B dAB = 0<br />
for A = B dAB > 0<br />
dAB = dBA<br />
dAB ≤ dAx + dxB<br />
as an example. Another complication is nam<strong>in</strong>g. Function vegdist uses<br />
colloquial names which may not be strictly correct. The default <strong>in</strong>dex <strong>in</strong><br />
<strong>vegan</strong> is called Bray (or Bray–Curtis), but it probably should be called<br />
Ste<strong>in</strong>haus <strong>in</strong>dex. On the other hand, its correct name was supposed to be<br />
Czekanowski <strong>in</strong>dex some years ago (but now this is regarded as another<br />
<strong>in</strong>dex), and it is also known as Sørensen <strong>in</strong>dex (but usually misspelt).<br />
Strictly speak<strong>in</strong>g, Jaccard <strong>in</strong>dex is b<strong>in</strong>ary, and the quantitative variant<br />
<strong>in</strong> <strong>vegan</strong> should be called Ruˇzička <strong>in</strong>dex. However, <strong>vegan</strong> f<strong>in</strong>ds either<br />
quantitative or b<strong>in</strong>ary variant <strong>of</strong> any <strong>in</strong>dex under the same name.<br />
These three basic <strong>in</strong>dices are regarded as good <strong>in</strong> detect<strong>in</strong>g gradients.<br />
In addition, vegdist function has <strong>in</strong>dices that should satisfy other<br />
criteria. Morisita, Horn–Morisita, Raup–Cric, B<strong>in</strong>omial and Mountford<br />
<strong>in</strong>dices should be able to compare sampl<strong>in</strong>g units <strong>of</strong> different sizes. Euclidean,<br />
Canberra and Gower <strong>in</strong>dices should have better theoretical properties.<br />
Function metaMDS used Bray-Curtis dissimilarity as default, which<br />
usually is a good choice. Jaccard (Ruˇzička) <strong>in</strong>dex has identical rank<br />
order, but has better metric properties, and probably should be preferred.<br />
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>dices<br />
best separates communities along known gradients us<strong>in</strong>g rank correlation<br />
as default. The follow<strong>in</strong>g example uses all environmental variables <strong>in</strong> data<br />
set varechem, but standardizes these to unit variance:<br />
> data(varechem)<br />
> rank<strong>in</strong>dex(scale(varechem), varespec, c("euc","man","bray","jac","kul"))<br />
euc man bray jac kul<br />
0.2396 0.2735 0.2838 0.2838 0.2840<br />
are non-l<strong>in</strong>early related, but they have identical rank orders, and their<br />
rank correlations are identical. In general, the three recommended <strong>in</strong>dices<br />
are fairly equal.<br />
I took a very practical approach on <strong>in</strong>dices emphasiz<strong>in</strong>g their ability<br />
to recover underly<strong>in</strong>g environmental gradients. Many textbooks emphasize<br />
metric properties <strong>of</strong> <strong>in</strong>dices. These are important <strong>in</strong> some methods,<br />
but not <strong>in</strong> nmds which only uses rank order <strong>in</strong>formation. The metric<br />
properties simply say that<br />
1. if two sites are identical, their distance is zero,<br />
2. if two sites are different, their distance is larger than zero,<br />
3. distances are symmetric, and<br />
4. the shortest distance between two sites is a l<strong>in</strong>e, and you cannot<br />
improve by go<strong>in</strong>g through other sites.<br />
These all sound very natural conditions, but they are not fulfilled by all<br />
dissimilarities. Actually, only Euclidean distances – and probably Jaccard<br />
<strong>in</strong>dex – fulfill all conditions among the dissimilarities discussed here, and<br />
are metrics. Many other dissimilarities fulfill three first conditions and<br />
are semimetrics.<br />
There is a school that says that we should use metric <strong>in</strong>dices, and<br />
most naturally, Euclidean distances. One <strong>of</strong> their drawbacks was that<br />
6
2 ORDINATION: BASIC METHOD 2.2 Community dissimilarities<br />
they have no fixed limit, but two sites with no shared species can vary<br />
<strong>in</strong> dissimilarities, and even look more similar than two sites shar<strong>in</strong>g some<br />
species. This can be cured by standardiz<strong>in</strong>g data. S<strong>in</strong>ce Euclidean distances<br />
are based on squared differences, a natural transformation is to<br />
standardize sites to equal sum <strong>of</strong> squares, or to their vector norm us<strong>in</strong>g<br />
function decostand:<br />
> dis dis d d d
Dimension 2<br />
Procrustes residual<br />
−0.4 −0.2 0.0 0.2 0.4<br />
0.00 0.05 0.10 0.15 0.20 0.25 0.30<br />
2.3 Compar<strong>in</strong>g ord<strong>in</strong>ations: Procrustes rotation 2 ORDINATION: BASIC METHOD<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
Procrustes errors<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
−0.4 −0.2 0.0 0.2 0.4 0.6<br />
Dimension 1<br />
Procrustes errors<br />
5 10 15 20<br />
Index<br />
method metric mapp<strong>in</strong>g<br />
nmds any nonl<strong>in</strong>ear<br />
mds any l<strong>in</strong>ear<br />
pca Euclidean l<strong>in</strong>ear<br />
ca Chi-square weighted l<strong>in</strong>ear<br />
<br />
<br />
<br />
djk = N <br />
i=1<br />
●<br />
●<br />
(xij − xik) 2<br />
●<br />
●<br />
●<br />
●<br />
2.3 Compar<strong>in</strong>g ord<strong>in</strong>ations: Procrustes rotation<br />
Two ord<strong>in</strong>ations can be very similar, but this may be difficult to see,<br />
because axes have slightly different orientation and scal<strong>in</strong>g. Actually, <strong>in</strong><br />
nmds the sign, orientation, scale and location <strong>of</strong> the axes are not def<strong>in</strong>ed,<br />
although metaMDS uses simple method to fix the last three components.<br />
The best way to compare ord<strong>in</strong>ations is to use Procrustes rotation.<br />
Procrustes rotation uses uniform scal<strong>in</strong>g (expansion or contraction) and<br />
rotation to m<strong>in</strong>imize the squared differences between two ord<strong>in</strong>ations.<br />
Package <strong>vegan</strong> has function procrustes to perform Procrustes analysis.<br />
How much did we ga<strong>in</strong> with us<strong>in</strong>g metaMDS <strong>in</strong>stead <strong>of</strong> default isoMDS?<br />
> tmp dis vare.mds0 pro pro<br />
Call:<br />
procrustes(X = vare.mds, Y = vare.mds0)<br />
Procrustes sum <strong>of</strong> squares:<br />
0.156<br />
> plot(pro)<br />
In this case the differences were fairly small, and ma<strong>in</strong>ly concerned two<br />
po<strong>in</strong>ts. You can use identify function to identify those po<strong>in</strong>ts <strong>in</strong> an<br />
<strong>in</strong>teractive session, or you can ask a plot <strong>of</strong> residual differences only:<br />
> plot(pro, k<strong>in</strong>d = 2)<br />
The descriptive statistic is “Procrustes sum <strong>of</strong> squares” or the sum <strong>of</strong><br />
squared arrows <strong>in</strong> the Procrustes plot. Procrustes rotation is nonsymmetric,<br />
and the statistic would change with revers<strong>in</strong>g the order <strong>of</strong> ord<strong>in</strong>ations<br />
<strong>in</strong> the call. With argument symmetric = TRUE, both solutions are<br />
first scaled to unit variance, and a more scale-<strong>in</strong>dependent and symmetric<br />
statistic is found (<strong>of</strong>ten known as Procrustes m 2 ).<br />
2.4 Eigenvector methods<br />
Non-metric multidimensional scal<strong>in</strong>g was a hard task, because any k<strong>in</strong>d<br />
<strong>of</strong> dissimilarity measure could be used and dissimilarities were nonl<strong>in</strong>early<br />
mapped <strong>in</strong>to ord<strong>in</strong>ation. If we accept only certa<strong>in</strong> types <strong>of</strong> dissimilarities<br />
and make a l<strong>in</strong>ear mapp<strong>in</strong>g, the ord<strong>in</strong>ation becomes a simple task <strong>of</strong><br />
rotation and projection. In that case we can use eigenvector methods.<br />
Pr<strong>in</strong>cipal components analysis (pca) and correspondence analysis (ca)<br />
are the most important eigenvector methods <strong>in</strong> community ord<strong>in</strong>ation.<br />
In addition, pr<strong>in</strong>cipal coord<strong>in</strong>ates analysis a.k.a. metric scal<strong>in</strong>g (mds) is<br />
used occasionally. Pca is based on Euclidean distances, ca is based on<br />
Chi-square distances, and pr<strong>in</strong>cipal coord<strong>in</strong>ates can use any dissimilarities<br />
(but with Euclidean distances it is equal to pca).<br />
Pca is a standard statistical method, and can be performed with base<br />
R functions prcomp or pr<strong>in</strong>comp. Correspondence analysis is not as ubiquitous,<br />
but there are several alternative implementations for that also. In<br />
8
2 ORDINATION: BASIC METHOD 2.4 Eigenvector methods<br />
this <strong>tutorial</strong> I show how to run these analyses with <strong>vegan</strong> functions rda<br />
and cca which actually were designed for constra<strong>in</strong>ed analysis.<br />
Pr<strong>in</strong>cipal components analysis can be run as:<br />
> vare.pca vare.pca<br />
Call: rda(X = varespec)<br />
Inertia Rank<br />
Total 1826<br />
Unconstra<strong>in</strong>ed 1826 23<br />
Inertia is variance<br />
Eigenvalues for unconstra<strong>in</strong>ed axes:<br />
PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8<br />
983.0 464.3 132.3 73.9 48.4 37.0 25.7 19.7<br />
(Showed only 8 <strong>of</strong> all 23 unconstra<strong>in</strong>ed eigenvalues)<br />
> plot(vare.pca)<br />
The output tells that the total <strong>in</strong>ertia is 1826, and the <strong>in</strong>ertia is variance.<br />
The sum <strong>of</strong> all 23 (rank) eigenvalues would be equal to the total<br />
<strong>in</strong>ertia. In other words, the solution decomposes the total variance <strong>in</strong>to<br />
l<strong>in</strong>ear components. We can easily see that the variance equals <strong>in</strong>ertia:<br />
> sum(apply(varespec, 2, var))<br />
[1] 1826<br />
Function apply applies function var or variance to dimension 2 or columns<br />
(species), and then sum takes the sum <strong>of</strong> these values. Inertia is the sum<br />
<strong>of</strong> all species variances. The eigenvalues sum up to total <strong>in</strong>ertia. In other<br />
words, they each “expla<strong>in</strong>” a certa<strong>in</strong> proportion <strong>of</strong> total variance. The<br />
first axis “expla<strong>in</strong>s” 983/ 1826 = 53.8 % <strong>of</strong> total variance.<br />
The standard ord<strong>in</strong>ation plot command uses po<strong>in</strong>ts or labels for<br />
species and sites. Some people prefer to use biplot arrows for species<br />
<strong>in</strong> pca and possibly also for sites. There is a special biplot function for<br />
this purpose:<br />
PC2<br />
−6 −4 −2 0 2 4 6<br />
Ple.sch 27<br />
28<br />
15 22 25<br />
24<br />
5<br />
7<br />
Cla.arb<br />
13<br />
18<br />
Cla.ran<br />
14<br />
Cal.vul Vac.uli<br />
Ste.sp<br />
11<br />
20<br />
16 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.cil<br />
23Dic.fus<br />
Dic.sp Hyl.spl 21 Emp.nig<br />
Vac.myr Vac.vit<br />
6<br />
19<br />
4<br />
−4 −2 0 2 4 6 8 10<br />
> biplot(vare.pca, scal<strong>in</strong>g = -1) −4 −2 0 2 4 6<br />
For this graph we specified scal<strong>in</strong>g = -1. The results are scaled only<br />
when they are accessed, and we can flexibly change the scal<strong>in</strong>g <strong>in</strong> plot,<br />
biplot and other commands. The negative values mean that species<br />
scores are divided by the species standard deviations so that abundant<br />
and scarce species will be approximately as far away from the orig<strong>in</strong>.<br />
The species ord<strong>in</strong>ation looks somewhat unsatisfactory: only re<strong>in</strong>deer<br />
lichens (Clad<strong>in</strong>a) and Pleurozium schreberi are visible, and all other<br />
species are crowded at the orig<strong>in</strong>. This happens because <strong>in</strong>ertia was variance,<br />
and only abundant species with high variances are worth expla<strong>in</strong><strong>in</strong>g<br />
(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>g<br />
all species to unit variance, or us<strong>in</strong>g correlation coefficients <strong>in</strong>stead<br />
<strong>of</strong> covariances will give a more balanced ord<strong>in</strong>ation:<br />
> vare.pca vare.pca<br />
9<br />
PC2<br />
−4 −2 0 2 4<br />
28<br />
Ple.sch<br />
PC1<br />
Cla.gra 18<br />
13 Dip.mon<br />
Cal.vul<br />
Cet.niv4<br />
Cet.eriCla.fim<br />
14<br />
Cla.unc Cla.cer<br />
Cla.def 20<br />
11<br />
16 Cla.cri<br />
23<br />
Cla.cor Pel.aph Bet.pub Bar.lyc<br />
Cla.bot Pti.cil 21<br />
3<br />
2<br />
Pol.jun Nep.arc<br />
15 Dic.fus Dic.pol<br />
Cla.sp<br />
22<br />
19 P<strong>in</strong>.syl<br />
12<br />
24 25<br />
Dic.sp<br />
Cet.isl Cla.chl Cla.phy<br />
Led.pal Pol.com<br />
Emp.nig<br />
Cla.ste10<br />
9<br />
27<br />
Des.fle<br />
Vac.myr<br />
Hyl.spl<br />
Cla.arb Cla.ran<br />
Ich.eri 7Ste.sp Vac.uli<br />
Cla.ama Pol.pil Cla.coc<br />
5<br />
6<br />
PC1<br />
3<br />
Vac.vit Poh.nut<br />
12<br />
2<br />
10<br />
9<br />
Cla.ste
PC2<br />
CA2<br />
−2 −1 0 1<br />
−2.0 −1.5 −1.0 −0.5 0.0 0.5 1.0 1.5<br />
2.4 Eigenvector methods 2 ORDINATION: BASIC METHOD<br />
Poh.nut<br />
Cla.coc<br />
Cla.ste Cla.chl<br />
P<strong>in</strong>.syl Cet.isl<br />
Cla.sp Cla.gra<br />
Pol.pil Cet.eri Cla.cri Cla.fim<br />
Cla.ran<br />
Cla.arb Ste.sp Dip.mon Cla.unc<br />
Cla.ama Cla.cor<br />
Cal.vul<br />
Cet.niv<br />
Dic.sp<br />
Vac.uli<br />
Dic.fus<br />
Pol.jun<br />
Nep.arc<br />
Vac.vit<br />
Dic.pol<br />
Pti.cil<br />
Bet.pub Bar.lyc<br />
Cla.bot<br />
Emp.nig<br />
Pol.com Led.pal<br />
Pel.aph<br />
11Cla.phy<br />
10<br />
5<br />
23 12<br />
1418<br />
Cla.def<br />
6<br />
13 24<br />
Ich.eri<br />
3<br />
7 15<br />
16 20<br />
4<br />
Cla.cer<br />
2 19<br />
22<br />
Vac.myr<br />
25 Des.fle<br />
Ple.sch Hyl.spl<br />
28<br />
9<br />
27<br />
−1 0 1 2 3<br />
PC1<br />
Led.pal<br />
Vac.myr<br />
9<br />
10<br />
21<br />
Bar.lyc<br />
Bet.pub<br />
28<br />
Hyl.spl<br />
2 12<br />
Cla.phy<br />
Cla.ste<br />
Cet.isl<br />
Cla.chl<br />
19<br />
Pti.cil<br />
Dic.pol<br />
Pol.com<br />
27<br />
Des.fle<br />
Cla.bot<br />
P<strong>in</strong>.syl Poh.nut<br />
Ple.sch<br />
Cla.sp<br />
3<br />
Emp.nig<br />
Vac.vit<br />
Dic.sp 24<br />
25<br />
Nep.arc<br />
Pol.jun<br />
Cla.cer<br />
11<br />
Pel.aph<br />
Cla.fim Cla.cor 23<br />
Cla.gra<br />
Cla.cri<br />
15<br />
22<br />
Cla.def<br />
Cla.coc 20 Dic.fus<br />
Cet.eri<br />
Cet.niv<br />
4 Dip.mon Cla.ran<br />
Cla.unc<br />
16<br />
Pol.pil<br />
Cla.ama Cla.arb 18<br />
Vac.uli Cal.vul<br />
5<br />
6<br />
Ste.sp 13<br />
Ich.eri<br />
7<br />
−1 0 1 2<br />
CA1<br />
14<br />
21<br />
Call: rda(X = varespec, scale = TRUE)<br />
Inertia Rank<br />
Total 44<br />
Unconstra<strong>in</strong>ed 44 23<br />
Inertia is correlations<br />
Eigenvalues for unconstra<strong>in</strong>ed axes:<br />
PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8<br />
8.90 4.76 4.26 3.73 2.96 2.88 2.73 2.18<br />
(Showed only 8 <strong>of</strong> all 23 unconstra<strong>in</strong>ed eigenvalues)<br />
> plot(vare.pca, scal<strong>in</strong>g = 3)<br />
Now <strong>in</strong>ertia is correlation, and the correlation <strong>of</strong> a variable with itself is<br />
one. Thus the total <strong>in</strong>ertia is equal to the number <strong>of</strong> variables (species).<br />
The rank or the total number <strong>of</strong> eigenvectors is the same as previously.<br />
The maximum possible rank is def<strong>in</strong>ed by the dimensions <strong>of</strong> the data: it<br />
is one less than smaller <strong>of</strong> number <strong>of</strong> species or number <strong>of</strong> sites:<br />
> dim(varespec)<br />
[1] 24 44<br />
If there are species or sites similar to each other, rank will be reduced<br />
even from this.<br />
The percentage expla<strong>in</strong>ed by the first axis decreased from the previous<br />
pca. This is natural, s<strong>in</strong>ce previously we needed to “expla<strong>in</strong>” only the<br />
abundant species with high variances, but now we have to expla<strong>in</strong> all<br />
species equally. We should not look bl<strong>in</strong>dly at percentages, but the result<br />
we get.<br />
Correspondence analysis is very similar to pca:<br />
> vare.ca vare.ca<br />
Call: cca(X = varespec)<br />
Inertia Rank<br />
Total 2.08<br />
Unconstra<strong>in</strong>ed 2.08 23<br />
Inertia is mean squared cont<strong>in</strong>gency coefficient<br />
Eigenvalues for unconstra<strong>in</strong>ed axes:<br />
CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8<br />
0.5249 0.3568 0.2344 0.1955 0.1776 0.1216 0.1155 0.0889<br />
(Showed only 8 <strong>of</strong> all 23 unconstra<strong>in</strong>ed eigenvalues)<br />
> plot(vare.ca)<br />
Now the <strong>in</strong>ertia is called mean squared cont<strong>in</strong>gency coefficient. Correspondence<br />
analysis is based on Chi-squared distance, and the <strong>in</strong>ertia is<br />
the Chi-squared statistic <strong>of</strong> a data matrix standardized to unit total:<br />
> chisq.test(varespec/sum(varespec))<br />
Pearsons Chi-squared test<br />
data: varespec/sum(varespec)<br />
X-squared = 2.083, df = 989, p-value = 1<br />
10
2 ORDINATION: BASIC METHOD 2.5 Detrended correspondence analysis<br />
You should not pay any attention to P -values which are certa<strong>in</strong>ly mislead<strong>in</strong>g,<br />
but notice that the reported X-squared is equal to the <strong>in</strong>ertia<br />
above.<br />
Correspondence analysis is a weighted averag<strong>in</strong>g method. In the graph<br />
above species scores were weighted averages <strong>of</strong> site scores. With different<br />
scal<strong>in</strong>g <strong>of</strong> results, we could display the site scores as weighted averages <strong>of</strong><br />
species scores:<br />
> plot(vare.ca, scal<strong>in</strong>g = 1)<br />
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.<br />
The other two <strong>in</strong>tegers mean that either species are weighted averages <strong>of</strong><br />
sites (2) or sites are weighted averages <strong>of</strong> species (1). When we take<br />
weighted averages, the range <strong>of</strong> averages shr<strong>in</strong>ks from the orig<strong>in</strong>al values.<br />
The shr<strong>in</strong>kage factor is equal to the eigenvalue <strong>of</strong> ca, which has a<br />
theoretical maximum <strong>of</strong> 1.<br />
2.5 Detrended correspondence analysis<br />
Correspondence analysis is a much better and more robust method for<br />
community ord<strong>in</strong>ation than pr<strong>in</strong>cipal components analysis. However,<br />
with long ecological gradients it suffers from some drawbacks or “faults”<br />
which were corrected <strong>in</strong> detrended correspondence analysis (dca):<br />
S<strong>in</strong>gle long gradients appear as curves or arcs <strong>in</strong> ord<strong>in</strong>ation (arc<br />
effect): the solution is to detrend the later axes by mak<strong>in</strong>g their<br />
means equal along segments <strong>of</strong> previous axes.<br />
Sites are packed more closely at gradient extremes than at the centre:<br />
the solution is to rescale the axes to equal variances <strong>of</strong> species<br />
scores.<br />
Rare species seem to have an unduly high <strong>in</strong>fluence on the results:<br />
the solution iss to downweight rare species.<br />
All these three separate tricks are <strong>in</strong>corporated <strong>in</strong> function decorana<br />
which is a faithful port <strong>of</strong> Mark Hill’s orig<strong>in</strong>al programme with the same<br />
name. The usage is simple:<br />
> vare.dca vare.dca<br />
Call:<br />
decorana(veg = varespec)<br />
Detrended correspondence analysis with 26 segments.<br />
Rescal<strong>in</strong>g <strong>of</strong> axes with 4 iterations.<br />
DCA1 DCA2 DCA3 DCA4<br />
Eigenvalues 0.524 0.325 0.2001 0.1918<br />
Decorana values 0.525 0.157 0.0967 0.0608<br />
Axis lengths 2.816 2.205 1.5465 1.6486<br />
> plot(vare.dca, display="sites")<br />
11<br />
CA2<br />
−2 −1 0 1 2<br />
Cet.isl<br />
Cla.phy Cla.chl<br />
Cla.ste<br />
9<br />
21<br />
28<br />
10<br />
P<strong>in</strong>.syl Poh.nut<br />
Ple.sch<br />
2Cla.sp<br />
12<br />
27<br />
Emp.nig 19<br />
Vac.vit<br />
Dic.sp<br />
Nep.arc<br />
3<br />
Pol.jun 24 25<br />
Cla.cer 11 Pel.aph 23<br />
Cla.fim Cla.cor 15 22<br />
20<br />
4<br />
Cla.gra 16<br />
Cla.cri Cla.def<br />
Cla.coc 18<br />
Dic.fus<br />
Cet.eri 14<br />
Cet.niv<br />
6 13<br />
Dip.mon<br />
Cla.unc<br />
Cla.ran 7<br />
Pol.pil 5<br />
Cla.ama Cla.arb<br />
Vac.uli Cal.vul<br />
Ste.sp<br />
Ich.eri<br />
Bar.lyc<br />
Bet.pub<br />
Led.pal<br />
Vac.myr<br />
Hyl.spl<br />
Pti.cil<br />
Dic.pol<br />
Pol.com<br />
Des.fle<br />
Cla.bot<br />
−2 −1 0 1 2 3<br />
CA1
DCA2<br />
−1.0 −0.5 0.0 0.5 1.0<br />
2.6 Ord<strong>in</strong>ation graphics 2 ORDINATION: BASIC METHOD<br />
10<br />
9<br />
2<br />
3<br />
4<br />
12<br />
5<br />
11<br />
18<br />
6<br />
13<br />
7<br />
19<br />
−1.0 −0.5 0.0 0.5 1.0 1.5<br />
21<br />
DCA1<br />
23<br />
20<br />
14<br />
16<br />
15<br />
27<br />
22<br />
24<br />
25<br />
28<br />
Function decorana f<strong>in</strong>ds only four axes. Eigenvalues are def<strong>in</strong>ed as<br />
shr<strong>in</strong>kage values <strong>in</strong> weighted averages, similarly as <strong>in</strong> cca above. The<br />
“Decorana values” are the numbers that the orig<strong>in</strong>al programme returns<br />
as “eigenvalues” — I have no idea <strong>of</strong> their possible mean<strong>in</strong>g, and they<br />
should not be used. Most <strong>of</strong>ten people comment on axis lengths, which<br />
sometimes are called “gradient lengths”. The etymology is obscure: these<br />
are not gradients, but ord<strong>in</strong>ation axes. It is <strong>of</strong>ten said that if the axis<br />
length is shorter than two units, the data are l<strong>in</strong>ear, and pca should be<br />
used. This is only folklore and not based on research which shows that<br />
ca is at least as good as pca with short gradients, and usually better.<br />
The current data set is homogeneous, and the effects <strong>of</strong> dca are not<br />
very large. In heterogeneous data with a clear arc effect the changes <strong>of</strong>ten<br />
are more dramatic. Rescal<strong>in</strong>g may have larger <strong>in</strong>fluence than detrend<strong>in</strong>g<br />
<strong>in</strong> many cases.<br />
The default analysis is without downweight<strong>in</strong>g <strong>of</strong> rare species: see help<br />
pages for the needed arguments. Actually, downweight is an <strong>in</strong>dependent<br />
function that can be used with cca as well.<br />
There is a school <strong>of</strong> thought that regards dca as the method <strong>of</strong> choice<br />
<strong>in</strong> unconstra<strong>in</strong>ed ord<strong>in</strong>ation. However, it seems to be a fragile and vague<br />
back <strong>of</strong> tricks that is better avoided.<br />
2.6 Ord<strong>in</strong>ation graphics<br />
We have already seen many ord<strong>in</strong>ation diagrams <strong>in</strong> this <strong>tutorial</strong> with one<br />
feature <strong>in</strong> common: they are cluttered and labels are difficult to read.<br />
Ord<strong>in</strong>ation diagrams are difficult to draw cleanly because we must put a<br />
large number <strong>of</strong> labels <strong>in</strong> a small plot, and <strong>of</strong>ten it is impossible to draw<br />
clean plots with all items labelled. In this chapter we look at produc<strong>in</strong>g<br />
cleaner plots. For this we must look at the anatomy <strong>of</strong> plott<strong>in</strong>g functions<br />
<strong>in</strong> <strong>vegan</strong> and see how to ga<strong>in</strong> a better control <strong>of</strong> default functions.<br />
Ord<strong>in</strong>ation functions <strong>in</strong> <strong>vegan</strong> have their dedicated plot functions<br />
which provides a simple plot. For <strong>in</strong>stance, the result <strong>of</strong> decorana is<br />
displayed by function plot.decorana which beh<strong>in</strong>d the scenes is called<br />
by our plot function. Alternatively, we can use function ordiplot which<br />
also works with many non-<strong>vegan</strong> ord<strong>in</strong>ation functions, but uses po<strong>in</strong>ts<br />
<strong>in</strong>stead <strong>of</strong> text as default. The plot.decorana function (or ordiplot)<br />
actually works <strong>in</strong> three stages:<br />
1. It draws an empty plot with labelled axes, but with no symbols for<br />
sites or species.<br />
2. It uses functions text or po<strong>in</strong>ts to add species to the empty frame.<br />
If the user does not ask specifically, the function will use text <strong>in</strong><br />
small data sets and po<strong>in</strong>ts <strong>in</strong> large data sets.<br />
3. It adds the sites similarly.<br />
For better control <strong>of</strong> the plots we must repeat these stages by hand: draw<br />
an empty plot and then add sites and/or species as desired.<br />
In this chapter we study a difficult case: plott<strong>in</strong>g the Barro Colorado<br />
Island ord<strong>in</strong>ations.<br />
12
2 ORDINATION: BASIC METHOD 2.6 Ord<strong>in</strong>ation graphics<br />
> data(BCI)<br />
This is a difficult data set for plott<strong>in</strong>g: it has 225 species and there is no<br />
way <strong>of</strong> labell<strong>in</strong>g them all cleanly – unless we use very large plott<strong>in</strong>g area<br />
with small text. We must show only a selection <strong>of</strong> the species or small<br />
parts <strong>of</strong> the plot. First an ord<strong>in</strong>ation with decorana and its default plot:<br />
> mod plot(mod)<br />
There is an additional problem <strong>in</strong> plott<strong>in</strong>g species ord<strong>in</strong>ation with these<br />
data:<br />
> names(BCI)[1:5]<br />
[1] "Abarema.macradenium" "Acacia.melanoceras"<br />
[3] "Acalypha.diversifolia" "Acalypha.macrostachya"<br />
[5] "Adelia.triloba"<br />
The data set uses full species names, and there is no way <strong>of</strong> fitt<strong>in</strong>g those<br />
<strong>in</strong> ord<strong>in</strong>ation graphs. There is a utility function make.cepnames <strong>in</strong> <strong>vegan</strong><br />
to abbreviate Lat<strong>in</strong> names:<br />
> shnam shnam[1:5]<br />
[1] "Abarmacr" "Acacmela" "Acaldive" "Acalmacr" "Adeltril"<br />
The easiest way to selectively label species is to use <strong>in</strong>teractive identify<br />
function: when you click next to a po<strong>in</strong>t, its label will appear on the<br />
side you clicked. You can f<strong>in</strong>ish labell<strong>in</strong>g click<strong>in</strong>g the right mouse button,<br />
or with handicapped one-button mouse, you can hit the esc key.<br />
> pl identify(pl, "sp", labels=shnam)<br />
There is an “ord<strong>in</strong>ation text or po<strong>in</strong>ts” function orditorp <strong>in</strong> <strong>vegan</strong>.<br />
This function will label an item only if this can be done without overwrit<strong>in</strong>g<br />
previous labels. If an item cannot be labelled with text, it will be<br />
marked as a po<strong>in</strong>t. Items are processed either from the marg<strong>in</strong> toward<br />
the centre, or <strong>in</strong> decreas<strong>in</strong>g order <strong>of</strong> priority. The follow<strong>in</strong>g gives higher<br />
priority to the most abundant species:<br />
> stems plot(mod, dis="sp", type="n")<br />
> sel
DCA2<br />
−4 −2 0 2 4<br />
Casecomm<br />
Alchlati<br />
Abarmacr<br />
Ochrpyra Schipara Pachqu<strong>in</strong><br />
Pourbico Ficucolu Sipaguia Laetproc Lafopuni Cupac<strong>in</strong>e Micoelat<br />
Myrcgatu Garcmadr Micohond Entescho<br />
Tricgale Desmpana MicoaffiPachsess<br />
Ficuyopo<br />
Hampappe Guargran<br />
Ormoamaz Cuparufe<br />
Cedrodor Ingaspec Spacmemb Solahaye Coluglan Chimparv<br />
Margnobi<br />
Alibedul Tal<strong>in</strong>erv<br />
Heisacum Nectpurp Chamschi Tricgiga Chlot<strong>in</strong>c<br />
Ingaoers<br />
Ficupope<br />
Pipereti Acalmacr<br />
Poutfoss Tocopitt<br />
Talipr<strong>in</strong> Ingapunc Ficu<strong>in</strong>si<br />
Ingaruiz Ormomacr<br />
Tetrjoha<br />
Coccmanz Pseusept<br />
Theocaca Zuelguid Nectl<strong>in</strong>e Eugegala Vochferr<br />
Acaldive<br />
Ficucost Acacmela<br />
Ingalaur<br />
Ormococc<br />
Myr<strong>of</strong>rut Banaguia Psycgran<br />
Ficumaxi Ficuobtu<br />
Psidfrie<br />
Caseguia<br />
Vismbacc Cupalati<br />
Sapibroa Marilaxi Ficutrig<br />
Licaplat Cespmacr<br />
Chryecli Thevahou<br />
Ingaumbe<br />
Perexant<br />
Sipapauc Ingacocl<br />
Nectciss Ocotpube Laettham<br />
Zantjuni Zantpana<br />
Cocccoro<br />
Cupasylv Plateleg<br />
Phoec<strong>in</strong>n Licahypo<br />
Diptpana<br />
Mosagarw Cecrobtu Protpana<br />
Platp<strong>in</strong>n<br />
Turpocci Sponradl Sponmomb<br />
Aegipana Laciaggr<br />
Ocotcern Astrgrav<br />
Sympglob Eugenesi Erytmacr Tabeguay Micoarge<br />
Annospra Cordalli<br />
Termamaz<br />
Poutstip Tremmicr Ceibpent<br />
Lacmpana Couscurv Elaeolei<br />
Ingagold Ingasapi<br />
Ficutond Maytschi Trataspe Calolong<br />
Celtschi Troprace Chryca<strong>in</strong><br />
Sapiglan<br />
Apeitibo<br />
Erytcost Andi<strong>in</strong>er<br />
Guarfuzz<br />
Diosarta Sterapet Allopsil Casesylv<br />
L<strong>in</strong>dlaur<br />
Guazulmi<br />
Soroaffi Geniamer<br />
Attabuty<br />
Hyeralch<br />
Sloatern<br />
Inganobi<br />
Ocotoblo Caseacul<br />
Taberose Aspicrue<br />
Viromult AnacexceCavaplat<br />
Macrrose<br />
Tropcauc<br />
Ingaacum<br />
Termoblo<br />
Picrlati<br />
Posolati Ingapezi<br />
Pterrohr<br />
Socrexor<br />
Cordbico Dendarbo<br />
Cecr<strong>in</strong>si<br />
Simaamar<br />
Zantekma Jacacopa Tabearbo Priocopa Casearbo<br />
Unonpitt<br />
Chryarge Casselli Lonclati<br />
Maqucost Protcost Hassflor<br />
Apeiaspe<br />
Guatdume Oenomapo<br />
Virosebi Swarochn Tricpall<br />
Tachvers Crotbill Poutreti Swargran Eugeoers Faraocci Trictube<br />
Beilpend<br />
Guetfoli Alseblac<br />
Guapstan Randarma<br />
Tetrpana<br />
Ingamarg Brosalic Eugecolo Alchcost Adeltril<br />
Heisconc Garc<strong>in</strong>te Luehseem Gustsupe<br />
Poularma Quaraste<br />
Astrstan<br />
Ocotwhit Virosuri CordlasiTripcumi<br />
Hirttria Prottenu Guarguid<br />
Xylomacr Huracrep<br />
Drypstan<br />
Brosguia<br />
Hirtamer<br />
Quasamar<br />
Amaicory<br />
Senndari Zantsetu<br />
−6 −4 −2 0 2 4 6<br />
DCA1<br />
3 ENVIRONMENTAL INTERPRETATION<br />
> plot(mod, dis="sp", type="n")<br />
> ordilabel(mod, dis="sp", lab=shnam, priority = stems)<br />
F<strong>in</strong>ally, there is function ordipo<strong>in</strong>tlabel which uses both po<strong>in</strong>ts and<br />
labels to these po<strong>in</strong>ts. The po<strong>in</strong>ts are <strong>in</strong> fixed positions, but the labels are<br />
iteratively located to m<strong>in</strong>imize their overlap. The Barro Colorado Island<br />
data set has much too many names for the ordipo<strong>in</strong>tlabel function, but<br />
it can be useful <strong>in</strong> many cases.<br />
In addition to these automatic functions, function orditkplot allows<br />
edit<strong>in</strong>g <strong>of</strong> plots. It has po<strong>in</strong>ts <strong>in</strong> fixed positions with labels that can<br />
be dragged to better places with a mouse. The function uses different<br />
graphical toolset (Tcl/Tk) than ord<strong>in</strong>ary R graphics, but the results can<br />
be passed to standard R plot functions for edit<strong>in</strong>g or directly saved as<br />
graphics files. Moreover, the ordipo<strong>in</strong>tlabel ouput can be edited us<strong>in</strong>g<br />
orditkplot.<br />
Functions identify, orditorp, ordilabel and ordipo<strong>in</strong>tlabel may<br />
provide a quick and easy way to <strong>in</strong>spect ord<strong>in</strong>ation results. Often we need<br />
a better control <strong>of</strong> graphics, and judicuously select the labelled species.<br />
In that case we can first draw an empty plot (with type = "n"), and<br />
then use select argument <strong>in</strong> ord<strong>in</strong>ation text and po<strong>in</strong>ts functions. The<br />
select argument can be a numeric vector that lists the <strong>in</strong>dices <strong>of</strong> selected<br />
items. Such <strong>in</strong>dices are displayed from identify functions which can be<br />
used to help <strong>in</strong> select<strong>in</strong>g the items. Alternatively, select can be a logical<br />
vector which is TRUE to selected items. Such a list was produced <strong>in</strong>visibly<br />
from orditorp. You cannot see <strong>in</strong>visible results directly from the method,<br />
but you can catch the result like we did above <strong>in</strong> the first orditorp call,<br />
and use this vector as a basis for fully controlled graphics. In this case<br />
the first items were:<br />
> sel[1:14]<br />
Abarmacr Acacmela Acaldive Acalmacr Adeltril Aegipana Alchcost<br />
FALSE FALSE FALSE FALSE FALSE FALSE FALSE<br />
Alchlati Alibedul Allopsil Alseblac Amaicory Anacexce Andi<strong>in</strong>er<br />
TRUE FALSE FALSE FALSE TRUE TRUE FALSE<br />
3 Environmental <strong>in</strong>terpretation<br />
It is <strong>of</strong>ten possible to “expla<strong>in</strong>” ord<strong>in</strong>ation us<strong>in</strong>g ecological knowledge on<br />
studied sites, or knowledge on the ecological characteristics <strong>of</strong> species.<br />
Usually it is preferable to use external environmental variables to <strong>in</strong>terpret<br />
the ord<strong>in</strong>ation. There are many ways <strong>of</strong> overlay<strong>in</strong>g environmental<br />
<strong>in</strong>formation onto ord<strong>in</strong>ation diagrams. One <strong>of</strong> the simplest is to change<br />
the size <strong>of</strong> plott<strong>in</strong>g characters accord<strong>in</strong>g to an environmental variables<br />
(argument cex <strong>in</strong> plot functions). The <strong>vegan</strong> package has some useful<br />
functions for fitt<strong>in</strong>g environmental variables.<br />
3.1 Vector fitt<strong>in</strong>g<br />
The most commonly used method <strong>of</strong> <strong>in</strong>terpretation is to fit environmental<br />
vectors onto ord<strong>in</strong>ation. The fitted vectors are arrows with the <strong>in</strong>terpretation:<br />
14
3 ENVIRONMENTAL INTERPRETATION 3.2 Surface fitt<strong>in</strong>g<br />
The arrow po<strong>in</strong>ts to the direction <strong>of</strong> most rapid change <strong>in</strong> the the<br />
environmental variable. Often this is called the direction <strong>of</strong> the<br />
gradient.<br />
The length <strong>of</strong> the arrow is proportional to the correlation between<br />
ord<strong>in</strong>ation and environmental variable. Often this is called the<br />
strength <strong>of</strong> the gradient.<br />
Fitt<strong>in</strong>g environmental vectors is easy us<strong>in</strong>g function envfit. The<br />
example uses the previous nmds result and environmental variables <strong>in</strong><br />
the data set varechem:<br />
> data(varechem)<br />
> ef ef<br />
***VECTORS<br />
NMDS1 NMDS2 r2 Pr(>r)<br />
N -0.0573 -0.9984 0.25 0.036 *<br />
P 0.6197 0.7848 0.19 0.101<br />
K 0.7665 0.6423 0.18 0.114<br />
Ca 0.6852 0.7283 0.41 0.003 **<br />
Mg 0.6325 0.7745 0.43 0.004 **<br />
S 0.1914 0.9815 0.18 0.132<br />
Al -0.8716 0.4902 0.53 0.001 ***<br />
Fe -0.9360 0.3520 0.45 0.001 ***<br />
Mn 0.7987 -0.6017 0.52 0.001 ***<br />
Zn 0.6176 0.7865 0.19 0.108<br />
Mo -0.9031 0.4294 0.06 0.512<br />
Baresoil 0.9249 -0.3803 0.25 0.055 .<br />
Humdepth 0.9328 -0.3604 0.52 0.003 **<br />
pH -0.6480 0.7617 0.23 0.060 .<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
P values based on 999 permutations.<br />
The first two columns give direction cos<strong>in</strong>es <strong>of</strong> the vectors, and r2 gives<br />
the squared correlation coefficient. For plott<strong>in</strong>g, the axes should be scaled<br />
by the square root <strong>of</strong> r2. The plot function does this automatically, and<br />
you can extract the scaled values with scores(ef, "vectors"). The<br />
significances (Pr>r), or P -values are based on random permutations <strong>of</strong><br />
the data: if you <strong>of</strong>ten get as good or better R 2 with randomly permuted<br />
data, your values are <strong>in</strong>significant.<br />
You can add the fitted vectors to an ord<strong>in</strong>ation us<strong>in</strong>g plot command.<br />
You can limit plott<strong>in</strong>g to most significant variables with argument p.max.<br />
As usual, more options can be found <strong>in</strong> the help pages.<br />
> plot(vare.mds, display = "sites")<br />
> plot(ef, p.max = 0.1)<br />
3.2 Surface fitt<strong>in</strong>g<br />
Vector fitt<strong>in</strong>g is popular, and it provides a compact way <strong>of</strong> simultaneously<br />
display<strong>in</strong>g a large number <strong>of</strong> environmental variables. However, it implies<br />
15<br />
NMDS2<br />
−0.4 −0.2 0.0 0.2 0.4<br />
●<br />
●<br />
Al<br />
Fe<br />
●<br />
●<br />
●<br />
pH<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
N<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
−0.4 −0.2 0.0 0.2 0.4 0.6<br />
NMDS1<br />
●<br />
●<br />
●<br />
Mg<br />
Ca<br />
Baresoil<br />
Humdepth<br />
Mn<br />
●<br />
●<br />
●
NMDS2<br />
−0.4 −0.2 0.0 0.2 0.4<br />
3.3 Factors 3 ENVIRONMENTAL INTERPRETATION<br />
●<br />
200<br />
450<br />
350<br />
300<br />
300<br />
200<br />
●<br />
Al<br />
400<br />
250<br />
250<br />
500<br />
550<br />
●<br />
150<br />
●<br />
●<br />
600<br />
●<br />
●<br />
●<br />
650<br />
●<br />
●<br />
●<br />
●<br />
●<br />
50<br />
●<br />
700<br />
●<br />
● ●<br />
●<br />
−0.4 −0.2 0.0 0.2 0.4 0.6<br />
NMDS1<br />
●<br />
●<br />
●<br />
0<br />
Ca<br />
800<br />
100<br />
750<br />
●<br />
●<br />
●<br />
a l<strong>in</strong>ear relationship between ord<strong>in</strong>ation and environment: direction and<br />
strength are all you need to know. This may not always be appropriate.<br />
Function ordisurf fits surfaces <strong>of</strong> environmental variables to ord<strong>in</strong>ations.<br />
It uses generalized additive models <strong>in</strong> function gam <strong>of</strong> package<br />
mgcv. Function gam uses th<strong>in</strong>plate spl<strong>in</strong>es <strong>in</strong> two dimensions, and automatically<br />
selects the degree <strong>of</strong> smooth<strong>in</strong>g by generalized cross-validation.<br />
If the response really is l<strong>in</strong>ear and vectors are appropriate, the fitted surface<br />
is a plane whose gradient is parallel to the arrow, and the fitted<br />
contours are equally spaced parallel l<strong>in</strong>es perpendicular to the arrow.<br />
In the follow<strong>in</strong>g example I <strong>in</strong>troduce two new R features:<br />
Function envfit can be called with formula <strong>in</strong>terface. Formula<br />
has a special character tilde (∼), and the left-hand side gives the<br />
ord<strong>in</strong>ation results, and the right-hand side lists the environmental<br />
variables. In addition, we must def<strong>in</strong>e the name <strong>of</strong> the data conta<strong>in</strong><strong>in</strong>g<br />
the fitted variables.<br />
The variables <strong>in</strong> data frames are not visible to R session unless the<br />
data frame is attached to the session. We may not want to make all<br />
variables visible to the session, because there may be synonymous<br />
names, and we may use wrong variables with the same name <strong>in</strong><br />
some analyses. We can use function with which makes the given<br />
data frame visible only to the follow<strong>in</strong>g command.<br />
Now we are ready for the example. We make vector fitt<strong>in</strong>g for selected<br />
variables and add fitted surfaces <strong>in</strong> the same plot.<br />
> ef plot(vare.mds, display = "sites")<br />
> plot(ef)<br />
> tmp with(varechem, ordisurf(vare.mds, Ca, add = TRUE, col = "green4"))<br />
Function ordisurf returns the result <strong>of</strong> fitted gam. If we save that<br />
result, like we did <strong>in</strong> the first fit with Al, we can use it for further analyses,<br />
such as statistical test<strong>in</strong>g and prediction <strong>of</strong> new values. For <strong>in</strong>stance,<br />
fitted(ef) will give the actual fitted values for sites.<br />
3.3 Factors<br />
Class centroids are a natural choice for factor variables, and R 2 can be<br />
used as a goodness-<strong>of</strong>-fit statistic. The “significance” can be tested with<br />
permutations just like <strong>in</strong> vector fitt<strong>in</strong>g. Variables can be def<strong>in</strong>ed as factors<br />
<strong>in</strong> R, and they will be treated accord<strong>in</strong>gly without any special tricks.<br />
As an example, we shall <strong>in</strong>spect dune meadow data which has several<br />
class variables. Function envfit also works with factors:<br />
> data(dune)<br />
> data(dune.env)<br />
> dune.ca ef ef<br />
16
3 ENVIRONMENTAL INTERPRETATION 3.3 Factors<br />
***VECTORS<br />
CA1 CA2 r2 Pr(>r)<br />
A1 0.9982 0.0606 0.31 0.043 *<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
P values based on 999 permutations.<br />
***FACTORS:<br />
Centroids:<br />
CA1 CA2<br />
Moisture1 -0.75 -0.14<br />
Moisture2 -0.47 -0.22<br />
Moisture4 0.18 -0.73<br />
Moisture5 1.11 0.57<br />
ManagementBF -0.73 -0.14<br />
ManagementHF -0.39 -0.30<br />
ManagementNM 0.65 1.44<br />
ManagementSF 0.34 -0.68<br />
UseHayfield -0.29 0.65<br />
UseHaypastu -0.07 -0.56<br />
UsePasture 0.52 0.05<br />
Manure0 0.65 1.44<br />
Manure1 -0.46 -0.17<br />
Manure2 -0.59 -0.36<br />
Manure3 0.52 -0.32<br />
Manure4 -0.21 -0.88<br />
Goodness <strong>of</strong> fit:<br />
r2 Pr(>r)<br />
Moisture 0.41 0.005 **<br />
Management 0.44 0.001 ***<br />
Use 0.18 0.079 .<br />
Manure 0.46 0.010 **<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
P values based on 999 permutations.<br />
> plot(dune.ca, display = "sites")<br />
> plot(ef)<br />
The names <strong>of</strong> factor centroids are formed by comb<strong>in</strong><strong>in</strong>g the name <strong>of</strong><br />
the factor and the name <strong>of</strong> the level. Now the axes show the centroids<br />
for the level, and the R 2 values are for the whole factor, just like the<br />
significance test. The plot looks congested, and we may use tricks <strong>of</strong> §2.6<br />
(p. 12) to make cleaner plots, but obviously not all factors are necessary<br />
<strong>in</strong> <strong>in</strong>terpretation.<br />
Package <strong>vegan</strong> has several functions for graphical display <strong>of</strong> factors.<br />
Function ordihull draws an enclos<strong>in</strong>g convex hull for the items <strong>in</strong> a<br />
class, ordispider comb<strong>in</strong>es items to their (weighted) class centroid, and<br />
ordiellipse draws ellipses for class standard deviations, standard errors<br />
or confidence areas. The example displays all these for Management<br />
type <strong>in</strong> the previous ord<strong>in</strong>ation and automatically labels the groups <strong>in</strong><br />
17<br />
CA2<br />
−1 0 1 2 3<br />
17<br />
19<br />
UseHayfield 18<br />
11<br />
ManagementNM<br />
Manure0<br />
6 UsePasture<br />
10<br />
ManagementBF<br />
Moisture1<br />
5<br />
7Moisture2<br />
Manure1<br />
ManagementHF 8<br />
Manure2 Manure3<br />
UseHaypastu<br />
2 ManagementSF<br />
12<br />
Moisture4<br />
4 9<br />
Manure4 13<br />
3<br />
1<br />
−2 −1 0 1 2<br />
CA1<br />
Moisture5<br />
20<br />
15 14<br />
16<br />
A1
CA2<br />
−1 0 1 2 3<br />
●<br />
●<br />
● BF<br />
●<br />
HF<br />
●<br />
●<br />
●<br />
●<br />
●<br />
SF ●<br />
● ●<br />
●<br />
●<br />
−2 −1 0 1 2<br />
CA1<br />
NM<br />
●<br />
●<br />
●<br />
●<br />
ordispider command:<br />
4 CONSTRAINED ORDINATION<br />
> plot(dune.ca, display = "sites", type = "p")<br />
> with(dune.env, ordiellipse(dune.ca, Management, k<strong>in</strong>d = "se", conf = 0.95))<br />
> with(dune.env, ordispider(dune.ca, Management, col = "blue", label= TRUE))<br />
> with(dune.env, ordihull(dune.ca, Management, col="blue", lty=2))<br />
Correspondence analysis is a weighted ord<strong>in</strong>ation method, and <strong>vegan</strong><br />
functions envfit and ordisurf will do weighted fitt<strong>in</strong>g, unless the user<br />
specifies equal weights.<br />
4 Constra<strong>in</strong>ed ord<strong>in</strong>ation<br />
In unconstra<strong>in</strong>ed ord<strong>in</strong>ation we first f<strong>in</strong>d the major compositional variation,<br />
and then relate this variation to observed environmental variation.<br />
In constra<strong>in</strong>ed ord<strong>in</strong>ation we do not want to display all or even most <strong>of</strong><br />
the compositional variation, but only the variation that can be expla<strong>in</strong>ed<br />
by the used environmental variables, or constra<strong>in</strong>ts. Constra<strong>in</strong>ed ord<strong>in</strong>ation<br />
is <strong>of</strong>ten known as “canonical” ord<strong>in</strong>ation, but this name is mislead<strong>in</strong>g:<br />
there is noth<strong>in</strong>g particularly canonical <strong>in</strong> these methods (see your favorite<br />
Dictionary for the term). The name was taken <strong>in</strong>to use, because there<br />
is one special statistical method, canonical correlations, but these <strong>in</strong>deed<br />
are canonical: they are correlations between two matrices regarded to be<br />
symmetrically dependent on each other. The constra<strong>in</strong>ed ord<strong>in</strong>ation is<br />
non-symmetric: we have “<strong>in</strong>dependent” variables or constra<strong>in</strong>ts and we<br />
have “dependent” variables or the community. Constra<strong>in</strong>ed ord<strong>in</strong>ation<br />
rather is related to multivariate l<strong>in</strong>ear models.<br />
The <strong>vegan</strong> package has three constra<strong>in</strong>ed ord<strong>in</strong>ation methods which<br />
all are constra<strong>in</strong>ed versions <strong>of</strong> basic ord<strong>in</strong>ation methods:<br />
Constra<strong>in</strong>ed analysis <strong>of</strong> proximities (cap) <strong>in</strong> function capscale is<br />
related to metric scal<strong>in</strong>g (cmdscale). It can handle any dissimilarity<br />
measures and performs a l<strong>in</strong>ear mapp<strong>in</strong>g.<br />
Redundancy analysis (rda) <strong>in</strong> function rda is related to pr<strong>in</strong>cipal<br />
components analysis. It is based on Euclidean distances and performs<br />
l<strong>in</strong>ear mapp<strong>in</strong>g.<br />
Constra<strong>in</strong>ed correspondence analysis (cca) <strong>in</strong> function cca is related<br />
to correspondence analysis. It is based on Chi-squared distances<br />
and performs weighted l<strong>in</strong>ear mapp<strong>in</strong>g.<br />
We have already used functions rda and cca for unconstra<strong>in</strong>ed ord<strong>in</strong>ation:<br />
they will perform the basic unconstra<strong>in</strong>ed method as a special case if<br />
constra<strong>in</strong>ts are not used.<br />
All these three <strong>vegan</strong> functions are very similar. The follow<strong>in</strong>g examples<br />
ma<strong>in</strong>ly use cca, but other methods can be used similarly. Actually,<br />
the results are similarly structured, and they <strong>in</strong>herit properties from each<br />
other. For historical reasons, cca is the basic method, and rda <strong>in</strong>herits<br />
properties from it. Function capscale <strong>in</strong>herits directly from rda, and<br />
through this from cca. Many functions, are common with all these methods,<br />
and there are specific functions only if the method deviates from its<br />
18
4 CONSTRAINED ORDINATION 4.1 Model specification<br />
ancestor. In <strong>vegan</strong> version 2.0-6 the follow<strong>in</strong>g class functions are def<strong>in</strong>ed<br />
for these methods:<br />
cca: add1, alias, anova, as.mlm, bstick, calibrate, coef, deviance,<br />
drop1, eigenvals, extractAIC, fitted, goodness, model.frame, model.matrix,<br />
nobs, permutest, plot, po<strong>in</strong>ts, predict, pr<strong>in</strong>t, residuals, RsquareAdj,<br />
scores, screeplot, simulate, summary, text, tolerance, weights<br />
rda: as.mlm, biplot, coef, deviance, fitted, goodness, predict,<br />
RsquareAdj, scores, simulate, weights<br />
capscale: fitted, pr<strong>in</strong>t, simulate.<br />
Many <strong>of</strong> these methods are <strong>in</strong>ternal functions that users rarely need.<br />
4.1 Model specification<br />
The recommended way <strong>of</strong> def<strong>in</strong><strong>in</strong>g a constra<strong>in</strong>ed model is to use model<br />
formula. Formula has a special character ∼, and on its left-hand side<br />
gives the name <strong>of</strong> the community data, and right-hand gives the equation<br />
for constra<strong>in</strong>ts. In addition, you should give the name <strong>of</strong> the data set<br />
where to f<strong>in</strong>d the constra<strong>in</strong>ts. This fits a cca for varespec constra<strong>in</strong>ed<br />
by soil Al, K and P:<br />
> vare.cca vare.cca<br />
Call: cca(formula = varespec ~ Al + P + K, data =<br />
varechem)<br />
Inertia Proportion Rank<br />
Total 2.083 1.000<br />
Constra<strong>in</strong>ed 0.644 0.309 3<br />
Unconstra<strong>in</strong>ed 1.439 0.691 20<br />
Inertia is mean squared cont<strong>in</strong>gency coefficient<br />
Eigenvalues for constra<strong>in</strong>ed axes:<br />
CCA1 CCA2 CCA3<br />
0.362 0.170 0.113<br />
Eigenvalues for unconstra<strong>in</strong>ed axes:<br />
CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8<br />
0.3500 0.2201 0.1851 0.1551 0.1351 0.1003 0.0773 0.0537<br />
(Showed only 8 <strong>of</strong> all 20 unconstra<strong>in</strong>ed eigenvalues)<br />
The output is similar as <strong>in</strong> unconstra<strong>in</strong>ed ord<strong>in</strong>ation. Now the total<br />
<strong>in</strong>ertia is decomposed <strong>in</strong>to constra<strong>in</strong>ed and unconstra<strong>in</strong>ed components.<br />
There were three constra<strong>in</strong>ts, and the rank <strong>of</strong> constra<strong>in</strong>ed component<br />
is three. The rank <strong>of</strong> unconstra<strong>in</strong>ed component is 20, when it used to<br />
be 23 <strong>in</strong> the previous analysis. The rank is the same as the number <strong>of</strong><br />
axes: you have 3 constra<strong>in</strong>ed axes and 20 unconstra<strong>in</strong>ed axes. In some<br />
cases, the ranks may be lower than the number <strong>of</strong> constra<strong>in</strong>ts: some <strong>of</strong><br />
the constra<strong>in</strong>ts are dependent on each other, and they are aliased <strong>in</strong> the<br />
analysis, and an <strong>in</strong>formative message is pr<strong>in</strong>ted with the result.<br />
It is very common to calculate the proportion <strong>of</strong> constra<strong>in</strong>ed <strong>in</strong>ertia<br />
from the total <strong>in</strong>ertia. However, total <strong>in</strong>ertia does not have a clear mean<strong>in</strong>g<br />
<strong>in</strong> cca, and the mean<strong>in</strong>g <strong>of</strong> this proportion is just as obscure. In rda<br />
19
CCA2<br />
CCA3<br />
CCA2<br />
−2 −1 0 1 2<br />
−3 −2 −1 0 1 2 3 4<br />
−2 −1 0 1 2<br />
4.1 Model specification 4 CONSTRAINED ORDINATION<br />
28<br />
22<br />
24<br />
16<br />
Bar.lyc<br />
Bet.pub<br />
−3 −2 −1 0 1 2<br />
●<br />
14<br />
CCA1<br />
Cal.vul<br />
21<br />
Led.pal<br />
Dic.fus Cla.bot Pti.cil Ich.eri 18<br />
Pol.com<br />
Cla.arb Vac.uli<br />
Vac.myr Emp.nig Cla.ran<br />
P<strong>in</strong>.syl Dip.mon<br />
Des.fle<br />
Dic.pol Cla.unc Vac.vit<br />
Pol.pil<br />
Ple.sch Pol.jun Poh.nut<br />
Cla.ste<br />
Hyl.spl<br />
Dic.sp<br />
Cla.coc<br />
15<br />
23<br />
Cla.cri Ste.sp<br />
Cla.fim<br />
20 Cla.defCla.ama<br />
Cla.gra<br />
Cet.isl<br />
Cla.cor<br />
Cet.eri Cla.chl Cla.sp 11<br />
KNep.arc<br />
Pel.aph<br />
27<br />
19<br />
Cla.phy<br />
25<br />
3<br />
4<br />
Al<br />
12 Cla.cer<br />
2<br />
−4 −3 −2 −1 0 1 2 3<br />
●<br />
●<br />
●<br />
CCA1<br />
P<br />
●<br />
● ●<br />
●<br />
●<br />
●●<br />
● ●<br />
●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
●<br />
13<br />
6<br />
7 5<br />
10 Cet.niv<br />
9<br />
1<br />
0<br />
−1<br />
−2<br />
−3<br />
Viclat<br />
2<br />
Achmil<br />
ManagementHF<br />
Tripra Brohor<br />
Plalan<br />
19<br />
1<br />
Antodo<br />
Rumace<br />
Trirep<br />
Lolper Leoaut<br />
Hyprad<br />
Poapra<br />
Belper<br />
Brarut Junart<br />
ManagementNM<br />
Empnig Salrep Potpal Airpra<br />
Elyrep Poatri<br />
Elepal Ranfla<br />
JunbufSagpro<br />
Calcus<br />
9Alogen<br />
Agrsto<br />
3<br />
8<br />
4<br />
ManagementSF<br />
Chealb Cirarv<br />
12<br />
13<br />
10<br />
6<br />
75<br />
ManagementBF 11<br />
4<br />
3<br />
2<br />
−2 −1 0 1 2 3<br />
18<br />
CCA1<br />
16<br />
17<br />
14<br />
15<br />
20<br />
CCA2<br />
−1 0 1<br />
this would be the proportion <strong>of</strong> variance (or correlation). This may have<br />
a clearer mean<strong>in</strong>g, but even <strong>in</strong> this case most <strong>of</strong> the total <strong>in</strong>ertia may be<br />
random noise. It may be better to concentrate on results <strong>in</strong>stead <strong>of</strong> these<br />
proportions.<br />
Basic plott<strong>in</strong>g works just like earlier:<br />
> plot(vare.cca)<br />
have similar <strong>in</strong>terpretation as fitted vectors: the arrow po<strong>in</strong>ts to the direction<br />
<strong>of</strong> the gradient, and its length <strong>in</strong>dicates the strength <strong>of</strong> the variable<br />
<strong>in</strong> this dimensionality <strong>of</strong> solution. The vectors will be <strong>of</strong> unit length <strong>in</strong><br />
full rank solution, but they are projected to the plane used <strong>in</strong> the plot.<br />
There is also a primitive 3D plott<strong>in</strong>g function ordiplot3d (which needs<br />
user <strong>in</strong>teraction for f<strong>in</strong>al graphs) that shows all arrows <strong>in</strong> full length:<br />
> ordiplot3d(vare.cca, type = "h")<br />
With function ordirgl you can also <strong>in</strong>spect 3D dynamic plots that can<br />
be sp<strong>in</strong>ned or zoomed <strong>in</strong>to with your mouse.<br />
The formula <strong>in</strong>terface works with factor variables as well:<br />
> dune.cca plot(dune.cca)<br />
> dune.cca<br />
Call: cca(formula = dune ~ Management, data = dune.env)<br />
Inertia Proportion Rank<br />
Total 2.115 1.000<br />
Constra<strong>in</strong>ed 0.604 0.285 3<br />
Unconstra<strong>in</strong>ed 1.511 0.715 16<br />
Inertia is mean squared cont<strong>in</strong>gency coefficient<br />
Eigenvalues for constra<strong>in</strong>ed axes:<br />
CCA1 CCA2 CCA3<br />
0.319 0.182 0.103<br />
Eigenvalues for unconstra<strong>in</strong>ed axes:<br />
CA1 CA2 CA3 CA4 CA5 CA6 CA7<br />
0.44737 0.20300 0.16301 0.13457 0.12940 0.09494 0.07904<br />
CA8 CA9 CA10 CA11 CA12 CA13 CA14<br />
0.06526 0.05004 0.04321 0.03870 0.02385 0.01773 0.00917<br />
CA15 CA16<br />
0.00796 0.00416<br />
Factor variable Management had four levels (BF, HF, NM, SF). Internally<br />
R expressed these four levels as three contrasts (sometimes called“dummy<br />
variables”). The applied contrasts look like this:<br />
ManagementHF ManagementNM ManagementSF<br />
BF 0 0 0<br />
SF 0 0 1<br />
HF 1 0 0<br />
NM 0 1 0<br />
We do not need but three variables to express four levels: if there is<br />
number one <strong>in</strong> a column, the observation belongs to that level, and if<br />
20
4 CONSTRAINED ORDINATION 4.2 Permutation tests<br />
there is a whole l<strong>in</strong>e <strong>of</strong> zeros, the observation must belong to the omitted<br />
level, or the first. The basic plot function displays class centroids <strong>in</strong>stead<br />
<strong>of</strong> vectors for factors.<br />
In addition to these ord<strong>in</strong>ary factors, R also knows ordered factors.<br />
Variable Moisture <strong>in</strong> dune.env is def<strong>in</strong>ed as an ordered four-level factor.<br />
In this case the contrasts look different:<br />
Moisture.L Moisture.Q Moisture.C<br />
1 -0.6708 0.5 -0.2236<br />
2 -0.2236 -0.5 0.6708<br />
4 0.2236 -0.5 -0.6708<br />
5 0.6708 0.5 0.2236<br />
R uses polynomial contrasts: the l<strong>in</strong>ear term L is equal to treat<strong>in</strong>g<br />
Moisture as a cont<strong>in</strong>uous variable, and the quadratic Q and cubic C terms<br />
show nonl<strong>in</strong>ear features. There were four dist<strong>in</strong>ct levels, and the number<br />
<strong>of</strong> contrasts is one less, just like with ord<strong>in</strong>ary contrasts. The ord<strong>in</strong>ation<br />
configuration, eigenvalues or rank do not change if the factor is unordered<br />
or ordered, but the presentation <strong>of</strong> the factor <strong>in</strong> the results may change:<br />
> vare.cca plot(vare.cca)<br />
Now plot shows both the centroids <strong>of</strong> factor levels and the contrasts.<br />
If we could change the ordered factor to a cont<strong>in</strong>uous vector, only the<br />
l<strong>in</strong>ear effect arrow would be important. If the response to the variable is<br />
nonl<strong>in</strong>ear, the quadratic (and cubic) arrows would be long as well.<br />
I have expla<strong>in</strong>ed only the simplest usage <strong>of</strong> the formula <strong>in</strong>terface. The<br />
formula is very powerful <strong>in</strong> model specification: you can transform your<br />
contrasts with<strong>in</strong> the formula, you can def<strong>in</strong>e <strong>in</strong>teractions, you can use<br />
polynomial contrasts etc. However, models with <strong>in</strong>teractions or polynomials<br />
may be difficult to <strong>in</strong>terpret.<br />
4.2 Permutation tests<br />
The significance <strong>of</strong> all terms together can be assessed us<strong>in</strong>g permutation<br />
tests: the dat are permuted randomly and the model is refitted. When<br />
constra<strong>in</strong>ed <strong>in</strong>ertia <strong>in</strong> permutations is nearly always lower than observed<br />
constra<strong>in</strong>ed <strong>in</strong>ertia, we say that constra<strong>in</strong>ts are significant.<br />
The easiest way <strong>of</strong> runn<strong>in</strong>g permutation tests is to use the mock anova<br />
function <strong>in</strong> <strong>vegan</strong>:<br />
> anova(vare.cca)<br />
Permutation test for cca under reduced model<br />
Model: cca(formula = dune ~ Moisture, data = dune.env)<br />
Df Chisq F N.Perm Pr(>F)<br />
Model 3 0.63 2.25 199 0.005 **<br />
Residual 16 1.49<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
The Model refers to the constra<strong>in</strong>ed component, and Residual to the<br />
unconstra<strong>in</strong>ed component <strong>of</strong> the ord<strong>in</strong>ation, Chisq is the correspond<strong>in</strong>g<br />
21<br />
CCA2<br />
−2 −1 0 1 2 3<br />
3<br />
4<br />
Junbuf<br />
Sagpro Alogen<br />
Elyrep<br />
Rumace<br />
8<br />
Junart Moisture.L<br />
1<br />
Moisture2 CirarvPoatri<br />
Trirep<br />
Agrsto<br />
2<br />
Poapra Brarut<br />
Belper Leoaut<br />
7<br />
Viclat<br />
Achmil Brohor Lolper<br />
5<br />
Antodo<br />
Plalan<br />
Airpra<br />
Tripra<br />
Hyprad<br />
Moisture1<br />
SalrepMoisture5<br />
Empnig Chealb Calcus Ranfla Potpal Elepal<br />
16<br />
6 11<br />
10<br />
18 Moisture.C 19<br />
15<br />
17<br />
9<br />
12<br />
Moisture4<br />
−2 −1 0 1 2 3<br />
13<br />
Moisture.Q<br />
CCA1<br />
20<br />
14<br />
0 1
4.2 Permutation tests 4 CONSTRAINED ORDINATION<br />
F = 0.628/3<br />
= 2.254<br />
attention<br />
1.487/16<br />
<strong>in</strong>ertia, and Df the correspond<strong>in</strong>g rank. The test statistic F, or more<br />
correctly “pseudo-F ” is def<strong>in</strong>ed as their ratio. You should not pay any<br />
to its numeric values or to the numbers <strong>of</strong> degrees <strong>of</strong> freedom,<br />
s<strong>in</strong>ce this “pseudo-F ” has noth<strong>in</strong>g to do with the real F , and the only way<br />
to assess its “significance” is permutation. In simple models like the one<br />
studied here we could directly use <strong>in</strong>ertia <strong>in</strong> test<strong>in</strong>g, but the “pseudo-F ”<br />
is needed <strong>in</strong> more complicated model <strong>in</strong>clud<strong>in</strong>g “partialled” terms.<br />
The number <strong>of</strong> permutations was not specified <strong>in</strong> the mock anova<br />
function. The function tries to be lazy: it cont<strong>in</strong>ues permutations only as<br />
long as it is uncerta<strong>in</strong> whether the f<strong>in</strong>al P -value will be below or above<br />
the critical value (usually P = 0.05). If the observed <strong>in</strong>ertia is never<br />
reached <strong>in</strong> permutations, the function may stop after 200 permutations,<br />
and if it is very <strong>of</strong>ten exceeded, it may stop after 100 permutations.<br />
When we are close to the critical level, the permutations may cont<strong>in</strong>ue to<br />
thousands. In this way the calculations are fast when this is possible, but<br />
they are cont<strong>in</strong>ued longer <strong>in</strong> uncerta<strong>in</strong> cases. If you want to have a fixed<br />
number <strong>of</strong> iterations, you must specify that <strong>in</strong> anova call or directly use<br />
the underly<strong>in</strong>g function permutest.cca<br />
In addition to the overall test for all constra<strong>in</strong>ts together, we can<br />
also analyse s<strong>in</strong>gle terms or axes by sett<strong>in</strong>g argument by. The follow<strong>in</strong>g<br />
command analyses all terms separately <strong>in</strong> a sequential (“Type I”) test:<br />
> mod anova(mod, by = "term", step=200)<br />
Permutation test for cca under reduced model<br />
Terms added sequentially (first to last)<br />
Model: cca(formula = varespec ~ Al + P + K, data = varechem)<br />
Df Chisq F N.Perm Pr(>F)<br />
Al 1 0.30 4.14 199 0.005 **<br />
P 1 0.19 2.64 199 0.015 *<br />
K 1 0.16 2.17 199 0.035 *<br />
Residual 20 1.44<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
All terms are compared aga<strong>in</strong>st the same residuals, and there is no heuristic<br />
for the number permutations. The test is sequential, and the order<br />
<strong>of</strong> terms will <strong>in</strong>fluence the results, unless the terms are uncorrelated. In<br />
this case the same number <strong>of</strong> permutations will be used for all terms.<br />
The sum <strong>of</strong> test statistics (Chisq) for terms is the same as the Model test<br />
statistic <strong>in</strong> the overall test.<br />
“Type III” tests analyse the marg<strong>in</strong>al effects when each term is elim<strong>in</strong>ated<br />
from the model conta<strong>in</strong><strong>in</strong>g all other terms:<br />
> anova(mod, by = "marg<strong>in</strong>", perm=500)<br />
Permutation test for cca under reduced model<br />
Marg<strong>in</strong>al effects <strong>of</strong> terms<br />
Model: cca(formula = varespec ~ Al + P + K, data = varechem)<br />
Df Chisq F N.Perm Pr(>F)<br />
Al 1 0.31 4.33 199 0.005 **<br />
22
4 CONSTRAINED ORDINATION 4.3 Model build<strong>in</strong>g<br />
P 1 0.17 2.34 399 0.025 *<br />
K 1 0.16 2.17 499 0.026 *<br />
Residual 20 1.44<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
The marg<strong>in</strong>al effects are <strong>in</strong>dependent <strong>of</strong> the order <strong>of</strong> the terms, but correlated<br />
terms will get higher (“worse”) P -values. Now the the sum <strong>of</strong> test<br />
statistics is not equal to the Model test statistic <strong>in</strong> the overall test, unless<br />
the terms are uncorrelated.<br />
We can also ask for a test <strong>of</strong> <strong>in</strong>dividual axes:<br />
> anova(mod, by="axis", perm=1000)<br />
Model: cca(formula = varespec ~ Al + P + K, data = varechem)<br />
Df Chisq F N.Perm Pr(>F)<br />
CCA1 1 0.36 5.02 199 0.005 **<br />
CCA2 1 0.17 2.36 199 0.010 **<br />
CCA3 1 0.11 1.57 299 0.103<br />
Residual 20 1.44<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
4.3 Model build<strong>in</strong>g<br />
It is very popular to perform constra<strong>in</strong>ed ord<strong>in</strong>ation us<strong>in</strong>g all available<br />
constra<strong>in</strong>ts simultaneously. Increas<strong>in</strong>g the number <strong>of</strong> constra<strong>in</strong>ts actually<br />
means relax<strong>in</strong>g constra<strong>in</strong>ts: the ord<strong>in</strong>ation becomes more similar to the<br />
unconstra<strong>in</strong>ed one. When the rank <strong>of</strong> unconstra<strong>in</strong>ed component reduces<br />
towards zero, there are absolutely no constra<strong>in</strong>ts. However, the relaxation<br />
<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 we<br />
do not have strict constra<strong>in</strong>ts, it may be better to use unconstra<strong>in</strong>ed<br />
ord<strong>in</strong>ation with vector fitt<strong>in</strong>g (or surface fitt<strong>in</strong>g), which allows detection<br />
<strong>of</strong> compositional variation for which we have not observed environmental<br />
variables. In constra<strong>in</strong>ed ord<strong>in</strong>ation it is best to reduce the number <strong>of</strong><br />
constra<strong>in</strong>ts to just a few, say three to five.<br />
I do not want to encourage us<strong>in</strong>g all possible environmental variables<br />
together as constra<strong>in</strong>ts. However, there still is a shortcut for that purpose<br />
<strong>in</strong> formula <strong>in</strong>terface:<br />
> mod1 mod1<br />
Call: cca(formula = varespec ~ N + P + K + Ca + Mg + S<br />
+ Al + Fe + Mn + Zn + Mo + Baresoil + Humdepth + pH,<br />
data = varechem)<br />
Inertia Proportion Rank<br />
Total 2.083 1.000<br />
Constra<strong>in</strong>ed 1.441 0.692 14<br />
Unconstra<strong>in</strong>ed 0.642 0.308 9<br />
Inertia is mean squared cont<strong>in</strong>gency coefficient<br />
Eigenvalues for constra<strong>in</strong>ed axes:<br />
CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA7<br />
23
Dimension 2<br />
−2.0 −1.5 −1.0 −0.5 0.0 0.5 1.0 1.5<br />
4.3 Model build<strong>in</strong>g 4 CONSTRAINED ORDINATION<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
Procrustes errors<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
−1 0 1 2<br />
●<br />
Dimension 1<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
0.43887 0.29178 0.16285 0.14213 0.11795 0.08903 0.07029<br />
CCA8 CCA9 CCA10 CCA11 CCA12 CCA13 CCA14<br />
0.05836 0.03114 0.01329 0.00836 0.00654 0.00616 0.00473<br />
Eigenvalues for unconstra<strong>in</strong>ed axes:<br />
CA1 CA2 CA3 CA4 CA5 CA6 CA7<br />
0.19776 0.14193 0.10117 0.07079 0.05330 0.03330 0.01887<br />
CA8 CA9<br />
0.01510 0.00949<br />
This result probably is very similar to unconstra<strong>in</strong>ed ord<strong>in</strong>ation:<br />
> plot(procrustes(cca(varespec), mod1))<br />
For heuristic purposes we should reduce the number <strong>of</strong> constra<strong>in</strong>ts to<br />
f<strong>in</strong>d important environmental variables. In pr<strong>in</strong>ciple, constra<strong>in</strong>ed ord<strong>in</strong>ation<br />
only should be used with designed a priori constra<strong>in</strong>ts. All k<strong>in</strong>d <strong>of</strong><br />
automatic tools <strong>of</strong> model selection are dangerous: There may be several<br />
alternative models which are nearly equally good; Small changes <strong>in</strong> data<br />
can cause large changes <strong>in</strong> selected models; There may be no route to the<br />
best model with the adapted strategy; The model build<strong>in</strong>g has a history:<br />
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>al<br />
models; Significance tests are biased, because the model is selected for<br />
the best test performance.<br />
After all these warn<strong>in</strong>gs, I show how <strong>vegan</strong> can be used to automatically<br />
select constra<strong>in</strong>ts <strong>in</strong>to model us<strong>in</strong>g standard R function step. The<br />
step uses Akaike’s <strong>in</strong>formation criterion (aic) as the selection criterion.<br />
Aic is a penalized goodness-<strong>of</strong>-fit measure: the goodness-<strong>of</strong>-fit is basically<br />
derived from the residual (unconstra<strong>in</strong>ed) <strong>in</strong>ertia penalized by the<br />
rank <strong>of</strong> the constra<strong>in</strong>ts. In pr<strong>in</strong>ciple aic is based on log-Likelihood that<br />
ord<strong>in</strong>ation does not have. However, a deviance function changes the<br />
unconstra<strong>in</strong>ed <strong>in</strong>ertia to Chi-squared <strong>in</strong> cca or sum <strong>of</strong> squares <strong>in</strong> rda<br />
and capscale. This deviance is treated like sum <strong>of</strong> squares <strong>in</strong> Gaussian<br />
models. If we have only cont<strong>in</strong>uous (or 1 d.f.) terms, this is the same as<br />
select<strong>in</strong>g variables by their contributions to constra<strong>in</strong>ed eigenvalues (<strong>in</strong>ertia).<br />
With factors the situation is more tricky, because factors must be<br />
penalized by their degrees <strong>of</strong> freedom, and there is no way <strong>of</strong> know<strong>in</strong>g the<br />
magnitude <strong>of</strong> penalty. The step function may still be useful <strong>in</strong> help<strong>in</strong>g<br />
to 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 at<br />
all), but only regarded as an aid <strong>in</strong> model build<strong>in</strong>g.<br />
After this longish <strong>in</strong>troduction the example: us<strong>in</strong>g step is much simpler<br />
than expla<strong>in</strong><strong>in</strong>g how it works. We need to give the model we start<br />
with, and the scope <strong>of</strong> possible models <strong>in</strong>spected. For this we need another<br />
formula trick: formula with only 1 as the constra<strong>in</strong>t def<strong>in</strong>es an<br />
unconstra<strong>in</strong>ed model. We must def<strong>in</strong>e it like this so that we can add new<br />
terms to <strong>in</strong>itially unconstra<strong>in</strong>ed model. The aic used <strong>in</strong> model build<strong>in</strong>g<br />
is not based on a firm theory, and therefore we also ask for permutation<br />
tests at each step. In ideal case, all <strong>in</strong>cluded terms should be significant<br />
and all excluded terms <strong>in</strong>significant <strong>in</strong> the f<strong>in</strong>al model. The scope must<br />
be given as a list a formula, but we can extract this from fitted models<br />
us<strong>in</strong>g function formula. The follow<strong>in</strong>g example beg<strong>in</strong>s with an unconstra<strong>in</strong>ed<br />
model mod0 and steps towards the previously fitted maximum<br />
model mod1:<br />
24
4 CONSTRAINED ORDINATION 4.3 Model build<strong>in</strong>g<br />
> mod0 mod F)<br />
+ Al 1 128.61 3.6749 199 0.005 **<br />
+ Mn 1 128.95 3.3115 199 0.005 **<br />
+ Humdepth 1 129.24 3.0072 199 0.010 **<br />
+ Baresoil 1 129.77 2.4574 199 0.020 *<br />
+ Fe 1 129.79 2.4360 199 0.025 *<br />
+ P 1 130.03 2.1926 199 0.030 *<br />
+ Zn 1 130.30 1.9278 199 0.035 *<br />
130.31<br />
+ Mg 1 130.35 1.8749 199 0.065 .<br />
+ K 1 130.37 1.8609 199 0.075 .<br />
+ Ca 1 130.43 1.7959 199 0.055 .<br />
+ pH 1 130.57 1.6560 199 0.100 .<br />
+ S 1 130.72 1.5114 99 0.150<br />
+ N 1 130.77 1.4644 199 0.135<br />
+ Mo 1 131.19 1.0561 99 0.460<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
Step: AIC=128.61<br />
varespec ~ Al<br />
Df AIC F N.Perm Pr(>F)<br />
+ P 1 127.91 2.5001 199 0.005 **<br />
+ K 1 128.09 2.3240 199 0.005 **<br />
+ S 1 128.26 2.1596 199 0.025 *<br />
+ Zn 1 128.44 1.9851 199 0.040 *<br />
+ Mn 1 128.53 1.8945 199 0.030 *<br />
128.61<br />
+ Mg 1 128.70 1.7379 199 0.055 .<br />
+ N 1 128.85 1.5900 199 0.100 .<br />
+ Baresoil 1 128.88 1.5670 199 0.110<br />
+ Ca 1 129.04 1.4180 99 0.170<br />
+ Humdepth 1 129.08 1.3814 99 0.180<br />
+ Mo 1 129.50 0.9884 99 0.460<br />
+ pH 1 129.63 0.8753 99 0.580<br />
+ Fe 1 130.02 0.5222 99 0.860<br />
- Al 1 130.31 3.6749 199 0.005 **<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
Step: AIC=127.91<br />
varespec ~ Al + P<br />
Df AIC F N.Perm Pr(>F)<br />
+ K 1 127.44 2.1688 199 0.040 *<br />
127.91<br />
+ Baresoil 1 127.99 1.6606 199 0.060 .<br />
+ N 1 128.11 1.5543 199 0.095 .<br />
25
4.3 Model build<strong>in</strong>g 4 CONSTRAINED ORDINATION<br />
+ S 1 128.36 1.3351 99 0.210<br />
+ Mn 1 128.44 1.2641 99 0.290<br />
+ Zn 1 128.51 1.2002 99 0.240<br />
+ Humdepth 1 128.56 1.1536 99 0.310<br />
- P 1 128.61 2.5001 199 0.015 *<br />
+ Mo 1 128.75 0.9837 99 0.450<br />
+ Mg 1 128.79 0.9555 99 0.530<br />
+ pH 1 128.82 0.9247 99 0.510<br />
+ Fe 1 129.28 0.5253 99 0.850<br />
+ Ca 1 129.36 0.4648 99 0.870<br />
- Al 1 130.03 3.9401 199 0.005 **<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
Step: AIC=127.44<br />
varespec ~ Al + P + K<br />
Df AIC F N.Perm Pr(>F)<br />
127.44<br />
+ N 1 127.59 1.5148 99 0.160<br />
+ Baresoil 1 127.67 1.4544 99 0.150<br />
+ Zn 1 127.84 1.3067 99 0.240<br />
+ S 1 127.89 1.2604 99 0.230<br />
- K 1 127.91 2.1688 199 0.025 *<br />
+ Mo 1 127.92 1.2350 99 0.200<br />
- P 1 128.09 2.3362 199 0.020 *<br />
+ Mg 1 128.17 1.0300 99 0.400<br />
+ Mn 1 128.34 0.8879 99 0.580<br />
+ Humdepth 1 128.44 0.8056 99 0.620<br />
+ Fe 1 128.79 0.5215 99 0.870<br />
+ pH 1 128.81 0.5067 99 0.900<br />
+ Ca 1 128.89 0.4358 99 0.890<br />
- Al 1 130.14 4.3340 199 0.005 **<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
> mod<br />
Call: cca(formula = varespec ~ Al + P + K, data =<br />
varechem)<br />
Inertia Proportion Rank<br />
Total 2.083 1.000<br />
Constra<strong>in</strong>ed 0.644 0.309 3<br />
Unconstra<strong>in</strong>ed 1.439 0.691 20<br />
Inertia is mean squared cont<strong>in</strong>gency coefficient<br />
Eigenvalues for constra<strong>in</strong>ed axes:<br />
CCA1 CCA2 CCA3<br />
0.362 0.170 0.113<br />
Eigenvalues for unconstra<strong>in</strong>ed axes:<br />
CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8<br />
0.3500 0.2201 0.1851 0.1551 0.1351 0.1003 0.0773 0.0537<br />
(Showed only 8 <strong>of</strong> all 20 unconstra<strong>in</strong>ed eigenvalues)<br />
26
4 CONSTRAINED ORDINATION 4.3 Model build<strong>in</strong>g<br />
We ended up with the same familiar model we have been us<strong>in</strong>g all the time<br />
(and now you know the reason why this model was used <strong>in</strong> the first place).<br />
The aic was based on deviance, and penalty for each added parameter<br />
was 2 per degree <strong>of</strong> freedom. At every step the aic was evaluated for all<br />
possible additions (+) and removals (-), and the variables are listed <strong>in</strong><br />
the order <strong>of</strong> aic. The stepp<strong>in</strong>g stops when or the current model<br />
is at the top.<br />
Model build<strong>in</strong>g with step is fragile, and the strategy <strong>of</strong> model build<strong>in</strong>g<br />
can change the f<strong>in</strong>al model. If we start with the largest model (mod1),<br />
the f<strong>in</strong>al model will be different:<br />
> modb modb<br />
Call: cca(formula = varespec ~ P + K + Mg + S + Mn + Mo<br />
+ Baresoil + Humdepth, data = varechem)<br />
Inertia Proportion Rank<br />
Total 2.083 1.000<br />
Constra<strong>in</strong>ed 1.117 0.536 8<br />
Unconstra<strong>in</strong>ed 0.967 0.464 15<br />
Inertia is mean squared cont<strong>in</strong>gency coefficient<br />
Eigenvalues for constra<strong>in</strong>ed axes:<br />
CCA1 CCA2 CCA3 CCA4 CCA5 CCA6 CCA7 CCA8<br />
0.4007 0.2488 0.1488 0.1266 0.0875 0.0661 0.0250 0.0130<br />
Eigenvalues for unconstra<strong>in</strong>ed axes:<br />
CA1 CA2 CA3 CA4 CA5 CA6 CA7<br />
0.25821 0.18813 0.11927 0.10204 0.08791 0.06085 0.04461<br />
CA8 CA9 CA10 CA11 CA12 CA13 CA14<br />
0.02782 0.02691 0.01646 0.01364 0.00823 0.00655 0.00365<br />
CA15<br />
0.00238<br />
The aic <strong>of</strong> this model is 127.89 which is higher (worse) than reached<br />
<strong>in</strong> forward selection (127.44). We supressed trac<strong>in</strong>g to save some pages<br />
<strong>of</strong> output, but step adds its history <strong>in</strong> the result:<br />
> modb$anova<br />
Step Df Deviance Resid. Df Resid. Dev AIC<br />
1 NA NA 9 1551 130.1<br />
2 - Fe 1 115.2 10 1667 129.8<br />
3 - Al 1 106.0 11 1773 129.3<br />
4 - N 1 117.5 12 1890 128.8<br />
5 - pH 1 140.4 13 2031 128.5<br />
6 - Ca 1 141.2 14 2172 128.1<br />
7 - Zn 1 165.3 15 2337 127.9<br />
Variable Al was the first to be selected <strong>in</strong> the model <strong>in</strong> forward selection,<br />
but it was the second to be removed <strong>in</strong> backward elim<strong>in</strong>ation.<br />
Variable Al is strongly correlated with many other explanatory variables.<br />
This is obvious when look<strong>in</strong>g at the variance <strong>in</strong>flation factors (vif) <strong>in</strong> the<br />
full model mod1:<br />
27
4.4 L<strong>in</strong>ear comb<strong>in</strong>ations and weighted averages 4 CONSTRAINED ORDINATION<br />
> vif.cca(mod1)<br />
N P K Ca Mg S Al<br />
1.982 6.029 12.009 9.926 9.811 18.379 21.193<br />
Fe Mn Zn Mo Baresoil Humdepth pH<br />
9.128 5.380 7.740 4.320 2.254 6.013 7.389<br />
A common rule <strong>of</strong> thumb is that vif > 10 <strong>in</strong>dicates that a variable is<br />
strongly dependent on others and does not have <strong>in</strong>dependent <strong>in</strong>formation.<br />
On the other hand, it may not be the variable that should be removed,<br />
but alternatively some other variables may be removed. The vifs were<br />
all modest <strong>in</strong> model found by forward selection, <strong>in</strong>clud<strong>in</strong>g Al:<br />
> vif.cca(mod)<br />
Al P K<br />
1.012 2.365 2.379<br />
4.4 L<strong>in</strong>ear comb<strong>in</strong>ations and weighted averages<br />
There 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:<br />
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>g<br />
variables.<br />
2. Weighted averages scores wa which are weighted averages <strong>of</strong> species<br />
scores.<br />
These two scores are as similar as possible, and their (weighted) correlation<br />
is called the species–environment correlation:<br />
> spenvcor(mod)<br />
CCA1 CCA2 CCA3<br />
0.8555 0.8133 0.8793<br />
Correlation coefficient is very sensitive to s<strong>in</strong>gle extreme values, like seems<br />
to happen <strong>in</strong> the example above where axis 3 has the “best” correlation<br />
simply because it has some extreme po<strong>in</strong>ts, and eigenvalue is a more<br />
appropriate measure <strong>of</strong> similarity between lc and wa socres.<br />
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>ation<br />
graphics. The <strong>vegan</strong> package prefers wa scores, whereas the major<br />
commercial programme for cca prefers lc scores. The <strong>vegan</strong> package<br />
comes with a separate document (“<strong>vegan</strong> FAQ”) which studies the issue<br />
<strong>in</strong> more detail, but I will briefly discuss the subject here also, and show<br />
how you can circumvent my decisions.<br />
The practical reason to prefer wa scores is that they are more robust<br />
aga<strong>in</strong>st random error <strong>in</strong> environmental variables. All ecological observations<br />
have random error, and therefore it is better to use scores that<br />
are resistant to this variation. Another po<strong>in</strong>t is that I see lc scores as<br />
constra<strong>in</strong>ts: the scores are dependent only on environmental variables,<br />
and community composition does not <strong>in</strong>fluence them. The wa scores<br />
are based on community composition, but so that they are as similar as<br />
possible to the constra<strong>in</strong>ts. This duality is particularly clear when us<strong>in</strong>g<br />
a s<strong>in</strong>gle factor variable as constra<strong>in</strong>t: the lc scores are constant with<strong>in</strong><br />
28
4 CONSTRAINED ORDINATION 4.5 Biplot arrows and environmental calibration<br />
each level <strong>of</strong> the factor and fall <strong>in</strong> the same po<strong>in</strong>t. The wa scores show<br />
how well we can predict the factor level from community composition.<br />
The <strong>vegan</strong> package has a graphical function ordispider which (among<br />
other alternatives) will comb<strong>in</strong>e wa scores to the correspond<strong>in</strong>g lc score.<br />
With a s<strong>in</strong>gle factor constra<strong>in</strong>t:<br />
> dune.cca plot(dune.cca, display = c("lc", "wa"), type = "p")<br />
> ordispider(dune.cca, col="blue")<br />
The <strong>in</strong>terpretation is similar as <strong>in</strong> discrim<strong>in</strong>ant analysis: lc scores give<br />
the predicted class centroids, and wa scores give the predicted values.<br />
For dist<strong>in</strong>ct classes, there is no overlap among groups. In general, the<br />
length <strong>of</strong> ordispider segments is a visual image <strong>of</strong> species–environment<br />
correlation. −2 −1 0 1 2 3<br />
4.5 Biplot arrows and environmental calibration<br />
Biplot arrows are an essential part <strong>of</strong> constra<strong>in</strong>ed ord<strong>in</strong>ation plots. The<br />
arrows are based on (weighted) correlation <strong>of</strong> lc scores and environmental<br />
variables. They are scaled to unit length <strong>in</strong> the constra<strong>in</strong>ed ord<strong>in</strong>ation <strong>of</strong><br />
full rank. When these arrows are projected onto 2D ord<strong>in</strong>ation plot, they<br />
look shorter if they go <strong>of</strong>f the plane.<br />
In <strong>vegan</strong> the biplot arrows are always scaled similarly irrespective <strong>of</strong><br />
scal<strong>in</strong>g <strong>of</strong> sites or species. With default scal<strong>in</strong>g = 2, the biplot arrows<br />
have optimal relation to sites, but with scal<strong>in</strong>g = 1 they rather are<br />
related to species.<br />
The standard <strong>in</strong>terpretation <strong>of</strong> biplot arrows is that a site should be<br />
perpendicularly projected onto the arrow to predict the value <strong>of</strong> the variable.<br />
The arrow starts from the (weighted) mean <strong>of</strong> the environmental<br />
variable, and the values <strong>in</strong>crease towards the arrow head, and decrease to<br />
the opposite direction. Then we still should figure out the unit <strong>of</strong> change.<br />
Function calibrate.cca performs this automatically <strong>in</strong> <strong>vegan</strong>. Let us<br />
<strong>in</strong>spect the result <strong>of</strong> the step function with three constra<strong>in</strong>ts:<br />
> pred head(pred)<br />
Al P K<br />
18 103.219 25.64 80.57<br />
15 30.661 47.25 190.90<br />
24 32.105 72.80 208.34<br />
27 7.178 64.44 241.89<br />
23 14.321 38.50 125.73<br />
19 136.568 54.39 182.60<br />
Actually, this is not based on biplot arrows, but on regression coefficients<br />
used <strong>in</strong>ternally <strong>in</strong> constra<strong>in</strong>ed ord<strong>in</strong>ation. Biplot arrows should only be<br />
seen as a visual approximation. The fitt<strong>in</strong>g is done <strong>in</strong> full constra<strong>in</strong>ed rank<br />
as default and for all constra<strong>in</strong>ts simultaneously. The example draws a<br />
residual plot <strong>of</strong> predictions:<br />
> with(varechem, plot(Al, pred[,"Al"] - Al, ylab="Prediction Error"))<br />
> abl<strong>in</strong>e(h=0, col="grey")<br />
29<br />
CCA2<br />
−2 −1 0 1 2<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
CCA1<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●
Prediction Error<br />
CCA2<br />
−150 −100 −50 0 50 100 150<br />
−2 −1 0 1 2<br />
4.6 Conditioned or partial models 4 CONSTRAINED ORDINATION<br />
●●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
0 100 200 300 400<br />
28<br />
28<br />
27<br />
0<br />
27<br />
25<br />
22<br />
24<br />
16<br />
−3 −2 −1 0 1 2<br />
14<br />
Al<br />
22 21 16<br />
19<br />
CCA1<br />
●<br />
13<br />
13<br />
21<br />
15 12 18<br />
19 5<br />
14<br />
15<br />
23<br />
18 20<br />
23K<br />
25<br />
P<br />
50<br />
100<br />
20 10<br />
24<br />
150<br />
200<br />
250<br />
11<br />
11<br />
6<br />
6<br />
●<br />
12 9<br />
300<br />
7 5<br />
2<br />
10<br />
9<br />
7<br />
3Al<br />
2<br />
3<br />
4<br />
350<br />
4<br />
●<br />
−1 0 1<br />
The <strong>vegan</strong> package provides function ordisurf which is based on<br />
gam <strong>in</strong> the mgcv package, and can automatically detect the degree <strong>of</strong><br />
smoothness needed, and can be used to check the l<strong>in</strong>earity hypothesis <strong>of</strong><br />
the biplot method. Function performs weighted fitt<strong>in</strong>g, and the model<br />
should be consistent with the one used <strong>in</strong> arrow fitt<strong>in</strong>g. Alum<strong>in</strong>ium was<br />
the most important <strong>of</strong> three constra<strong>in</strong>ts <strong>in</strong> our example. Now we should<br />
fit the model to the lc scores, just like the arrows:<br />
> plot(mod, display = c("bp", "wa", "lc"))<br />
> ef dune.cca plot(dune.cca)<br />
> dune.cca<br />
Call: cca(formula = dune ~ Management +<br />
Condition(Moisture), data = dune.env)<br />
Inertia Proportion Rank<br />
Total 2.115 1.000<br />
Conditional 0.628 0.297 3<br />
Constra<strong>in</strong>ed 0.374 0.177 3<br />
Unconstra<strong>in</strong>ed 1.113 0.526 13<br />
Inertia is mean squared cont<strong>in</strong>gency coefficient<br />
Eigenvalues for constra<strong>in</strong>ed axes:<br />
CCA1 CCA2 CCA3<br />
0.2278 0.0849 0.0614<br />
Eigenvalues for unconstra<strong>in</strong>ed axes:<br />
30
4 CONSTRAINED ORDINATION 4.6 Conditioned or partial models<br />
CA1 CA2 CA3 CA4 CA5 CA6 CA7<br />
0.35040 0.15206 0.12508 0.10984 0.09221 0.07711 0.05944<br />
CA8 CA9 CA10 CA11 CA12 CA13<br />
0.04776 0.03696 0.02227 0.02070 0.01083 0.00825<br />
Now the total <strong>in</strong>ertia is decomposed <strong>in</strong>to three components: <strong>in</strong>ertia expla<strong>in</strong>ed<br />
by 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>g<br />
unconstra<strong>in</strong>ed <strong>in</strong>ertia. We previously fitted a model with Management<br />
as the only constra<strong>in</strong>t, and <strong>in</strong> that case constra<strong>in</strong>ed <strong>in</strong>ertia was clearly<br />
higher than now. It seems that different Management was practised <strong>in</strong><br />
different natural conditions, and the variation we previously attributed<br />
to Management may be due to Moisture.<br />
We can perform permutation tests for Management <strong>in</strong> conditioned<br />
model, and Management alone:<br />
> anova(dune.cca, perm.max = 2000)<br />
Permutation test for cca under reduced model<br />
Model: cca(formula = dune ~ Management + Condition(Moisture), data = dune.env)<br />
Df Chisq F N.Perm Pr(>F)<br />
Model 3 0.37 1.46 699 0.03 *<br />
Residual 13 1.11<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
> anova(cca(dune ~ Management, dune.env))<br />
Permutation test for cca under reduced model<br />
Model: cca(formula = dune ~ Management, data = dune.env)<br />
Df Chisq F N.Perm Pr(>F)<br />
Model 3 0.60 2.13 199 0.005 **<br />
Residual 16 1.51<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
Inspected alone, Management seemed to be very significant, but the situation<br />
is much less clear after remov<strong>in</strong>g the variation due to Moisture.<br />
The anova function (like any permutation test <strong>in</strong> <strong>vegan</strong>) can be restricted<br />
so that permutation are made only with<strong>in</strong> strata or with<strong>in</strong> a<br />
level <strong>of</strong> a factor variable:<br />
> with(dune.env, anova(dune.cca, strata = Moisture))<br />
Permutation test for cca under reduced model<br />
Permutations stratified with<strong>in</strong> Moisture<br />
Model: cca(formula = dune ~ Management + Condition(Moisture), data = dune.env)<br />
Df Chisq F N.Perm Pr(>F)<br />
Model 3 0.37 1.46 199 0.01 **<br />
Residual 13 1.11<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
Conditioned or partial models are sometimes used for decomposition<br />
<strong>of</strong> <strong>in</strong>ertia <strong>in</strong>to various components attributed to different sets <strong>of</strong> environmental<br />
variables. In some cases this gives mean<strong>in</strong>gful results, but the<br />
31<br />
CCA2<br />
−2 −1 0 1 2<br />
ManagementHF<br />
Tripra<br />
7<br />
Rumace<br />
Antodo<br />
Junart Plalan 9<br />
15<br />
8<br />
10<br />
Airpra<br />
16Cirarv<br />
Poatri Elyrep<br />
Junbuf<br />
PoapraAchmil<br />
20<br />
Agrsto Lolper Elepal Ranfla Brarut<br />
Trirep Leoaut ManagementNM<br />
Empnig Potpal<br />
Alogen Sagpro Brohor<br />
Belper Calcus Hyprad Salrep<br />
13<br />
ManagementSF<br />
3<br />
4 12<br />
Chealb<br />
14<br />
1<br />
Viclat<br />
ManagementBF<br />
2<br />
5<br />
6<br />
−2 −1 0 1 2 3<br />
11<br />
CCA1<br />
18<br />
19<br />
17
S =kX z<br />
z =[log(2) − log(2a + b + c)<br />
+ log(a + b + c)]/ log(2)<br />
5 DISSIMILARITIES AND ENVIRONMENT<br />
groups <strong>of</strong> environmental variables should be non-l<strong>in</strong>early <strong>in</strong>dependent for<br />
unbiased decomposition. If the groups <strong>of</strong> environmental variables have<br />
polynomial dependencies, some <strong>of</strong> the components <strong>of</strong> <strong>in</strong>ertia may even<br />
become negative (that should be impossible). That k<strong>in</strong>d <strong>of</strong> higher-order<br />
dependencies are almost certa<strong>in</strong> to appear with high number <strong>of</strong> variables<br />
and high number <strong>of</strong> groups. However, varpart performs decomposition<br />
<strong>of</strong> rda models among two to four components.<br />
5 Dissimilarities and environment<br />
We already discussed environmental <strong>in</strong>terpretation <strong>of</strong> ord<strong>in</strong>ation and environmentally<br />
constra<strong>in</strong>ed ord<strong>in</strong>ation. These both reduce the variation <strong>in</strong>to<br />
an ord<strong>in</strong>ation space, and ma<strong>in</strong>ly <strong>in</strong>spect the first dimensions. Sometimes<br />
we may wish to analyse vegetation–environment relationships without ord<strong>in</strong>ation,<br />
or <strong>in</strong> full space. Typically these methods use the dissimilarity<br />
matrix <strong>in</strong> analysis. The recommended method <strong>in</strong> <strong>vegan</strong> is adonis which<br />
implements a multivariate analysis <strong>of</strong> variances us<strong>in</strong>g distance matrices.<br />
Function adonis can handle both cont<strong>in</strong>uous and factor predictors. Other<br />
methods <strong>in</strong> <strong>vegan</strong> <strong>in</strong>clude multiresponse permutation procedure (mrpp)<br />
and analysis <strong>of</strong> similarities (anosim). Both <strong>of</strong> these handle only class<br />
predictors, and they are less robust than adonis.<br />
5.1 adonis: <strong>Multivariate</strong> ANOVA based on dissimilarities<br />
Function adonis partitions dissimilarities for the sources <strong>of</strong> variation, and<br />
uses permutation tests to <strong>in</strong>spect the significances <strong>of</strong> those partitions.<br />
With Euclidean distances the results are similar as <strong>in</strong> rda and its anova<br />
permutation tests, but adonis can handle any dissimilarity objects.<br />
The example uses adonis to study beta diversity between Management<br />
classes <strong>in</strong> the dune meadow data. We def<strong>in</strong>e beta diversity as the<br />
slope <strong>of</strong> species-area curve, or the exponent z <strong>of</strong> the Arrhenius model<br />
where the number <strong>of</strong> species S is dependent on the size X <strong>of</strong> the study<br />
area. For pairwise comparison <strong>of</strong> sites the slope z can be found from the<br />
number <strong>of</strong> species shared between two sites (a) and the number <strong>of</strong> species<br />
unique to each sites (b and c). It is commonly regarded that z ≈ 0.3<br />
implies random sampl<strong>in</strong>g variability, and only higher values mean real<br />
systematic differences. The Arrhenius z can be directly found with function<br />
betadiver that also provided many other <strong>in</strong>dices <strong>of</strong> pairwise beta<br />
diversity.<br />
> betad adonis(betad ~ Management, dune.env, perm=200)<br />
Call:<br />
adonis(formula = betad ~ Management, data = dune.env, permutations = 200)<br />
32
5 DISSIMILARITIES AND ENVIRONMENT 5.2 Homogeneity <strong>of</strong> groups and beta diversity<br />
Terms added sequentially (first to last)<br />
Df SumsOfSqs MeanSqs F.Model R2 Pr(>F)<br />
Management 3 1.24 0.412 2.36 0.307 0.015 *<br />
Residuals 16 2.79 0.174 0.693<br />
Total 19 4.03 1.000<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
The models can be more complicated, and sequential test <strong>of</strong> permutational<br />
ANOVA is performed if there are several parameters:<br />
> adonis(betad ~ A1*Management, dune.env, perm = 200)<br />
Call:<br />
adonis(formula = betad ~ A1 * Management, data = dune.env, permutations = 200)<br />
Terms added sequentially (first to last)<br />
Df SumsOfSqs MeanSqs F.Model R2 Pr(>F)<br />
A1 1 0.65 0.655 4.13 0.163 0.005 **<br />
Management 3 1.00 0.334 2.11 0.249 0.025 *<br />
A1:Management 3 0.47 0.156 0.99 0.117 0.502<br />
Residuals 12 1.90 0.158 0.472<br />
Total 19 4.03 1.000<br />
---<br />
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1<br />
5.2 Homogeneity <strong>of</strong> groups and beta diversity<br />
Function adonis studied the differences <strong>in</strong> the group means, but function<br />
betadisper studies the differences <strong>in</strong> group homogeneities. Function<br />
adonis was analogous to multivariate analysis <strong>of</strong> variance, and betadisper<br />
is analogous to Levene’s test <strong>of</strong> the equality <strong>of</strong> variances.<br />
The example cont<strong>in</strong>ues the analysis <strong>of</strong> the previous section and <strong>in</strong>spects<br />
the beta diversity. The function can only use one factor as an<br />
<strong>in</strong>dependent variable, and it does not know the formula <strong>in</strong>terface, so that<br />
we need to attach the data frame or use with to make the factor visible<br />
to the function:<br />
> mod mod<br />
Homogeneity <strong>of</strong> multivariate dispersions<br />
Call: betadisper(d = betad, group = Management)<br />
No. <strong>of</strong> Positive Eigenvalues: 12<br />
No. <strong>of</strong> Negative Eigenvalues: 7<br />
Average distance to centroid:<br />
BF HF NM SF<br />
0.308 0.251 0.441 0.363<br />
Eigenvalues for PCoA axes:<br />
PCoA1 PCoA2 PCoA3 PCoA4 PCoA5 PCoA6 PCoA7 PCoA8 PCoA9<br />
33
PCoA 2<br />
Distance to centroid<br />
−0.2 0.0 0.2 0.4<br />
0.1 0.2 0.3 0.4 0.5 0.6<br />
5.2 Homogeneity <strong>of</strong> groups and beta diversity 5 DISSIMILARITIES AND ENVIRONMENT<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
mod<br />
−0.2 0.0 0.2 0.4<br />
PCoA 1<br />
method = "beta.z"<br />
BF HF NM SF<br />
●<br />
1.655 0.887 0.533 0.374 0.287 0.224 0.161 0.081 0.065<br />
PCoA10 PCoA11 PCoA12 PCoA13 PCoA14 PCoA15 PCoA16 PCoA17 PCoA18<br />
0.035 0.018 0.004 -0.004 -0.019 -0.037 -0.043 -0.054 -0.060<br />
PCoA19<br />
-0.083<br />
The function has plot and boxplot methods for graphical display.<br />
> plot(mod)<br />
> boxplot(mod)<br />
The significance <strong>of</strong> the fitted model can be analysed either us<strong>in</strong>g standard<br />
parametric anova or permutation tests (permutest):<br />
> anova(mod)<br />
<strong>Analysis</strong> <strong>of</strong> Variance Table<br />
Response: Distances<br />
Df Sum Sq Mean Sq F value Pr(>F)<br />
Groups 3 0.104 0.0348 1.26 0.32<br />
Residuals 16 0.443 0.0277<br />
> permutest(mod)<br />
Permutation test for homogeneity <strong>of</strong> multivariate<br />
dispersions<br />
No. <strong>of</strong> permutations: 999<br />
**** STRATA ****<br />
Permutations are unstratified<br />
**** SAMPLES ****<br />
Permutation type: free<br />
Mirrored permutations for Samples?: No<br />
Response: Distances<br />
Df Sum Sq Mean Sq F N.Perm Pr(>F)<br />
Groups 3 0.104 0.0348 1.26 999 0.32<br />
Residuals 16 0.443 0.0277<br />
Moreover, it is possible to analyse pairwise differences between groups<br />
us<strong>in</strong>g parametric Tukey’s HSD test:<br />
> TukeyHSD(mod)<br />
Tukey multiple comparisons <strong>of</strong> means<br />
95% family-wise confidence level<br />
Fit: aov(formula = distances ~ group, data = df)<br />
$group<br />
diff lwr upr p adj<br />
HF-BF -0.05682 -0.40452 0.2909 0.9651<br />
NM-BF 0.13256 -0.20409 0.4692 0.6791<br />
SF-BF 0.05547 -0.28119 0.3921 0.9643<br />
NM-HF 0.18938 -0.09891 0.4777 0.2752<br />
SF-HF 0.11229 -0.17600 0.4006 0.6862<br />
SF-NM -0.07709 -0.35197 0.1978 0.8523<br />
34
5 DISSIMILARITIES AND ENVIRONMENT 5.3 Mantel test<br />
5.3 Mantel test<br />
Mantel test compares two sets <strong>of</strong> dissimilarities. Basically, it is the correlation<br />
between dissimilarity entries. As there are N(N − 1)/2 dissimilarities<br />
among N objects, normal significance tests are not applicable.<br />
Mantel developed asymptotic test statistics, but <strong>vegan</strong> function mantel<br />
uses permutation tests.<br />
In this example we study how well the lichen pastures (varespec) correspond<br />
to the environment. We have already used vector fitt<strong>in</strong>g after ord<strong>in</strong>ation.<br />
However, the ord<strong>in</strong>ation and environment may be non-l<strong>in</strong>early<br />
related, and we try now with function mantel. We first perform a pca <strong>of</strong><br />
environmental variables, and then compute dissimilarities for first pr<strong>in</strong>cipal<br />
components. We use standard R function prcomp, but pr<strong>in</strong>comp or<br />
rda will work as well. Function scores <strong>in</strong> <strong>vegan</strong> will work with all these<br />
methods. The follow<strong>in</strong>g uses the same standardizations for community<br />
dissimilarities as previously used <strong>in</strong> metaMDS.<br />
> pc pc edis vare.dis mantel(vare.dis, edis)<br />
Mantel statistic based on Pearsons product-moment correlation<br />
Call:<br />
mantel(xdis = vare.dis, ydis = edis)<br />
Mantel statistic r: 0.381<br />
Significance: 0.002<br />
Upper quantiles <strong>of</strong> permutations (null model):<br />
90% 95% 97.5% 99%<br />
0.143 0.184 0.213 0.237<br />
Based on 999 permutations<br />
We could use a selection <strong>of</strong> environmental variables <strong>in</strong> pca, or we could<br />
use standardized environmental variables directly without pca — tastes<br />
vary. Function bioenv gives an <strong>in</strong>trigu<strong>in</strong>g alternative for select<strong>in</strong>g optimal<br />
subsets for compar<strong>in</strong>g ord<strong>in</strong>ation and environment. There also is a partial<br />
Mantel test where we can remove the <strong>in</strong>fluence <strong>of</strong> third set dissimilarities<br />
from the analysis, but its results <strong>of</strong>ten are difficult to <strong>in</strong>terpret.<br />
Function mantel does not have diagnostic plot functions, but you can<br />
directly plot two dissimilarity matrices aga<strong>in</strong>st each other:<br />
> plot(vare.dis, edis)<br />
Everyth<strong>in</strong>g is O.K. if the relationship is more or less monotonous, or even<br />
l<strong>in</strong>ear and positive. In spatial models we even may observe a hump which<br />
<strong>in</strong>dicates spatial aggregation.<br />
35<br />
edis<br />
2 4 6 8<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
●<br />
● ●<br />
● ● ●<br />
●●<br />
● ●<br />
● ●<br />
●<br />
●<br />
●<br />
● ●<br />
● ●<br />
●<br />
●<br />
●<br />
● ●<br />
● ●<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
● ● ●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
●●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
● ● ●<br />
● ●<br />
●<br />
●<br />
●<br />
●●<br />
● ● ● ●<br />
● ●<br />
●<br />
●<br />
● ●<br />
●<br />
● ●<br />
● ●<br />
●<br />
●<br />
●●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
● ● ● ●●<br />
●<br />
● ●<br />
● ● ●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
● ●<br />
● ●<br />
●<br />
●●<br />
●<br />
●<br />
●<br />
● ● ●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
● ●<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
● ● ● ●●<br />
●<br />
●●<br />
●<br />
● ● ● ●<br />
● ●<br />
●<br />
●<br />
● ●<br />
● ● ●<br />
● ●<br />
● ● ●<br />
● ● ●<br />
●<br />
● ● ● ●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
● ● ●<br />
● ●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
●●<br />
●<br />
● ●<br />
●<br />
●●<br />
●<br />
●<br />
●<br />
●<br />
● ●<br />
●<br />
● ●<br />
●<br />
● ●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
0.2 0.3 0.4 0.5 0.6 0.7<br />
vare.dis<br />
●
Dimension 2<br />
−0.2 −0.1 0.0 0.1 0.2<br />
5.4 Protest: Procrustes test 6 CLASSIFICATION<br />
●<br />
●<br />
●<br />
●<br />
●<br />
Procrustes errors<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●<br />
●●<br />
−0.2 −0.1 0.0 0.1 0.2 0.3<br />
Dimension 1<br />
●<br />
●<br />
● ●<br />
●<br />
●<br />
r = 1 − m 2<br />
●<br />
5.4 Protest: Procrustes test<br />
Procrustes test or protest compares two ord<strong>in</strong>ations us<strong>in</strong>g symmetric<br />
Procrustes analysis. It is an alternative to Mantel tests, but uses reduced<br />
space <strong>in</strong>stead <strong>of</strong> complete dissimilarity matrices. We can repeat the previous<br />
analysis, but now with the solution <strong>of</strong> metaMDS and two first pr<strong>in</strong>cipal<br />
components <strong>of</strong> the environmental analysis:<br />
> pc pro plot(pro)<br />
> pro<br />
Call:<br />
protest(X = vare.mds, Y = pc)<br />
Procrustes Sum <strong>of</strong> Squares (m12 squared): 0.533<br />
Correlation <strong>in</strong> a symmetric Procrustes rotation: 0.683<br />
Significance: 0.001<br />
Based on 999 permutations.<br />
The significance is assessed by permutation tests. The statistic is now<br />
Procrustes correlation r derived from the symmetric Procrustes resid-<br />
ual m 2 . The correlation is clearly higher than the Mantel correlation<br />
for the correspond<strong>in</strong>g dissimilarities. In lower number <strong>of</strong> dimensions we<br />
remove noise from the data which may expla<strong>in</strong> higher correlations (as<br />
well as different methods <strong>of</strong> calculat<strong>in</strong>g the correlation). However, both<br />
methods are about as significant. Significance <strong>of</strong>ten is not a significant<br />
concept: even small deviations from randomness may be highly significant<br />
<strong>in</strong> large data sets. Function protest provides graphical presentations<br />
(“Procrustes superimposition plot”) which may be more useful <strong>in</strong><br />
evaluat<strong>in</strong>g the congruence between configurations.<br />
Protest (as ord<strong>in</strong>ary Procrustes analysis) is <strong>of</strong>ten used <strong>in</strong> assess<strong>in</strong>g<br />
similarities between different community ord<strong>in</strong>ations. This is known as<br />
analysis <strong>of</strong> congruence.<br />
6 Classification<br />
The <strong>vegan</strong> ma<strong>in</strong>ly is a package for ord<strong>in</strong>ation and diversity analysis, and<br />
there is only a scanty support to classification. There are several other R<br />
packages with more extensive classification functions. Among community<br />
ecological packages, labdsv package by Dave Roberts is particularly strong<br />
<strong>in</strong> classification functions.<br />
This chapter describes perform<strong>in</strong>g simple classification tasks <strong>in</strong> community<br />
ecology that are sufficient to many community ecologists.<br />
6.1 Cluster analysis<br />
Hierarchic cluster<strong>in</strong>g can be perfomed us<strong>in</strong>g standard R function hclust.<br />
In addition, there are several other cluster<strong>in</strong>g packages, some <strong>of</strong> which<br />
may be compatible with hclust. Function hclust needs a dissimilarities<br />
as <strong>in</strong>put.<br />
36
6 CLASSIFICATION 6.1 Cluster analysis<br />
Function hclust provides several alternative cluster<strong>in</strong>g strategies. In<br />
community ecology, most popular are s<strong>in</strong>gle l<strong>in</strong>kage a.k.a. nearest neighbour,<br />
complete l<strong>in</strong>kage a.k.a. furthest neighbour, and various brands <strong>of</strong><br />
average l<strong>in</strong>kage methods. These are best illustrated with examples:<br />
> dis clus plot(clus)<br />
Some people prefer s<strong>in</strong>gle l<strong>in</strong>kage, because it is conceptually related to<br />
m<strong>in</strong>imum spann<strong>in</strong>g tree which nicely can be represented <strong>in</strong> ord<strong>in</strong>ations,<br />
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>kage<br />
is prone to cha<strong>in</strong> data so that s<strong>in</strong>gle sites are jo<strong>in</strong>ed to large clusters.<br />
> cluc plot(cluc)<br />
Some people prefer complete l<strong>in</strong>kage because it makes compact clusters.<br />
However, this is <strong>in</strong> part an artefact <strong>of</strong> the method: the clusters are not<br />
allowed to grow, because the complete l<strong>in</strong>kage criterion would be violated.<br />
> clua plot(clua)<br />
Some people (I <strong>in</strong>cluded) prefer average l<strong>in</strong>kage cluster<strong>in</strong>g, because it<br />
seems to be a compromise between the previous two extremes, and more<br />
neutral <strong>in</strong> group<strong>in</strong>g. There are several alternative methods loosely connected<br />
to “average l<strong>in</strong>kage” family. Ward’s method seems to be popular <strong>in</strong><br />
publications. It approaches complete l<strong>in</strong>kage <strong>in</strong> its attempt to m<strong>in</strong>imize<br />
variances <strong>in</strong> agglomeration. The default "average" method is the one<br />
<strong>of</strong>ten known as upgma which was popular <strong>in</strong> old-time genetics.<br />
All these cluster<strong>in</strong>g methods are agglomerative. They start with comb<strong>in</strong><strong>in</strong>g<br />
two most similar sites to each other. Then they proceed by comb<strong>in</strong><strong>in</strong>g<br />
po<strong>in</strong>ts to po<strong>in</strong>ts or to groups, or groups to groups. The fusion criteria<br />
vary. The vertical axis <strong>in</strong> all graphs shows the level <strong>of</strong> fusion. The numbers<br />
vary among methods, but all are based on the same dissimilarities<br />
with range:<br />
> range(dis)<br />
[1] 0.2273 1.0000<br />
The first fusion is between the same two most similar sites <strong>in</strong> all examples,<br />
and at the same m<strong>in</strong>imum dissimilarity. In complete l<strong>in</strong>kage the last<br />
fusion comb<strong>in</strong>es the two most dissimilar sites, and it is at the maximum<br />
dissimilarity. In s<strong>in</strong>gle l<strong>in</strong>kage the fusion level always is at the smallest<br />
gap between groups, and the reported levels are much lower than with<br />
complete l<strong>in</strong>kage. Average l<strong>in</strong>kage makes fusions between group centre<br />
po<strong>in</strong>ts, and its fusion levels are between the previous two trees. The<br />
estimated dissimilarity between two po<strong>in</strong>ts is the level where they are<br />
fused <strong>in</strong> a tree. Function cophenetic f<strong>in</strong>ds this estimated dissimilarity<br />
from a tree for evey pair <strong>of</strong> po<strong>in</strong>ts – the name <strong>of</strong> the function reflects<br />
the history <strong>of</strong> cluster<strong>in</strong>g <strong>in</strong> numerical taxonomy. Cophenetic correlation<br />
measures the similarity between orig<strong>in</strong>al dissimilarities and dissimilarities<br />
estimated from the tree. For our three example methods:<br />
37<br />
Height<br />
Height<br />
Height<br />
0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55<br />
0.2 0.4 0.6 0.8 1.0<br />
0.2 0.3 0.4 0.5 0.6 0.7 0.8<br />
17<br />
17<br />
14<br />
19<br />
19<br />
16<br />
1<br />
14<br />
11<br />
18<br />
15<br />
20<br />
16<br />
1<br />
17<br />
19<br />
15<br />
20<br />
Cluster Dendrogram<br />
2<br />
10<br />
5<br />
11<br />
18<br />
13<br />
12<br />
2<br />
10<br />
dis<br />
hclust (*, "s<strong>in</strong>gle")<br />
Cluster Dendrogram<br />
1<br />
6<br />
7<br />
13<br />
12<br />
4<br />
3<br />
dis<br />
hclust (*, "complete")<br />
Cluster Dendrogram<br />
13<br />
12<br />
4<br />
3<br />
5<br />
6<br />
7<br />
8<br />
9<br />
11<br />
18<br />
dis<br />
hclust (*, "average")<br />
8<br />
9<br />
5<br />
4<br />
3<br />
14<br />
16<br />
6<br />
7<br />
8<br />
9<br />
15<br />
20<br />
2<br />
10
Height<br />
CA2<br />
0.2 0.4 0.6 0.8 1.0<br />
4 6 8 10<br />
−1 0 1 2 3<br />
6.2 Display and <strong>in</strong>terpretation <strong>of</strong> classes 6 CLASSIFICATION<br />
17<br />
19<br />
11<br />
18<br />
17<br />
1<br />
Cluster Dendrogram<br />
2<br />
10<br />
5<br />
6<br />
7<br />
13<br />
12<br />
4<br />
3<br />
dis<br />
hclust (*, "complete")<br />
●<br />
●<br />
8<br />
9<br />
14<br />
1 2 3<br />
10 6<br />
5<br />
7<br />
1<br />
19<br />
11<br />
2<br />
18<br />
12<br />
4 9<br />
3<br />
13<br />
−2 −1 0 1 2<br />
CA1<br />
8<br />
20<br />
15 14<br />
16<br />
16<br />
15<br />
20<br />
> cor(dis, cophenetic(clus))<br />
[1] 0.6602<br />
> cor(dis, cophenetic(cluc))<br />
[1] 0.6707<br />
> cor(dis, cophenetic(clua))<br />
[1] 0.8169<br />
Approximat<strong>in</strong>g dissimilarities is the same task that ord<strong>in</strong>ations perform,<br />
and average l<strong>in</strong>kage is the best performer.<br />
6.2 Display and <strong>in</strong>terpretation <strong>of</strong> classes<br />
Cluster analysis performs a hierarchic cluster<strong>in</strong>g, and its results can be<br />
<strong>in</strong>spected at as many levels as there are po<strong>in</strong>ts: the extremes are that<br />
every po<strong>in</strong>t is <strong>in</strong> its private cluster, or that all po<strong>in</strong>ts belong to the same<br />
cluster. We commonly want to <strong>in</strong>spect cluster<strong>in</strong>g at a certa<strong>in</strong> level, as a<br />
non-hierarchic system <strong>of</strong> certa<strong>in</strong> number <strong>of</strong> clusters. The flatten<strong>in</strong>g <strong>of</strong> the<br />
cluster<strong>in</strong>g happens by cutt<strong>in</strong>g the tree at some fusion level so that we get<br />
a desired number <strong>of</strong> clusters.<br />
Base R provides function rect.hclust to visualize the cutt<strong>in</strong>g, and<br />
function cutree to make a classification vector with certa<strong>in</strong> number <strong>of</strong><br />
classes:<br />
> plot(cluc)<br />
> rect.hclust(cluc, 3)<br />
> grp boxplot(A1 ~ grp, data=dune.env, notch = TRUE)<br />
If we wish, we may use all normal statistical methods with factors, such<br />
as functions lm or aov for formal test<strong>in</strong>g <strong>of</strong> “significance” <strong>of</strong> clusters.<br />
Classification can be compared aga<strong>in</strong>st external factor variables as well.<br />
However, <strong>vegan</strong> does not provide any tools for this. It may be best to<br />
see the labdsv package and its <strong>tutorial</strong> for this purpose.<br />
The cluster<strong>in</strong>g results can be displayed <strong>in</strong> ord<strong>in</strong>ation diagrams. All<br />
usual <strong>vegan</strong> functions for factors can be used: ordihull, ordispider,<br />
and ordiellipse. We shall see only the first as an example:<br />
> ord plot(ord, display = "sites")<br />
> ordihull(ord, grp, lty = 2, col = "red")<br />
It is said sometimes that overlay<strong>in</strong>g classification <strong>in</strong> ord<strong>in</strong>ation can be<br />
used as a cross-check: if the clusters look dist<strong>in</strong>ct <strong>in</strong> the ord<strong>in</strong>ation diagram,<br />
(both) analyses probably were adequate. However, the classes can<br />
overlap and the analyses can still be good. It may be that you need three<br />
38
6 CLASSIFICATION 6.3 Classified community tables<br />
or more axes to display the multivariate class structure. In addition, ord<strong>in</strong>ation<br />
and classification may use different criteria. In our example, ca<br />
uses weighted Chi-squared criteria, and the cluster<strong>in</strong>g uses Bray–Curtis<br />
dissimilarities which may be quite different. Function ordirgl with its<br />
support function orglspider can be used to <strong>in</strong>spect classification us<strong>in</strong>g<br />
dynamic 3D graphics.<br />
The <strong>vegan</strong> package has function ordicluster to overlay hclust tree<br />
<strong>in</strong> an ord<strong>in</strong>ation:<br />
> plot(ord, display="sites")<br />
> ordicluster(ord, cluc, col="blue")<br />
The function comb<strong>in</strong>es po<strong>in</strong>ts and cluster midpo<strong>in</strong>ts similarly as <strong>in</strong> the<br />
orig<strong>in</strong>al cluster dendrogram.<br />
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>ation<br />
diagrams. S<strong>in</strong>gle l<strong>in</strong>kage cluster<strong>in</strong>g is special among the cluster<strong>in</strong>g<br />
algorithms, because it always comb<strong>in</strong>es po<strong>in</strong>ts to po<strong>in</strong>ts: it is only the<br />
nearest po<strong>in</strong>t that is recognized and no <strong>in</strong>formation on its cluster membership<br />
is used. The dendrogram, however, hides this <strong>in</strong>formation: it<br />
only shows the fusions between clusters, but does not show which were<br />
the 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>ts<br />
is called a m<strong>in</strong>imum spann<strong>in</strong>g tree (mst). In graph theory, ‘tree’ is a<br />
connected graph with no loops, ‘spann<strong>in</strong>g tree’ is tree that connects all<br />
po<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><br />
connect<strong>in</strong>g segments is shortest. Function spantree <strong>in</strong> <strong>vegan</strong> f<strong>in</strong>d this<br />
tree, and it has a l<strong>in</strong>es function to overlay the tree onto ord<strong>in</strong>ation:<br />
> mst plot(mst, ord=ord, pch=21, col = "red", bg = "yellow", type = "t")<br />
In our dissimilarity <strong>in</strong>dex, distance = 1 means that there is noth<strong>in</strong>g <strong>in</strong><br />
common with two sample plots. Function spantree regards these maximum<br />
dissimilarities as miss<strong>in</strong>g data, and does not use them <strong>in</strong> build<strong>in</strong>g<br />
the tree. If all po<strong>in</strong>ts cannot be connected because <strong>of</strong> these miss<strong>in</strong>g values,<br />
the result will consist <strong>of</strong> disconnected spann<strong>in</strong>g trees. In graph theory this<br />
is known as a ‘forest’. Mst is used sometimes to cross-check ord<strong>in</strong>ation:<br />
if the tree is l<strong>in</strong>ear, the ord<strong>in</strong>ation might be good. A curved tree may<br />
<strong>in</strong>dicate arc or horseshoe artefacts, and a messy tree a bad ord<strong>in</strong>ation, or<br />
a need <strong>of</strong> higher number <strong>of</strong> dimensions. However, the results <strong>of</strong>ten are<br />
difficult to <strong>in</strong>terpret.<br />
6.3 Classified community tables<br />
The aim <strong>of</strong> classification <strong>of</strong>ten is to make a classified community table.<br />
For this purpose, both sites and species should be arranged so that the<br />
table looks structured. The orig<strong>in</strong>al cluster<strong>in</strong>g may not be ideally structured,<br />
because the order<strong>in</strong>g <strong>of</strong> sites is not strictly def<strong>in</strong>ed <strong>in</strong> the cluster<br />
dendrogram. You can take any branch and rotate it around its base, and<br />
the cluster<strong>in</strong>g is the same. The tree draw<strong>in</strong>g algorithms use heuristic<br />
rules to make the tree look aesthetically pleas<strong>in</strong>g, but this order<strong>in</strong>g may<br />
not be the best one for a structured community table.<br />
Base R has a general tree class called dendrogram which is <strong>in</strong>tended as<br />
a common base for any tree-like presentations. This class has a function<br />
39<br />
CA2<br />
CA2<br />
−1 0 1 2 3<br />
−1 0 1 2 3<br />
17<br />
10 6<br />
5<br />
7<br />
1<br />
19<br />
11<br />
2<br />
18<br />
12<br />
4 9<br />
3<br />
13<br />
−2 −1 0 1 2<br />
17<br />
10 6<br />
5<br />
7<br />
1<br />
19<br />
11<br />
2<br />
18<br />
CA1<br />
12<br />
4 9<br />
3<br />
13<br />
8<br />
20<br />
15 14<br />
−2 −1 0 1 2<br />
CA1<br />
8<br />
16<br />
20<br />
15 14<br />
16
0.0 0.2 0.4 0.6 0.8<br />
0.0 0.2 0.4 0.6 0.8<br />
6.3 Classified community tables 6 CLASSIFICATION<br />
14<br />
16<br />
15<br />
20<br />
17<br />
19<br />
1<br />
13<br />
12<br />
4<br />
3<br />
8<br />
9<br />
11<br />
18<br />
5<br />
6<br />
7<br />
2<br />
10<br />
17<br />
19<br />
1<br />
5<br />
7<br />
6<br />
10<br />
2<br />
11<br />
18<br />
3<br />
4<br />
9<br />
8<br />
12<br />
13<br />
14<br />
15<br />
20<br />
16<br />
to reorder a tree accord<strong>in</strong>g to some external variable. The hclust result<br />
can be changed <strong>in</strong>to dendrogram with function as.dendrogram, and this<br />
can be reorderd with function reorder. The only cont<strong>in</strong>uous variable<br />
<strong>in</strong> the Dune data is the thickness <strong>of</strong> A1 horizon, and this could be used<br />
to arrange the tree. However, for a nicely structured community table<br />
we use another trick: ca is an ord<strong>in</strong>ation method that structures table<br />
optimally <strong>in</strong>to a diagonal structure, and we can use its first axis to reorder<br />
the tree:<br />
> wa den oden op plot(den)<br />
> plot(oden)<br />
> par(op)<br />
Function vegemite <strong>in</strong> <strong>vegan</strong> produces compact vegetation tables. It<br />
can take an argument use to arrange the sites (and species, if possible).<br />
This argument can be a vector used to arrange sites, or it can be an<br />
ord<strong>in</strong>ation result, or it can be an hclust result or a dendrogram object.<br />
> vegemite(dune, use = oden, zero = "-")<br />
11 1 11 111121<br />
79157602183498234506<br />
Airpra 23------------------<br />
Empnig -2------------------<br />
Hyprad 25------2-----------<br />
Antodo 44-4234-------------<br />
Tripra ---225--------------<br />
Achmil 2-122243------------<br />
Plalan 2--5553-33----------<br />
Rumace ---536------2-2-----<br />
Brohor ---22-44---3--------<br />
Lolper --726665726524------<br />
Belper ---2--23-222--------<br />
Viclat ------1-21----------<br />
Elyrep --44---4--446-------<br />
Poapra 1-424344435444-2----<br />
Leoaut 26-3333555222322222-<br />
Trirep -2-225653221323261--<br />
Poatri --265447--655449---2<br />
Brarut -3-2262-4622224--444<br />
Sagpro -3------2--52242----<br />
Salrep -3-------3--------5-<br />
Cirarv -----------2--------<br />
Junbuf ----2-------4-43----<br />
Alogen -------2--723585---4<br />
Agrsto ----------4834454457<br />
Chealb ---------------1----<br />
Junart ------------44---343<br />
40
6 CLASSIFICATION 6.3 Classified community tables<br />
Potpal ----------------22--<br />
Ranfla -------------2-22242<br />
Elepal -------------4--4548<br />
Calcus ----------------4-33<br />
sites species<br />
20 30<br />
The dendrogram had no <strong>in</strong>formation on species, but it uses weigthed<br />
averages to arrange them similarly as sites. This may not be optimal for<br />
a cluster<strong>in</strong>g results, but if the clusters are reorderd nicely, the results may<br />
be very satisfactory with a nicely structured community table.<br />
The vegemite output is very compact (hence the name), and it uses<br />
only one column for sites. In this case this was automatic, s<strong>in</strong>ce Dune<br />
meadow data uses class scales. Percent cover scale can be transformed to<br />
traditional class scales, such as Braun-Blanquet, Dom<strong>in</strong> or Hult–Sernander–<br />
Du Rietz.<br />
Session Info<br />
R version 2.15.1 (2012-06-22), x86_64-pc-l<strong>in</strong>ux-gnu<br />
Locale: LC_CTYPE=en_IE.UTF-8, LC_NUMERIC=C, LC_TIME=en_IE.UTF-8,<br />
LC_COLLATE=en_IE.UTF-8, LC_MONETARY=en_IE.UTF-8,<br />
LC_MESSAGES=en_IE.UTF-8, LC_PAPER=C, LC_NAME=C, LC_ADDRESS=C,<br />
LC_TELEPHONE=C, LC_MEASUREMENT=en_IE.UTF-8, LC_IDENTIFICATION=C<br />
Base packages: base, datasets, graphics, grDevices, methods, stats, utils<br />
Other packages: MASS 7.3-23, mgcv 1.7-22, permute 0.7-0,<br />
scatterplot3d 0.3-33, <strong>vegan</strong> 2.0-6<br />
Loaded via a namespace (and not attached): grid 2.15.1, lattice 0.20-13,<br />
Matrix 1.0-10, nlme 3.1-108, tools 2.15.1<br />
41
Index<br />
adonis, 32, 33<br />
AIC, 24, 27<br />
anosim, 32<br />
anova, 21, 22, 31, 32, 34<br />
aov, 38<br />
apply, 9<br />
arc effect, 11, 12<br />
as.dendrogram, 40<br />
attach, 16, 33<br />
beta diversity, 7, 32, 33<br />
betadisper, 33<br />
betadiver, 7, 32<br />
bioenv, 35<br />
biplot, 9<br />
calibrate.cca, 29<br />
capscale, 18, 24<br />
cca, 9, 12, 18, 24<br />
cluster<strong>in</strong>g, 37–39<br />
cmdscale, 3, 18<br />
constra<strong>in</strong>ed analysis <strong>of</strong> proximities,<br />
18<br />
constra<strong>in</strong>ed correspondence analysis,<br />
18, 19<br />
constra<strong>in</strong>ed ord<strong>in</strong>ation, 18, 19, 21,<br />
23, 28<br />
contrasts, 20, 21<br />
cophenetic, 37<br />
correspondence analysis, 8, 10–12,<br />
18, 40<br />
cutree, 38<br />
daisy, 7<br />
decorana, 11–13<br />
decostand, 7<br />
dendrogram, 39–41<br />
designdist, 7<br />
detrended correspondence analysis,<br />
11, 12<br />
deviance, 24<br />
dissimilarity<br />
Arrhenius, 32<br />
b<strong>in</strong>omial, 6<br />
Bray-Curtis, 3, 5, 6<br />
Canberra, 6<br />
Chi-square, 8, 10, 18<br />
42<br />
chord, 7<br />
Czekanowski, 6<br />
Euclidean, 5–8, 18, 32<br />
Gower, 6<br />
Hell<strong>in</strong>ger, 7<br />
Horn-Morisita, 6<br />
Jaccard, 5, 6<br />
Kulczyński, 5<br />
Manhattan, 5<br />
metric properties, 6<br />
Morisita, 6<br />
Mountford, 6<br />
Raup-Crick, 6<br />
Ruˇzička, 6<br />
semimetric, 6<br />
Ste<strong>in</strong>haus, 3, 6<br />
Sørensen, 6, 7<br />
dist, 5, 7<br />
distance, 7<br />
downweight, 12<br />
downweight<strong>in</strong>g, 11, 12<br />
dsvdis, 7<br />
envfit, 15, 16, 18<br />
factor fitt<strong>in</strong>g, 16<br />
formula, 16, 19, 21, 23, 24<br />
gam, 16, 30<br />
half-change scal<strong>in</strong>g, 5<br />
hclust, 36, 37, 39, 40<br />
identify, 8, 13, 14<br />
<strong>in</strong>ertia, 9–11, 19–22, 24<br />
isoMDS, 3–5, 8<br />
LC scores, 28–30<br />
Levene’s test, 33<br />
lm, 38<br />
local optimum, 4<br />
make.cepnames, 13<br />
mantel, 35<br />
Mantel test, 35, 36<br />
partial, 35<br />
metaMDS, 4–6, 8, 36<br />
metric scal<strong>in</strong>g, 3, 8, 18
INDEX INDEX<br />
m<strong>in</strong>imum spann<strong>in</strong>g tree, 39<br />
mrpp, 32<br />
non-metric multidimensional scal<strong>in</strong>g,<br />
3–8, 15<br />
ordered factors, 21<br />
ordicluster, 39<br />
ordiellipse, 17, 38<br />
ordihull, 17, 38<br />
ordilabel, 13, 14<br />
ordiplot, 4, 12, 13<br />
ordiplot3d, 20<br />
ordipo<strong>in</strong>tlabel, 14<br />
ordirgl, 20, 39<br />
ordispider, 17, 18, 29, 38<br />
ordisurf, 16, 18, 30<br />
orditkplot, 14<br />
orditorp, 13, 14<br />
orglspider, 39<br />
package<br />
analogue, 7<br />
cluster, 7<br />
labdsv, 7, 36, 38<br />
MASS, 3<br />
mgcv, 16, 30<br />
partial ord<strong>in</strong>ation, 30<br />
permutation tests, 21, 33–36<br />
permutest, 34<br />
permutest.cca, 22<br />
po<strong>in</strong>ts, 12, 14<br />
prcomp, 8, 35<br />
pr<strong>in</strong>cipal components analysis, 8, 9,<br />
12, 35<br />
pr<strong>in</strong>cipal coord<strong>in</strong>ates analysis, 8<br />
pr<strong>in</strong>comp, 8, 35<br />
procrustes, 8<br />
Procrustes analysis, 36<br />
Procrustes rotation, 8<br />
protest, 36<br />
rank<strong>in</strong>dex, 6<br />
rda, 9, 18, 24, 32, 35<br />
rect.hclust, 38<br />
redundancy analysis, 18, 19<br />
reorder, 40<br />
scores, 4<br />
Shepard, 3<br />
spantree, 39<br />
species space, 5<br />
species–environment correlation, 28,<br />
29<br />
spl<strong>in</strong>es, 16<br />
standardization<br />
Hell<strong>in</strong>ger, 7<br />
norm, 7<br />
Wiscons<strong>in</strong>, 4, 7<br />
step, 24, 27, 29<br />
stress, 3<br />
stressplot, 3<br />
surface fitt<strong>in</strong>g, 15<br />
Tcl/Tk, 14<br />
text, 12, 14<br />
transformation<br />
square root, 4, 7<br />
Tukey’s HSD, 34<br />
var, 9<br />
variance <strong>in</strong>flation factor, 27<br />
varpart, 32<br />
vector fitt<strong>in</strong>g, 14<br />
vegdist, 3, 5–7, 32<br />
vegemite, 40, 41<br />
WA scores, 28, 29<br />
weighted averages, 5, 11, 28<br />
wiscons<strong>in</strong>, 7<br />
with, 16, 33<br />
43