This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
06-B-constrained-ordination.html
1924 lines (1826 loc) · 111 KB
/
06-B-constrained-ordination.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="Tad & Jamie" />
<title>Constrained ordination</title>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<style type="text/css">
/* padding for bootstrap navbar */
body {
padding-top: 51px;
padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar) */
.section h1 {
padding-top: 56px;
margin-top: -56px;
}
.section h2 {
padding-top: 56px;
margin-top: -56px;
}
.section h3 {
padding-top: 56px;
margin-top: -56px;
}
.section h4 {
padding-top: 56px;
margin-top: -56px;
}
.section h5 {
padding-top: 56px;
margin-top: -56px;
}
.section h6 {
padding-top: 56px;
margin-top: -56px;
}
</style>
<script>
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark it active
menuAnchor.parent().addClass('active');
// if it's got a parent navbar menu mark it active as well
menuAnchor.closest('li.dropdown').addClass('active');
});
</script>
<div class="container-fluid main-container">
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<script>
$(document).ready(function () {
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2,h3",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = false;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
padding-left: 25px;
text-indent: 0;
}
.tocify .list-group-item {
border-radius: 0px;
}
.tocify-subheader {
display: inline;
}
.tocify-subheader .tocify-item {
font-size: 0.95em;
}
</style>
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row-fluid">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="00-computer-setup.html">Computer Setup</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
W1
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="01-A-R-intro.html">Intro to R</a>
</li>
<li>
<a href="01-B-Rmarkdown-intro.html">R markdown</a>
</li>
<li>
<a href="01-C-R-workshop.html">R workshop</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
W2
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="02-A-tidyr.html">ggplot2 and tidyr</a>
</li>
<li>
<a href="02-B-git-intro.html">Intro to git</a>
</li>
<li>
<a href="02-C-student-projects.html">Project introductions</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
W3
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="03-A-data-exploration.html">Data exploration</a>
</li>
<li>
<a href="03-B-linear-models.html">Linear models</a>
</li>
<li>
<a href="03-C-heterogeneity.html">Heterogeneity</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
W4
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="04-A-mixed-models.html">Mixed effects models</a>
</li>
<li>
<a href="04-B-binary-data.html">Binary & proportional data</a>
</li>
<li>
<a href="04-C-zero-data.html">Zero-inflated data</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
W5
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="05-A-Bayesian-linear-models.html">Bayesian linear models</a>
</li>
<li>
<a href="05-B-Bayesian-priors.html">Bayesian inference with prior information</a>
</li>
<li>
<a href="05-C-Advanced-bayesian-example.html">Advanced Bayesian model example</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
W6
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="06-A-unconstrained-ordination.html">Unconstrained ordination</a>
</li>
<li>
<a href="06-B-constrained-ordination.html">Constrained ordination</a>
</li>
<li>
<a href="06-C-matrix-comparison.html">Comparing multivariate data</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
W8
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="08-A-mapping.html">Visualizing spatial data</a>
</li>
<li>
<a href="08-B-spatial-regression.html">Spatial regression</a>
</li>
<li>
<a href="08-C-spatial-ordination.html">Ordination approach to spatial analysis</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
W9
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="09-A-time-series.html">Time series</a>
</li>
<li>
<a href="09-B-networks.html">Network analysis</a>
</li>
<li>
<a href="09-C-occupancy-models.html">Occupancy models</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div class="fluid-row" id="header">
<h1 class="title toc-ignore">Constrained ordination</h1>
<h4 class="author"><em>Tad & Jamie</em></h4>
</div>
<p><strong>Assigned Reading:</strong></p>
<blockquote>
<p>Chapter 6 from: Borcard, D., Gillet, F. and Legendre, P. 2011. <em>Numerical Ecology with R.</em> Springer. <a href="https://link.springer.com/book/10.1007/978-1-4419-7976-6">link</a></p>
</blockquote>
<div id="key-points" class="section level3">
<h3>Key Points</h3>
<div id="unconstrained-vs.constrained-ordination" class="section level4">
<h4>Unconstrained vs. constrained ordination</h4>
<ul>
<li><p>Borcard et al. - Simple (unconstrained) ordination analyses a single data matrix. Canonical (constrained) ordination associates two or more data sets.</p></li>
<li><p>Ramette 2007 - “In constrained (canonical) ordination analyses, only the variation in the species table that can be explained by the environmental variables is displayed and analyzed, and not all the variation in the species table.” (This refers to asymmetrical methods only?)</p></li>
</ul>
<div class="figure">
<img src="images/ordination.jpg" alt="Ordination chart" style="width:80.0%" />
<p class="caption">Ordination chart</p>
</div>
</div>
<div id="in-ch-6" class="section level4">
<h4>In Ch 6</h4>
<ul>
<li><p>RDA, CCA: asymmetrical matrices; combines multiple regression with PCA or CA (Extensions: partial RDA, variation partitioning, db-RDA)</p></li>
<li><p>LDA: combines quantitative variables to explain predefined grouping of objects</p></li>
<li><p>CCorA, CoIA, MFA: symmetrical matrices; computes eigenvectors to describe common structure of two data sets</p></li>
</ul>
</div>
<div id="rda" class="section level4">
<h4>RDA</h4>
<ul>
<li><p>Regress each (Hellinger-transformed) y(i) on X, find y_hat(i), and do PCA on Y_hat</p></li>
<li><p>Scaling 1 vs. scaling 2 (default in R)</p></li>
<li><p>For species and sites, interpretation same as in PCA</p></li>
<li><p>For explanatory variables and their relationships with response variables, subtle but important differences regarding angles, positions, centroids</p></li>
</ul>
</div>
<div id="partial-rda" class="section level4">
<h4>Partial RDA</h4>
<ul>
<li>e.g., <code>envtopo</code> vs. <code>envchem</code></li>
</ul>
<p><code>(spechem.physio2 <- rda(spe.hel ~ pH + dur + pho + nit + amm</code> <code>+ oxy + dbo + Condition(alt + pen + deb), data=env))</code> <code>anova(spechem.physio2, step=1000)</code> <code>anova(spechem.physio2, step=1000, by="axis")</code></p>
</div>
<div id="forward-selection-of-explanatory-variables" class="section level4">
<h4>Forward selection of explanatory variables</h4>
<ul>
<li><p>Use VIFs to look for severe collinearity</p></li>
<li><p><code>forward.sel()</code> in <code>packfor</code> - Blanchet et al (2008) corrections built in</p></li>
<li><p><code>ordistep()</code> in <code>vegan</code> - allows use of factors</p></li>
</ul>
</div>
<div id="variation-partioning" class="section level4">
<h4>Variation partioning</h4>
<ul>
<li>Steps to compute R2adj (Peres-Neto et al. 2006) - <code>varpart()</code> in <code>vegan</code></li>
</ul>
</div>
<div id="db-rda-legendre-and-anderson-1999" class="section level4">
<h4>db-RDA (Legendre and Anderson 1999)</h4>
<ul>
<li><p>Allows use of various dissimilarity measures, as in PCoA</p></li>
<li><p>Run PCoA on Y and then RDA on principal coordinates</p></li>
<li><p><code>capscale()</code> in <code>vegan</code></p></li>
</ul>
</div>
<div id="cca" class="section level4">
<h4>CCA</h4>
<ul>
<li><p>Canonical counterpart of CA; otherwise similar to RDA</p></li>
<li><p>Rare species overemphasized</p></li>
</ul>
</div>
<div id="lda" class="section level4">
<h4>LDA</h4>
<ul>
<li>Identifies linear combinations of environmental variables that best discriminate groups obtained by cluster analysis</li>
</ul>
</div>
<div id="symmetric-analysis" class="section level4">
<h4>Symmetric analysis</h4>
<ul>
<li><p>CCorA, CoIA (and RLQ), MFA</p></li>
<li><p>No “dependent” or “explanatory” matrix</p></li>
<li><p>Suitable for studying, e.g.,</p></li>
<li>two groups of competing taxa
<ul>
<li>Soil-vegetation relationships</li>
</ul></li>
</ul>
<hr />
</div>
</div>
<div id="analysis-example" class="section level3">
<h3>Analysis Example</h3>
<p>Constrained ordinations use an a prior hypothesis to produce the ordination plot (i.e. they relate a matrix of response variables to explanatory variables). They only display the variation in the data of the explanatory variables (versus unconstrained which display all the variation in the data). An unconstrained ordination is useful for viewing overall patterns in the data, but constrained ordinations allow you to test hypotheses and discover trends that were hidden in the unconstrained ordination (i.e. masked by high variability and high correlation structure). When you are comparing an unconstrained and constrained ordination on the same data, it is important that you use the same distance metric in order to jointly interpret them.</p>
<p>Outline<br />
1) RDA</p>
<ul>
<li>interpret and plot<br />
</li>
<li>forward selection of variables<br />
</li>
</ul>
<ol start="2" style="list-style-type: decimal">
<li>CCA</li>
</ol>
<ul>
<li>interpret and plot<br />
</li>
</ul>
<ol start="3" style="list-style-type: decimal">
<li>db-RDA</li>
</ol>
<ul>
<li>interpret and plot<br />
</li>
</ul>
<ol start="4" style="list-style-type: decimal">
<li>CAP</li>
</ol>
<p>RDA and CCA are the two most common methods in ecology. db-RDA is very useful for using any dissimilarity/simmilarity measure. I’ll also mention CAP, which is not included in the reading, but seems like a robust constrained ordination.</p>
<p><em>Data</em>: I am using my own community data for this example. The data is a species by site matrix (264 species by 27 sites) of coral reef benthic organisms. After looking at correlations between my explanatory variables, the environmental data I will use in this analysis is net primary productivity, coral cover, relief, exposure, mangrove connectivity, seagrass connectivity and depth.</p>
<p>I try to show different ways of plotting the data other than base plot (i.e. using ggplot), but I wasn’t able to find packages that were able to plot all of the different constrained ordinations.</p>
<div id="rda-1" class="section level4">
<h4>RDA</h4>
<p><em>RDA</em>: combines regression and PCA, it is an extension of regression analysis to model multivariate response data. RDA computes axes that are linear combinations of the explanatory variables (in order of which explain the most variation of the species matrix). The axes are orthogonal to eachother (i.e. right angles). It is constrained because you are directly testing the influence of explanatory variables.</p>
<p>In terms of thinking of transforming your data for ordinations, this paper is helpful: <a href="http://adn.biol.umontreal.ca/~numericalecology/Reprints/Legendre_&_Gallagher.pdf" class="uri">http://adn.biol.umontreal.ca/~numericalecology/Reprints/Legendre_&_Gallagher.pdf</a></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Data import, transformation, distance matrix </span>
<span class="co"># clear my environment</span>
<span class="kw">rm</span>(<span class="dt">list=</span><span class="kw">ls</span>())
<span class="kw">library</span>(stringr)
<span class="kw">library</span>(dplyr)</code></pre></div>
<pre><code>##
## Attaching package: 'dplyr'</code></pre>
<pre><code>## The following objects are masked from 'package:stats':
##
## filter, lag</code></pre>
<pre><code>## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(tidyr)
<span class="kw">library</span>(vegan)</code></pre></div>
<pre><code>## Loading required package: permute</code></pre>
<pre><code>## Loading required package: lattice</code></pre>
<pre><code>## This is vegan 2.4-4</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
<span class="co"># Purpose: initial ordination on montastraea data</span>
<span class="kw">load</span>(<span class="st">"data/montastraea_species_matrix_vegan_harbornesites.Rdata"</span>) <span class="co"># mont.spec.matrix</span>
<span class="kw">load</span>(<span class="st">"data/montast_harbmeta_fullsite_shannon.Rdata"</span>) <span class="co"># shannon.montast.env.site</span>
<span class="kw">ls</span>()
<span class="kw">head</span>(shannon.montast.env.site)
<span class="co"># hellinger transform the species dataset: gives low weights to rare species </span>
spe.hel <-<span class="st"> </span><span class="kw">decostand</span>(mont.spec.matrix<span class="fl">.27</span>, <span class="st">"hellinger"</span>)
<span class="co"># Calculate distance matrix</span>
bc<-<span class="kw">vegdist</span>(spe.hel, <span class="dt">method=</span><span class="st">"bray"</span>, <span class="dt">binary=</span><span class="ot">FALSE</span>)
<span class="co"># look at an unconstrained ordination first, it is always a good idea to look at both unconstrained and constrained ordinations</span>
<span class="co"># set the seed: to reproduce the same result in the fture</span>
<span class="kw">set.seed</span>(<span class="dv">100</span>)
bci.mds<-<span class="kw">metaMDS</span>(spe.hel, <span class="dt">distance =</span> <span class="st">"bray"</span>, <span class="dt">k =</span> <span class="dv">2</span>)
<span class="co"># extract x and y coordinates from MDS plot into new dataframe, so you can plot with ggplot </span>
MDS_xy <-<span class="st"> </span><span class="kw">data.frame</span>(bci.mds$points)
bci.mds$stress <span class="co"># 0.1241412</span>
<span class="co"># colour by island</span>
<span class="kw">ggplot</span>(MDS_xy, <span class="kw">aes</span>(MDS1, MDS2, <span class="dt">col=</span>shannon.montast.env.site$Island)) +<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span><span class="kw">theme_bw</span>() +<span class="st"> </span><span class="kw">ggtitle</span>(<span class="st">'stress:0.12'</span>)</code></pre></div>
<p><img src="images/06-B/unnamed-chunk-2-1.png" width="672" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># RDA</span>
simpleRDA <-<span class="st"> </span><span class="kw">rda</span>(spe.hel ~<span class="st"> </span>Net_primary_productivity +<span class="st"> </span>Relief +<span class="st"> </span>Exposure +<span class="st"> </span>Mangrove_connectivity +<span class="st"> </span>Denseseagrass_connectivity +<span class="st"> </span>Coral +<span class="st"> </span>Depth +<span class="st"> </span>Protected_status_text, <span class="dt">data=</span>shannon.montast.env.site )
<span class="kw">summary</span>(simpleRDA)
<span class="kw">screeplot</span>(simpleRDA) <span class="co">#bstick not available for constrained ordinations</span></code></pre></div>
<p><img src="images/06-B/unnamed-chunk-3-1.png" width="672" /></p>
<p>So this is a lot of output, how do we interpret this?</p>
<p>We can see that the first two axes explain most of the variation (RDA1- 0.24. RDA2- 0.15, cumulative- 0.39) so plotting by these two axes seems to represent the data well. The unconstrained eigenvalue (PC1) is 0.05, so comparatively small, which means it does not display any important residenual structure of the response data. Each RDA axis has an eigenvalue, which is the proportion of the variance explained by each axis. The species and site scores tells us where the sites and species fall along the axes.</p>
<ul>
<li><em>Partioning of variance</em>: the overall variance is partitioned into constrained and unconstrained fractions. The constrained is the amount of variance the species by site matrix is explained by the explanatory variables (expressed as a proportion, is equivalent to R2 in a multiple regression). Yet this R2 is biased so you have to look at the adjusted R2 (below)<br />
</li>
<li><em>Eigenvalues and their contribute to variance</em>: RDA1 –> RDA9 for the canonical axes, and unconstrained axes. The cumulative contribute of the variance is the proportion of the total variance of the response data explained by the RDA. The results also give the eigenvalues.<br />
</li>
<li><em>Eigenvalues</em>: the canonical eigenvalues are decreasing in value (in the order they are presented). But sometimes the residual structure (residual eigenvalue PC1) can be larger than the last RDA eigenvalue, which means that the residual structure has more variance than some of the structures that can be explained by the explan variables. It is up to you on how to deal with this?<br />
</li>
<li><em>Canonical eigenvalues</em>: measure the amount of variance explained by the RDA model<br />
</li>
<li><em>Residual eigenvalues</em>: measure the amount of variance represented by the residual axes<br />
</li>
<li><em>Accumulated constrained eigenvalues</em>: cumulative amounts of variance expressed as proportions of the total explained variance<br />
</li>
<li><em>Species scores</em>: coordinates of the tips of vectors representing the response variables in bi or triplots<br />
</li>
<li><em>Site scores (weighted sums of species scores)</em>: coordinates of the sites as expressed in the space of the response variables<br />
</li>
<li><em>Site constraints (linear combinations of constraining variables)</em>: coordinates of the sites in space of the explanatory variables<br />
</li>
<li><em>Biplot scores for constraining variables</em>: coordinates of the tips of the vectors represnting explanatory variables<br />
</li>
<li><em>Centroids for factor constraints</em>: coordinates of centroids of levels of factor variables</li>
</ul>
<p>What if we want the canonical coefficient (i.e. the equivalent of regression coefficients for each explanatory variable on each canonical axis)</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># canonical coefficients</span>
<span class="kw">coef</span>(simpleRDA)</code></pre></div>
<div id="retrive-interpret-and-plot-results-from-the-vegan-rda-output" class="section level5">
<h5>Retrive, interpret and plot results from the vegan RDA output</h5>
<p>We can get the R2 for model fit for the constrained ordinations.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># unadjusted R^2 retreived from the rda result</span>
R2 <-<span class="st"> </span><span class="kw">RsquareAdj</span>(simpleRDA)$r.squared
R2 </code></pre></div>
<pre><code>## [1] 0.6447528</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># adjusted R^2</span>
R2adj <-<span class="st"> </span><span class="kw">RsquareAdj</span>(simpleRDA)$adj.r.squared
R2adj </code></pre></div>
<pre><code>## [1] 0.4566807</code></pre>
<p>As you can see, the adjustment has reduced the value of R2. The adjusted R2 measures the unbiased amount of explained variation. So this model explains 45.6% of the variation in the data. If you used the biased R2, any variable included in the explanatory responses would increase the R2, so the R2 needs to be adjusted for the number of explanatory variables (especially since we have eight included here).</p>
<p>Now lets plot the results of the RDA. There are two ways to plot the RDA, using “wa” and “lc”.</p>
<p>The first plots we will show will be using ‘wa’ plotting (weighted sums of species).</p>
<p>Note: the code below uses a package called <code>ggord</code>. You can find instructions for installing this package <a href="https://github.com/fawda123/ggord">here</a>.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Triplot: three different entities in the plot: sites, response variables and explanatory variables (arrowheads are on the explanatory variables)</span>
<span class="co"># Scaling 1</span>
<span class="kw">plot</span>(simpleRDA, <span class="dt">scaling=</span><span class="dv">1</span>, <span class="dt">main=</span><span class="st">"Triplot RDA matrix ~ env - scaling 1 - wa scores"</span>)
<span class="co"># arrows for species are missing, so lets add them without heads so they look different than the explanatory variables</span>
spe.sc <-<span class="st"> </span><span class="kw">scores</span>(simpleRDA, <span class="dt">choices=</span><span class="dv">1</span>:<span class="dv">2</span>, <span class="dt">scaling=</span><span class="dv">1</span>, <span class="dt">display=</span><span class="st">"sp"</span>)
<span class="kw">arrows</span>(<span class="dv">0</span>,<span class="dv">0</span>,spe.sc[,<span class="dv">1</span>], spe.sc[,<span class="dv">2</span>], <span class="dt">length=</span><span class="dv">0</span>, <span class="dt">lty=</span><span class="dv">1</span>, <span class="dt">col=</span><span class="st">'red'</span>)</code></pre></div>
<p><img src="images/06-B/unnamed-chunk-6-1.png" width="672" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Scaling 2</span>
<span class="kw">plot</span>(simpleRDA, <span class="dt">main=</span><span class="st">"Triplot RDA matrix ~ env - scaling 2 - wa scores"</span>)
spe2.sc <-<span class="st"> </span><span class="kw">scores</span>(simpleRDA, <span class="dt">choices=</span><span class="dv">1</span>:<span class="dv">2</span>, <span class="dt">display=</span><span class="st">"sp"</span>) <span class="co"># scores() choices= indicates which axes are to be selected, make sure to specify the scaling if its different than 2 </span>
<span class="kw">arrows</span>(<span class="dv">0</span>,<span class="dv">0</span>,spe2.sc[,<span class="dv">1</span>], spe2.sc[,<span class="dv">2</span>], <span class="dt">length=</span><span class="dv">0</span>, <span class="dt">lty=</span><span class="dv">1</span>, <span class="dt">col=</span><span class="st">'red'</span>)</code></pre></div>
<p><img src="images/06-B/unnamed-chunk-6-2.png" width="672" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># plot the RDA using ggplot (ggord package)</span>
<span class="kw">library</span>(ggord)
<span class="kw">ggord</span>(simpleRDA, shannon.montast.env.site$Island) +<span class="st"> </span><span class="kw">theme</span>(<span class="dt">panel.grid.major =</span> <span class="kw">element_blank</span>(), <span class="dt">panel.grid.minor =</span> <span class="kw">element_blank</span>()) <span class="co"># looking at the raw code, this is plotting the 'wa scores', the blue dots are different species </span></code></pre></div>
<p><img src="images/06-B/unnamed-chunk-6-3.png" width="672" /> So these results are showing us that Mangrove connectivity, Relief, Coral, Dense seagrass connectivity, and Depth are contributing to RDA2 while Exposure and Net primary productivity are contributing to RDA1. It seems that sites with increasing depth have decreasing exposure (from scaling 2). The vectors indicate species that are driving different axes.</p>
<p><em>Wa or lc?</em></p>
<p>The two RDA plots above use the site scores that are weighted sums of species (wa), but you can choose the fitted site scores (lc). Choosing between these site scores is still controversial.</p>
<p>‘lc’: orthogonal linear combinations of the explanatory variable<br />
‘wa’: more robust to noise in the environmental variables but are a step between constrained towards unconstrained.</p>
<p><em>How do we know whether to use lc or wa?</em></p>
<p>Most of the time, the default is “wa”. Because these are the most robust to noise in the data.</p>
<p>Remember Scaling 1 vs Scaling 2:</p>
<ul>
<li><em>Scaling 1</em>- distance biplot (object focused): distance between objects are eudlidean distances (objects closer together have similar variable values), angles between vectors of response variables are meaningless. Angles between vectors of response variables and explanatory variables reflect linear correlation.<br />
</li>
<li><em>Scaling 2</em>- correlation biplot (response variable focused): distances between objects are not approximate Euclidean distances. Angles between <strong>all</strong> vectors reflect linear correlation.</li>
</ul>
<p>Now lets plot the results of the RDA using ‘lc’</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># site scores as linear combinations of the environmental variables </span>
<span class="co"># Scaling 1</span>
<span class="kw">plot</span>(simpleRDA, <span class="dt">scaling=</span><span class="dv">1</span>, <span class="dt">display=</span><span class="kw">c</span>(<span class="st">"lc"</span>, <span class="st">"sp"</span>, <span class="st">"cn"</span>), <span class="dt">main=</span><span class="st">"Triplot RDA matrix ~ env -scaling 1- lc scores"</span>)
<span class="kw">arrows</span>(<span class="dv">0</span>,<span class="dv">0</span>, spe.sc[,<span class="dv">1</span>], spe.sc[,<span class="dv">2</span>], <span class="dt">length=</span><span class="dv">0</span>, <span class="dt">lty=</span><span class="dv">1</span>, <span class="dt">col=</span><span class="st">'red'</span>)</code></pre></div>
<p><img src="images/06-B/unnamed-chunk-7-1.png" width="672" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># text(simpleRDA, display = "spec", cex=0.7, col="blue")</span>
<span class="co"># scaling 2</span>
<span class="kw">plot</span>(simpleRDA, <span class="dt">display=</span><span class="kw">c</span>(<span class="st">"sp"</span>, <span class="st">"lc"</span>, <span class="st">"cn"</span>), <span class="dt">main=</span><span class="st">"Triplot RDA matrix ~ env -scaling2-lc scores"</span>, <span class="dt">col=</span>shannon.montast.env.site$Island)
<span class="kw">arrows</span>(<span class="dv">0</span>,<span class="dv">0</span>,spe2.sc[,<span class="dv">1</span>],spe2.sc[,<span class="dv">2</span>], <span class="dt">length=</span><span class="dv">0</span>, <span class="dt">lty=</span><span class="dv">1</span>,<span class="dt">col=</span><span class="st">'red'</span>)</code></pre></div>
<p><img src="images/06-B/unnamed-chunk-7-2.png" width="672" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># To choose the elements that are plotted, use the argument display=c(), sp=species, wa= site scores in the species space (weighted averages), lc= fitted site scores (linear combinations of explanatory variables) and cn= constraints (the explanatory variables)</span></code></pre></div>
<p>The results look very similar. We will stick with ‘wa’ because they are the suggested scores.</p>
</div>
<div id="forward-selection-of-variables" class="section level5">
<h5>Forward Selection of Variables</h5>
<p>When you want to reduce the number of explanatory variables.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># variance inflation factors in the RDA</span>
<span class="kw">vif.cca</span>(simpleRDA)</code></pre></div>
<pre><code>## Net_primary_productivity Relief
## 2.695918 3.667992
## Exposure Mangrove_connectivity
## 4.295913 5.150047
## Denseseagrass_connectivity Coral
## 9.440542 1.965195
## Depth Protected_status_textNo-take
## 1.721723 7.498254
## Protected_status_textSome management
## 4.927174</code></pre>
<p>Anything above 10 should be examined or avoided. Seagrass connectivity is close, but not over 10.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Forward selection of explanatory variables (form of model selection)</span>
<span class="co"># RDA with all explanatory variables </span>
spe.rda.all <-<span class="st"> </span><span class="kw">rda</span>(spe.hel ~<span class="st"> </span>Net_primary_productivity +<span class="st"> </span>Relief +<span class="st"> </span>Exposure +<span class="st"> </span>Mangrove_connectivity +<span class="st"> </span>Denseseagrass_connectivity +<span class="st"> </span>Coral +<span class="st"> </span>Depth +<span class="st"> </span>Protected_status_text, <span class="dt">data=</span>shannon.montast.env.site)
<span class="co"># Forward selection using ordistep</span>
<span class="kw">ordistep</span>(<span class="kw">rda</span>(spe.hel ~Net_primary_productivity +<span class="st"> </span>Relief +<span class="st"> </span>Exposure +<span class="st"> </span>Mangrove_connectivity +<span class="st"> </span>Denseseagrass_connectivity +<span class="st"> </span>Coral +<span class="st"> </span>Depth +<span class="st"> </span>Protected_status_text, <span class="dt">data=</span>shannon.montast.env.site), <span class="dt">direction=</span><span class="st">"forward"</span>, <span class="dt">pstep=</span><span class="dv">1000</span>, <span class="dt">R2scop=</span><span class="ot">TRUE</span>) <span class="co">#R2scope only accepts models with lower adjusted R2</span></code></pre></div>
<pre><code>##
## Start: spe.hel ~ Net_primary_productivity + Relief + Exposure + Mangrove_connectivity + Denseseagrass_connectivity + Coral + Depth + Protected_status_text</code></pre>
<pre><code>## Call: rda(formula = spe.hel ~ Net_primary_productivity + Relief +
## Exposure + Mangrove_connectivity + Denseseagrass_connectivity +
## Coral + Depth + Protected_status_text, data =
## shannon.montast.env.site)
##
## Inertia Proportion Rank
## Total 0.19156 1.00000
## Constrained 0.12351 0.64475 9
## Unconstrained 0.06805 0.35525 17
## Inertia is variance
##
## Eigenvalues for constrained axes:
## RDA1 RDA2 RDA3 RDA4 RDA5 RDA6 RDA7 RDA8 RDA9
## 0.04602 0.02917 0.01549 0.00989 0.00789 0.00491 0.00436 0.00300 0.00279
##
## Eigenvalues for unconstrained axes:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8
## 0.010759 0.008512 0.006477 0.005134 0.004891 0.004096 0.003939 0.003584
## (Showed only 8 of all 17 unconstrained eigenvalues)</code></pre>
<p>So it says the best model for this data includes all of the explanatory variables.</p>
</div>
<div id="permutation-tests-of-rda-results" class="section level5">
<h5>Permutation Tests of RDA Results</h5>
<p>Permutation tests are common in ecology because alot of our data is non-normal. Permutation tests generates a reference distribution of a chosen test statistic by randomly permuting elements of the data a large number of times and recomputing the statistic each time. Then you compare the true value of the statistic to the reference distribution.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Test of RDA result</span>
<span class="kw">anova.cca</span>(simpleRDA, <span class="dt">step=</span><span class="dv">1000</span>)</code></pre></div>
<pre><code>## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(formula = spe.hel ~ Net_primary_productivity + Relief + Exposure + Mangrove_connectivity + Denseseagrass_connectivity + Coral + Depth + Protected_status_text, data = shannon.montast.env.site)
## Df Variance F Pr(>F)
## Model 9 0.123508 3.4282 0.001 ***
## Residual 17 0.068051
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Test of all canonical axes</span>
<span class="kw">anova.cca</span>(simpleRDA, <span class="dt">by=</span><span class="st">'axis'</span>, <span class="dt">step=</span><span class="dv">1000</span>)</code></pre></div>
<pre><code>## Permutation test for rda under reduced model
## Forward tests for axes
## Permutation: free
## Number of permutations: 999
##
## Model: rda(formula = spe.hel ~ Net_primary_productivity + Relief + Exposure + Mangrove_connectivity + Denseseagrass_connectivity + Coral + Depth + Protected_status_text, data = shannon.montast.env.site)
## Df Variance F Pr(>F)
## RDA1 1 0.046015 11.4953 0.001 ***
## RDA2 1 0.029168 7.2867 0.001 ***
## RDA3 1 0.015491 3.8700 0.001 ***
## RDA4 1 0.009886 2.4697 0.009 **
## RDA5 1 0.007886 1.9702 0.123
## RDA6 1 0.004906 1.2257 0.850
## RDA7 1 0.004363 1.0900 0.871
## RDA8 1 0.003003 0.7503 0.993
## RDA9 1 0.002787 0.6962 0.878
## Residual 17 0.068051
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</code></pre>
<p>RDA Result: The model refers to the constrained component and the residual is the uncontrained ordination. From this, we can see the model is significant.</p>
<p>All canonical axes: Note only the top 4 axes are significant. I think this is ok, because we are mainly interested in the top 2.</p>
</div>
</div>
<div id="cca-canonical-correspondence-analysis" class="section level4">
<h4>CCA: Canonical correspondence analysis</h4>
<p>It is a weighted form of RDA applied to the same species matrix. It preserves the chi-squared distance among sites, and species are represented as points in triplots. In the CCA triplot species are ordered along canonical axes following their ecological optima, which allows relatively easy ecological interpretation. The drawbacks, are the chi-squared distance is not always accepted by ecologists and it was “one of the worst distances for community composition data”. It should only be used where rare species are sampled well and are seen as potential indicators of paricular characteristics of the ecosystem. Or else you could get rid of rare species prior to CCA. Additional, you can not compute an adjusted R2 (i.e. you have a biased measure of explained variation).</p>
<p>This probably is not the best bet for my data, but since it is so common, let’s run a quick example and talk about how to interpret it.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># CCA constrained by the same environmental data</span>
simpleCCA <-<span class="st"> </span><span class="kw">cca</span>(mont.spec.matrix<span class="fl">.27</span> ~<span class="st"> </span>Net_primary_productivity +<span class="st"> </span>Relief +<span class="st"> </span>Exposure +<span class="st"> </span>Mangrove_connectivity +<span class="st"> </span>Denseseagrass_connectivity +<span class="st"> </span>Coral +<span class="st"> </span>Depth +<span class="st"> </span>Protected_status_text, <span class="dt">data=</span>shannon.montast.env.site ) <span class="co"># Notice we are not using the hellinger transformation that downweights the importance of rare species</span>
<span class="kw">summary</span>(simpleCCA)
<span class="co"># variation is now expressed as the mean squared contigency coefficient (biased and is not easily adjusted)</span>
<span class="co"># species scores are represented as points</span>
<span class="co"># site scores are averages of species scores </span>
<span class="kw">screeplot</span>(simpleCCA) <span class="co"># the first two axes are not as clear </span></code></pre></div>
<p><img src="images/06-B/unnamed-chunk-11-1.png" width="672" /></p>
<p>The model explains 59% of the variation with 41% left unconstrained. The top axes are not as clear with the first two CCA1- 0.1736, CCA2- 0.11564, not that much higher than CCA3 0.09216.</p>
<p>But let’s plot it just with the two axes.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># CCA Triplots</span>
<span class="co"># Scaling 1: species scores scaled to relative eigenvalues, sites are weighted averages of the species </span>
<span class="kw">plot</span>(simpleCCA, <span class="dt">scaling=</span><span class="dv">1</span>, <span class="dt">display=</span><span class="kw">c</span>(<span class="st">'sp'</span>, <span class="st">'lc'</span>, <span class="st">'cn'</span>), <span class="dt">main=</span><span class="st">'Triplot CCA matrix ~ env -scaling 1'</span>)</code></pre></div>
<p><img src="images/06-B/unnamed-chunk-12-1.png" width="672" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Scaling 2 (default): site scores scaled to relative eigenvalues, species are weighted averages of the sites </span>
<span class="kw">plot</span>(simpleCCA, <span class="dt">display=</span><span class="kw">c</span>(<span class="st">'sp'</span>, <span class="st">'lc'</span>, <span class="st">'cn'</span>), <span class="dt">main=</span><span class="st">"Triplot CCA matrix ~ env -scaling 2"</span>)</code></pre></div>
<p><img src="images/06-B/unnamed-chunk-12-2.png" width="672" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># plot the CCA using ggplot (ggord package)</span>
<span class="kw">ggord</span>(simpleCCA, shannon.montast.env.site$Island) +<span class="st"> </span><span class="kw">theme</span>(<span class="dt">panel.grid.major =</span> <span class="kw">element_blank</span>(), <span class="dt">panel.grid.minor =</span> <span class="kw">element_blank</span>()) <span class="co"># looking at the raw code, this is plotting the 'wa scores'</span></code></pre></div>
<p><img src="images/06-B/unnamed-chunk-12-3.png" width="672" /> So this is telling us similar results to the RDA.</p>
<div id="distance-based-rda" class="section level5">
<h5>Distance Based RDA</h5>
<p>db-RDA is an important constrained ordination because it allows you to use other dissimilarity matrices (e.g. bray) that are non-euclidean in RDA (i.e. you don’t have the double zero problem). It makes a dissimilarity matrix, creates a PCoA, then runs an RDA of the principal coordinates created in the PCoA constrained by the explanatory variables.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># db-RDA</span>
dbRDA <-<span class="st"> </span><span class="kw">capscale</span>(mont.spec.matrix<span class="fl">.27</span> ~<span class="st"> </span>Net_primary_productivity +<span class="st"> </span>Relief +<span class="st"> </span>Exposure +<span class="st"> </span>Mangrove_connectivity +<span class="st"> </span>Denseseagrass_connectivity +<span class="st"> </span>Coral +<span class="st"> </span>Depth +<span class="st"> </span>Protected_status_text, <span class="dt">data=</span>shannon.montast.env.site, <span class="dt">distance =</span> <span class="st">"bray"</span>)
dbRDA</code></pre></div>
<pre><code>## Call: capscale(formula = mont.spec.matrix.27 ~
## Net_primary_productivity + Relief + Exposure +
## Mangrove_connectivity + Denseseagrass_connectivity + Coral + Depth
## + Protected_status_text, data = shannon.montast.env.site, distance
## = "bray")
##
## Inertia Proportion Eigenvals Rank
## Total 2.05445 1.00000 2.06789
## Constrained 1.40199 0.68241 1.40650 9
## Unconstrained 0.65247 0.31759 0.66139 17
## Imaginary -0.01344 2
## Inertia is squared Bray distance
##
## Eigenvalues for constrained axes:
## CAP1 CAP2 CAP3 CAP4 CAP5 CAP6 CAP7 CAP8 CAP9
## 0.5336 0.4557 0.1404 0.0965 0.0774 0.0387 0.0328 0.0184 0.0129
##
## Eigenvalues for unconstrained axes:
## MDS1 MDS2 MDS3 MDS4 MDS5 MDS6 MDS7 MDS8
## 0.13359 0.10560 0.08845 0.06212 0.04350 0.03800 0.03458 0.03135
## (Showed only 8 of all 17 unconstrained eigenvalues)</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">plot</span>(dbRDA)</code></pre></div>
<p><img src="images/06-B/unnamed-chunk-13-1.png" width="672" /></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">summary</span>(dbRDA)</code></pre></div>
<pre><code>##
## Call:
## capscale(formula = mont.spec.matrix.27 ~ Net_primary_productivity + Relief + Exposure + Mangrove_connectivity + Denseseagrass_connectivity + Coral + Depth + Protected_status_text, data = shannon.montast.env.site, distance = "bray")
##
## Partitioning of squared Bray distance:
## Inertia Proportion
## Total 2.0679 1.0000
## Constrained 1.4020 0.6780
## Unconstrained 0.6525 0.3155
##
## Eigenvalues, and their contribution to the squared Bray distance
##
## Importance of components:
## CAP1 CAP2 CAP3 CAP4 CAP5 CAP6
## Eigenvalue 0.5336 0.4557 0.14042 0.09653 0.07745 0.03868
## Proportion Explained 0.2580 0.2204 0.06791 0.04668 0.03745 0.01870
## Cumulative Proportion 0.2580 0.4784 0.54631 0.59299 0.63045 0.64915
## CAP7 CAP8 CAP9 MDS1 MDS2 MDS3
## Eigenvalue 0.03283 0.01837 0.01293 0.1336 0.10560 0.08845
## Proportion Explained 0.01588 0.00888 0.00625 0.0646 0.05107 0.04277
## Cumulative Proportion 0.66503 0.67391 0.68016 0.7448 0.79583 0.83860
## MDS4 MDS5 MDS6 MDS7 MDS8 MDS9
## Eigenvalue 0.06212 0.04350 0.03800 0.03458 0.03135 0.02384
## Proportion Explained 0.03004 0.02104 0.01838 0.01672 0.01516 0.01153
## Cumulative Proportion 0.86865 0.88968 0.90806 0.92478 0.93994 0.95147
## MDS10 MDS11 MDS12 MDS13 MDS14 MDS15
## Eigenvalue 0.02218 0.01773 0.01723 0.01356 0.01295 0.008175
## Proportion Explained 0.01072 0.00858 0.00833 0.00656 0.00626 0.003950
## Cumulative Proportion 0.96219 0.97077 0.97910 0.98566 0.99193 0.995880
## MDS16 MDS17
## Eigenvalue 0.00535 0.003169
## Proportion Explained 0.00259 0.001530
## Cumulative Proportion 0.99847 1.000000
##
## Accumulated constrained eigenvalues
## Importance of components:
## CAP1 CAP2 CAP3 CAP4 CAP5 CAP6
## Eigenvalue 0.5336 0.4557 0.14042 0.09653 0.07745 0.03868
## Proportion Explained 0.3794 0.3240 0.09984 0.06863 0.05506 0.02750
## Cumulative Proportion 0.3794 0.7034 0.80321 0.87184 0.92691 0.95441
## CAP7 CAP8 CAP9
## Eigenvalue 0.03283 0.01837 0.01293
## Proportion Explained 0.02334 0.01306 0.00919
## Cumulative Proportion 0.97775 0.99081 1.00000
##
## Scaling 2 for species and site scores
## * Species are scaled proportional to eigenvalues
## * Sites are unscaled: weighted dispersion equal on all dimensions
## * General scaling constant of scores: 2.703444
##
##
## Species scores
##
## CAP1 CAP2 CAP3 CAP4
## AGJ 0.0185904 1.151e-01 6.058e-02 -5.501e-02
## Acervicornis -0.0153068 6.642e-03 -3.544e-03 1.436e-04
## Acetabularia 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Acfulva 0.2810320 -1.147e-01 7.373e-02 3.621e-02
## Aclathrodes 0.0051215 9.409e-03 9.260e-03 -5.720e-03
## Acomplanarta 0.0090113 -8.182e-03 -9.401e-03 1.736e-03
## Acompressa 0.0163490 -4.566e-02 5.867e-02 -3.959e-02
## Aconifera 0.0641576 -2.220e-02 -2.303e-02 -4.858e-03
## Acrassa 0.1420728 -2.545e-02 -5.561e-02 -8.395e-03
## Adispar 0.0053420 3.272e-03 -5.927e-03 6.662e-04
## Afistularis 0.2116285 -6.385e-02 1.939e-01 -5.972e-03
## Aga 0.1523476 1.388e-01 -4.660e-02 -2.192e-01
## Aga.f.carinata.dana -0.0742220 6.662e-02 -3.368e-02 -1.524e-01
## Aga.f.purp -0.0111332 -1.911e-02 -9.277e-03 -2.923e-02
## Agf 0.0038225 -2.311e-02 5.303e-03 -2.465e-02
## Agg.u 0.0045405 -2.301e-03 -3.916e-03 2.559e-03
## Agt 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Alacunosa 0.0056906 -6.138e-04 2.790e-03 -3.293e-03
## Amber.penshell 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Amuricatum 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Anadyo 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Apalmata 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Aprolifera 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Aramosissima 0.0032692 -1.048e-03 -3.529e-03 4.233e-04
## Arenicola 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Avarians 0.1111354 -3.552e-02 -1.951e-02 -4.806e-04
## Aviridis 0.0198174 -6.313e-03 -1.830e-02 1.450e-02
## Avr...Udo 0.0432798 -3.766e-02 5.384e-02 2.506e-02
## B.fireworm 0.0000000 0.000e+00 0.000e+00 0.000e+00
## BBS 0.0181335 1.462e-02 1.883e-02 -1.206e-02
## BG.blob 0.0495124 1.436e-01 5.605e-02 -3.478e-02
## Balanophyllia.sp 0.0018294 1.868e-03 6.414e-04 -7.597e-04
## Bartholomea -0.0063474 -8.314e-04 -1.223e-04 -1.268e-04
## Batophorasp 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Bivalve 0.0054230 -1.662e-03 -4.824e-03 4.075e-03
## Black.ball.spg 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Black.enc.spg 0.0293460 -4.761e-03 -8.075e-03 9.729e-03
## Black.band.dis -0.0022224 -1.640e-04 -1.421e-03 -9.384e-04
## Blue.grey.lump 0.0018294 1.868e-03 6.414e-04 -7.597e-04
## Briareum 0.0972877 -1.794e-01 -9.231e-02 -1.004e-01
## Brown.zoanthid 0.0047734 -3.374e-03 -5.241e-03 -2.185e-03
## CW -0.1735429 1.144e-01 -5.736e-02 2.846e-03
## Cassopfrondosa 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Caulerpasp 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Caulsertularoides 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Cbetinensis 0.0158957 2.229e-02 1.222e-02 -1.134e-02
## Ccupress 0.0038119 -7.548e-03 7.653e-03 1.576e-02
## Cdelx 0.2308972 1.209e-02 -7.189e-02 -5.835e-02
## Cerithium -0.0007850 -2.863e-03 -5.781e-04 -2.668e-03
## Cfallax 0.0385239 -6.502e-03 -1.572e-02 3.397e-03
## Christmas.tree.worm 0.0452382 -4.811e-02 -3.708e-03 -2.146e-02
## Cinachyra 0.0017967 2.749e-03 -1.130e-02 4.095e-03
## Clac 0.0384805 1.198e-03 -1.025e-02 2.791e-03
## Clathriasp 0.0032602 -9.089e-04 -1.284e-03 1.284e-04
## Clavelinasp 0.0062151 -4.282e-03 -3.224e-03 -3.739e-03
## Clypeasterrosa 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Cnummularia 0.0000000 0.000e+00 0.000e+00 0.000e+00
## Colpophyllia -0.0103835 -3.148e-03 -4.694e-03 -5.353e-03