forked from FukamiLab/BIO202
-
Notifications
You must be signed in to change notification settings - Fork 0
/
08-C-spatial-ordination.html
1399 lines (1298 loc) · 73.3 KB
/
08-C-spatial-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="Jes & Sandra" />
<title>Ordination approach to spatial analysis</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">Ordination approach to spatial analysis</h1>
<h4 class="author"><em>Jes & Sandra</em></h4>
</div>
<p><strong>Assigned Reading:</strong></p>
<blockquote>
<p>Chapter 7 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>
<p>Two ordination-based approaches to modeling spatial structure:</p>
<ol style="list-style-type: decimal">
<li>Do an ordination of the spatial relationships among sampling locations and use these “spatial eigenvectors” to explore variation in a response variable (e.g. PCNM, MEM).</li>
<li>Do an ordination of the response (e.g. community data) and use the variogram of the resulting eigenvectors to explore spatial dependence of the primary axes of variation (e.g. MSO).</li>
</ol>
<div id="approach-1-morans-eigenvector-maps-mem-and-principal-coordinates-of-neighbor-matrices-pcnm" class="section level4">
<h4>Approach 1: Moran’s Eigenvector Maps (MEM) and Principal Coordinates of Neighbor Matrices (PCNM)</h4>
<ol style="list-style-type: decimal">
<li>Construct spatial variables (eigenvectors) derived from the adjacency of sampling sites.</li>
</ol>
<ul>
<li>PCNM: uses a distance matrix
<ol style="list-style-type: decimal">
<li>Create a matrix of Euclidean distances among sites and set sites that are far apart to 0. (All sites must be connected.)</li>
<li>Compute a PCoA of the distance matrix to create spatial eigenvectors representing the broadest to smallest potential spatial structures that can be detected by your sampling design.</li>
</ol></li>
<li>MEM: uses similarity matrix
<ol style="list-style-type: decimal">
<li>Define a spatial weights matrix in which weights (<span class="math inline">\(w_{i,j}\)</span>) are larger between sites that are more similar (e.g. closer together).</li>
</ol>
<p><span class="math display">\[W[i,j] = \begin{cases}
0 & \text{if $i$ and $j$ are not connected} \\
w_{i,j} & \text{if $i$ and $j$ are connected}
\end{cases}\]</span></p>
<p>Note: How <span class="math inline">\(W\)</span> is defined can have a strong effect on results, so if you don’t have a strong biologically motivated way to construct <span class="math inline">\(W\)</span> be sure to do some sensitivity analyses and determine which way of defining <span class="math inline">\(W\)</span> is best. The <code>spdep</code> packages has many ways to define connectivity and neighbor matrices (some examples: Delaunay triangulation, <span class="math inline">\(k\)</span>-nearest neighbors, minimum spanning tree, neighbors within <span class="math inline">\(d\)</span> distance)</p>
<ol start="2" style="list-style-type: decimal">
<li>Compute a PCoA without the square root standardization to create spatial eigenvectors from the most positively autocorrelated to the most negatively autocorrelated.</li>
</ol></li>
</ul>
<ol start="2" style="list-style-type: decimal">
<li>Test spatial eigenvectors for significant autocorrelation using Moran’s I (see below).</li>
<li>Model <span class="math inline">\(Y \sim \text{spatial eigenvectors}\)</span> using linear models or canonical ordination to determine the scales at which <span class="math inline">\(Y\)</span> has spatial structure. Some propose using spatial eigenvectors to “control” for spatial autocorrelation (what do you think?), but different authors find that this may work well or poorly.</li>
</ol>
</div>
<div id="approach-2-multiscale-ordination-mso" class="section level4">
<h4>Approach 2: Multiscale Ordination (MSO)</h4>
<ol style="list-style-type: decimal">
<li>Conduct a canonical ordination (RDA) that partitions <span class="math inline">\(Y\)</span> into fitted values explained by the covariates and residual values not explained by covariates.</li>
<li>Calculate a variogram matrix of the fitted values that shows how the fitted values covary across sites for each distance class. Plot the empirical variogram of this matrix to see the spatial structure of fitted values (e.g. spatial structure related to covariates).</li>
<li>Calculate a variogram matrix of the residual values that shows how residuals covary across sites for each distance class. Plot the empirical variogram of this matrix to see the spatial structure of residuals (e.g. spatial structure not related to covariates).</li>
</ol>
</div>
<div id="correlograms" class="section level4">
<h4>Correlograms</h4>
<ul>
<li>Correlograms are used to assess spatial autocorrelation at different spatial scales.</li>
<li>Correlograms plot the correlation between observations as a function of the distance between them.</li>
<li>Several statistics are used in correlograms: Moran’s I, Geary’s c, and the Mantel statistic.</li>
<li>We can calculate whether data are significantly autocorrelated at a given spatial scale by comparing the observed value of a statistic to its expected value. It is usually better to use permutations to test in case normality is violated.</li>
<li>If testing multiple distance classes, p-values should be adjusted for multiple tests (e.g. Holm’s or Bonferroni correction).</li>
<li>We can only test for significance if data are stationary: there is not trend in the mean or the spatial covariance across the spatial extent of the data. If there is a trend, we can try “detrending” by modeling the data as a function of the site-coordinates and then testing the residuals.</li>
</ul>
</div>
<div id="other-resources" class="section level4">
<h4>Other resources</h4>
<p>A list of papers that might be useful:</p>
<ul>
<li><p>Legendre and Gauthier 2014. Statistical methods for temporal and space–time analysis of community composition. Proc. R. Soc. B. DOI: <a href="http://dx.doi.org/10.1098/rspb.2013.2728">10.1098/rspb.2013.2728</a></p></li>
<li><p>Wagner 2013. Rethinking the linear regression model for spatial ecological data. Ecology. DOI: <a href="http://dx.doi.org/10.1890/12-1899.1">10.1890/12-1899.1</a> Describes a method called “spatial component regression”.</p></li>
</ul>
</div>
</div>
<div id="analysis-example" class="section level3">
<h3>Analysis Example</h3>
<p>First, let’s get the data:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><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>(adespatial)</code></pre></div>
<pre><code>## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'
## Warning: namespace 'DBI' is not available and has been replaced
## by .GlobalEnv when processing object 'call.'</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ade4)</code></pre></div>
<pre><code>##
## Attaching package: 'ade4'</code></pre>
<pre><code>## The following object is masked from 'package:adespatial':
##
## multispati</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">source</span>(<span class="st">"sr.value.R"</span>) <span class="co"># from https://raw.githubusercontent.com/JoeyBernhardt/NumericalEcology/master/sr.value.R</span>
<span class="co"># Data converted to semi-quantitative</span>
data <-<span class="st"> </span><span class="kw">cbind</span>(<span class="kw">c</span>(<span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">30</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">76</span>, <span class="dv">3</span>, <span class="dv">76</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">75</span>, <span class="dv">76</span>, <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>), <span class="kw">c</span>(<span class="dv">75</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">30</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">75</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">75</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">100</span>, <span class="dv">75</span>, <span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>), <span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">30</span>, <span class="dv">0</span>, <span class="dv">75</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>), <span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">75</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">75</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">77</span>, <span class="dv">75</span>, <span class="dv">75</span>, <span class="dv">75</span>, <span class="dv">2</span>, <span class="dv">100</span>, <span class="dv">2</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">30</span>, <span class="dv">30</span>, <span class="dv">77</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">77</span>, <span class="dv">100</span>, <span class="dv">75</span>, <span class="dv">77</span>, <span class="dv">31</span>, <span class="dv">0</span>, <span class="dv">30</span>, <span class="dv">76</span>, <span class="dv">30</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">100</span>, <span class="dv">77</span>, <span class="dv">2</span>, <span class="dv">76</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">100</span>, <span class="dv">30</span>, <span class="dv">1</span>), <span class="kw">c</span>(<span class="dv">75</span>, <span class="dv">75</span>, <span class="dv">100</span>, <span class="dv">75</span>, <span class="dv">0</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">30</span>, <span class="dv">75</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">30</span>, <span class="dv">30</span>, <span class="dv">100</span>, <span class="dv">75</span>, <span class="dv">30</span>, <span class="dv">75</span>, <span class="dv">30</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">75</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">30</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">75</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">76</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">77</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>))
<span class="kw">colnames</span>(data) <-<span class="st"> </span><span class="kw">c</span>(<span class="st">"pt"</span>, <span class="st">"sp"</span>, <span class="st">"co"</span>, <span class="st">"ly"</span>, <span class="st">"fe"</span>) <span class="co"># clades</span>
<span class="co"># vector indicating distance from river</span>
riv.dist <-<span class="st"> </span><span class="kw">c</span>(<span class="kw">seq</span>(<span class="dv">35</span>,<span class="dv">1</span>),<span class="kw">seq</span>(<span class="dv">1</span>,<span class="dv">20</span>))
<span class="co"># vector indicating point along transect</span>
trans.dist <-<span class="st"> </span><span class="kw">seq</span>(<span class="dv">1</span>,<span class="kw">nrow</span>(data),<span class="dv">1</span>)</code></pre></div>
<div id="two-naive-examples-using-spatial-data-but-no-autocorrelation" class="section level4">
<h4>Two naive examples, using spatial data but no autocorrelation</h4>
<p>Now, we can do an RDA using distance from the river, or distance along the transect, as a possible explanatory variable. First, distance from the river:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">riv.rda <-<span class="st"> </span><span class="kw">rda</span>(data,riv.dist)
<span class="kw">summary</span>(riv.rda)</code></pre></div>
<pre><code>##
## Call:
## rda(X = data, Y = riv.dist)
##
## Partitioning of variance:
## Inertia Proportion
## Total 5939.8 1.0000
## Constrained 606.8 0.1022
## Unconstrained 5333.0 0.8978
##
## Eigenvalues, and their contribution to the variance
##
## Importance of components:
## RDA1 PC1 PC2 PC3 PC4
## Eigenvalue 606.8149 2893.2107 1309.1388 566.22028 459.45026
## Proportion Explained 0.1022 0.4871 0.2204 0.09533 0.07735
## Cumulative Proportion 0.1022 0.5893 0.8096 0.90498 0.98233
## PC5
## Eigenvalue 104.94684
## Proportion Explained 0.01767
## Cumulative Proportion 1.00000
##
## Accumulated constrained eigenvalues
## Importance of components:
## RDA1
## Eigenvalue 606.8
## Proportion Explained 1.0
## Cumulative Proportion 1.0
##
## 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: 23.79803
##
##
## Species scores
##
## RDA1 PC1 PC2 PC3 PC4 PC5
## pt 7.461522 -3.8399 6.2365 -4.7412 3.0844 0.11915
## sp -0.602733 -1.6925 -1.7844 -4.7018 -4.9289 -0.02402
## co 0.737645 0.2319 0.5707 0.3657 -0.4354 3.14807
## ly -1.129948 11.3183 -5.4668 -2.9741 2.3755 0.18828
## fe 0.009609 -11.4059 -7.2481 -0.6500 2.0414 0.21429
##
##
## Site scores (weighted sums of species scores)
##
## RDA1 PC1 PC2 PC3 PC4 PC5
## sit1 -2.393 -4.0862 1.33792 -5.523906 -6.5964 0.73325
## sit2 -3.076 -0.4994 -1.02133 -2.942616 5.7314 2.22260
## sit3 -1.736 -4.5469 0.61506 1.157042 2.5815 1.23294
## sit4 -2.053 -3.6478 1.49117 -0.973518 -2.1364 0.52364
## sit5 -3.218 2.7639 2.84361 -1.408341 1.6333 0.29883
## sit6 -1.627 -4.3713 0.18115 1.557633 2.1734 0.95794
## sit7 -1.736 -4.3489 0.02830 1.881708 1.8712 0.82531
## sit8 -3.257 2.9944 2.31594 -0.975018 1.2091 0.03074
## sit9 -3.218 2.9618 2.25684 -0.683674 0.9230 -0.10879
## sit10 -3.218 3.0113 2.11015 -0.502507 0.7455 -0.21070
## sit11 -3.218 3.0608 1.96346 -0.321341 0.5679 -0.31261
## sit12 -1.792 0.1152 5.01388 3.881304 -3.5681 -1.78811
## sit13 -3.701 2.9451 -1.16681 -1.697408 2.9664 0.59644
## sit14 -2.561 -3.3470 -0.70661 -3.191097 -8.8668 -0.56581
## sit15 -3.706 4.2845 0.28180 -0.973893 1.2133 -0.24983
## sit16 -3.706 4.3339 0.13511 -0.792726 1.0357 -0.35174
## sit17 -3.706 4.3834 -0.01158 -0.611560 0.8581 -0.45364
## sit18 -2.076 0.2926 1.26539 2.888998 -1.5764 -1.20642
## sit19 -2.321 0.3708 1.02334 3.252578 -1.9047 -1.01754
## sit20 -3.240 -0.5464 -5.25098 -0.004959 3.7382 0.94938
## sit21 -3.565 1.4665 -4.90335 -0.877668 3.7132 0.75677
## sit22 -3.701 3.3904 -2.48702 -0.066908 1.3683 -0.32072
## sit23 -3.694 1.5793 -5.24670 -0.427515 3.2877 0.54105
## sit24 -3.701 3.4894 -2.78040 0.295425 1.0131 -0.52454
## sit25 -3.706 4.7793 -1.18510 0.837774 -0.5624 -1.26890
## sit26 -3.706 4.8288 -1.33179 1.018940 -0.7400 -1.37080
## sit27 -3.244 0.8336 -4.82615 1.564193 1.3302 -0.29935
## sit28 -3.706 4.9277 -1.62518 1.381274 -1.0951 -1.57462
## sit29 -3.218 3.9515 -0.67697 2.939659 -2.6283 -2.14693
## sit30 -3.257 4.0830 -0.91125 3.010648 -2.6975 -2.21121
## sit31 10.925 -0.3620 4.34809 -3.214045 2.7712 8.09263
## sit32 11.143 -0.3692 7.16391 -1.167158 -0.1871 -2.67313
## sit33 2.486 1.9486 2.54886 4.016760 -4.4119 20.55116
## sit34 9.659 2.8479 3.54203 -4.991569 3.5789 -1.44691
## sit35 10.570 -2.0909 1.05499 -3.179275 4.4019 -0.80823
## sit36 11.124 -0.1797 6.68005 -0.678747 -0.6656 -2.96004
## sit37 11.143 -0.2703 6.87053 -0.804824 -0.5423 -2.87695
## sit38 10.355 -3.8812 1.48825 -8.487854 -5.2074 -1.30870
## sit39 11.149 -4.5100 1.34299 -2.458189 4.3603 -0.53402
## sit40 8.054 -4.2254 0.29058 -0.531682 2.8481 -0.71789
## sit41 -1.409 -3.1828 -3.31188 5.500724 -2.1182 -1.44999
## sit42 8.057 -4.3297 0.57423 -0.974332 3.0807 -0.20187
## sit43 -1.607 -3.3237 -3.00224 5.598388 -1.7873 -1.30283
## sit44 -1.736 -3.3593 -2.90551 5.505041 -1.6802 -1.21283
## sit45 7.936 -4.4527 0.98836 -1.262605 3.7780 -0.21786
## sit46 8.065 -4.5162 1.18501 -1.531591 4.0260 -0.10405
## sit47 -4.735 0.9326 -6.93903 -8.979466 -8.0480 0.24193
## sit48 -3.893 -0.8721 -6.71322 -6.081058 -5.1626 0.47553
## sit49 -1.786 -3.5308 -2.27395 4.401940 -0.7964 -0.66806
## sit50 -3.241 -0.5502 -5.38246 0.057116 3.2813 0.82385
## sit51 -1.647 -3.6375 -1.91631 4.038878 -0.2583 -0.44994
## sit52 -1.736 -3.7551 -1.73199 4.055708 -0.2596 -0.39757
## sit53 -3.706 4.4329 -0.15827 -0.430393 0.6806 -0.55555
## sit54 -2.339 1.5114 3.05414 3.244653 -2.9376 -1.77078
## sit55 -1.773 0.2721 4.47092 4.661060 -4.3326 -2.21455
##
##
## Site constraints (linear combinations of constraining variables)
##
## RDA1 PC1 PC2 PC3 PC4 PC5
## con1 -6.67215 -4.0862 1.33792 -5.523906 -6.5964 0.73325
## con2 -6.33393 -0.4994 -1.02133 -2.942616 5.7314 2.22260
## con3 -5.99571 -4.5469 0.61506 1.157042 2.5815 1.23294
## con4 -5.65749 -3.6478 1.49117 -0.973518 -2.1364 0.52364
## con5 -5.31927 2.7639 2.84361 -1.408341 1.6333 0.29883
## con6 -4.98105 -4.3713 0.18115 1.557633 2.1734 0.95794
## con7 -4.64283 -4.3489 0.02830 1.881708 1.8712 0.82531
## con8 -4.30461 2.9944 2.31594 -0.975018 1.2091 0.03074
## con9 -3.96639 2.9618 2.25684 -0.683674 0.9230 -0.10879
## con10 -3.62817 3.0113 2.11015 -0.502507 0.7455 -0.21070
## con11 -3.28995 3.0608 1.96346 -0.321341 0.5679 -0.31261
## con12 -2.95173 0.1152 5.01388 3.881304 -3.5681 -1.78811
## con13 -2.61351 2.9451 -1.16681 -1.697408 2.9664 0.59644
## con14 -2.27529 -3.3470 -0.70661 -3.191097 -8.8668 -0.56581
## con15 -1.93708 4.2845 0.28180 -0.973893 1.2133 -0.24983
## con16 -1.59886 4.3339 0.13511 -0.792726 1.0357 -0.35174
## con17 -1.26064 4.3834 -0.01158 -0.611560 0.8581 -0.45364
## con18 -0.92242 0.2926 1.26539 2.888998 -1.5764 -1.20642
## con19 -0.58420 0.3708 1.02334 3.252578 -1.9047 -1.01754
## con20 -0.24598 -0.5464 -5.25098 -0.004959 3.7382 0.94938
## con21 0.09224 1.4665 -4.90335 -0.877668 3.7132 0.75677
## con22 0.43046 3.3904 -2.48702 -0.066908 1.3683 -0.32072
## con23 0.76868 1.5793 -5.24670 -0.427515 3.2877 0.54105
## con24 1.10690 3.4894 -2.78040 0.295425 1.0131 -0.52454
## con25 1.44512 4.7793 -1.18510 0.837774 -0.5624 -1.26890
## con26 1.78334 4.8288 -1.33179 1.018940 -0.7400 -1.37080
## con27 2.12156 0.8336 -4.82615 1.564193 1.3302 -0.29935
## con28 2.45978 4.9277 -1.62518 1.381274 -1.0951 -1.57462
## con29 2.79800 3.9515 -0.67697 2.939659 -2.6283 -2.14693
## con30 3.13622 4.0830 -0.91125 3.010648 -2.6975 -2.21121
## con31 3.47444 -0.3620 4.34809 -3.214045 2.7712 8.09263
## con32 3.81266 -0.3692 7.16391 -1.167158 -0.1871 -2.67313
## con33 4.15088 1.9486 2.54886 4.016760 -4.4119 20.55116
## con34 4.48909 2.8479 3.54203 -4.991569 3.5789 -1.44691
## con35 4.82731 -2.0909 1.05499 -3.179275 4.4019 -0.80823
## con36 4.82731 -0.1797 6.68005 -0.678747 -0.6656 -2.96004
## con37 4.48909 -0.2703 6.87053 -0.804824 -0.5423 -2.87695
## con38 4.15088 -3.8812 1.48825 -8.487854 -5.2074 -1.30870
## con39 3.81266 -4.5100 1.34299 -2.458189 4.3603 -0.53402
## con40 3.47444 -4.2254 0.29058 -0.531682 2.8481 -0.71789
## con41 3.13622 -3.1828 -3.31188 5.500724 -2.1182 -1.44999
## con42 2.79800 -4.3297 0.57423 -0.974332 3.0807 -0.20187
## con43 2.45978 -3.3237 -3.00224 5.598388 -1.7873 -1.30283
## con44 2.12156 -3.3593 -2.90551 5.505041 -1.6802 -1.21283
## con45 1.78334 -4.4527 0.98836 -1.262605 3.7780 -0.21786
## con46 1.44512 -4.5162 1.18501 -1.531591 4.0260 -0.10405
## con47 1.10690 0.9326 -6.93903 -8.979466 -8.0480 0.24193
## con48 0.76868 -0.8721 -6.71322 -6.081058 -5.1626 0.47553
## con49 0.43046 -3.5308 -2.27395 4.401940 -0.7964 -0.66806
## con50 0.09224 -0.5502 -5.38246 0.057116 3.2813 0.82385
## con51 -0.24598 -3.6375 -1.91631 4.038878 -0.2583 -0.44994
## con52 -0.58420 -3.7551 -1.73199 4.055708 -0.2596 -0.39757
## con53 -0.92242 4.4329 -0.15827 -0.430393 0.6806 -0.55555
## con54 -1.26064 1.5114 3.05414 3.244653 -2.9376 -1.77078
## con55 -1.59886 0.2721 4.47092 4.661060 -4.3326 -2.21455
##
##
## Biplot scores for constraining variables
##
## RDA1 PC1 PC2 PC3 PC4 PC5
## bip1 -1 0 0 0 0 0</code></pre>
<p>The RDA explains very little of the variance. Now, we can try distance along the transect:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">trans.rda <-<span class="st"> </span><span class="kw">rda</span>(data,trans.dist)
<span class="kw">summary</span>(trans.rda)</code></pre></div>
<pre><code>##
## Call:
## rda(X = data, Y = trans.dist)
##
## Partitioning of variance:
## Inertia Proportion
## Total 5939.8 1.00000
## Constrained 352.9 0.05941
## Unconstrained 5586.9 0.94059
##
## Eigenvalues, and their contribution to the variance
##
## Importance of components:
## RDA1 PC1 PC2 PC3 PC4
## Eigenvalue 352.90119 2679.1055 1593.7619 711.5639 492.82768
## Proportion Explained 0.05941 0.4510 0.2683 0.1198 0.08297
## Cumulative Proportion 0.05941 0.5105 0.7788 0.8986 0.98154
## PC5
## Eigenvalue 109.62157
## Proportion Explained 0.01846
## Cumulative Proportion 1.00000
##
## Accumulated constrained eigenvalues
## Importance of components:
## RDA1
## Eigenvalue 352.9
## Proportion Explained 1.0
## Cumulative Proportion 1.0
##
## 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: 23.79803
##
##
## Species scores
##
## RDA1 PC1 PC2 PC3 PC4 PC5
## pt 3.7706 -4.1971 9.1655 5.0135 0.5828 -0.07387
## sp 0.1774 -1.5634 -1.8156 2.2245 -6.4879 0.01356
## co 0.1678 0.1591 0.7869 -0.2799 -0.1113 3.22393
## ly -3.1127 11.0362 -3.6563 5.2684 1.0794 0.11785
## fe 3.1117 -10.6566 -7.1183 3.1509 1.8385 0.19729
##
##
## Site scores (weighted sums of species scores)
##
## RDA1 PC1 PC2 PC3 PC4 PC5
## sit1 4.806093 -4.9531 -1.34340 -0.4852 -9.076e+00 -0.10256
## sit2 -2.527394 -1.1876 -2.28327 2.8419 2.987e+00 0.63585
## sit3 6.610543 -5.3882 -1.74148 -1.9326 2.216e+00 0.25929
## sit4 4.456799 -4.4628 -0.96024 -2.1477 -2.919e+00 -0.18358
## sit5 -9.575158 2.1561 1.07543 -0.8284 -3.073e-03 -0.80247
## sit6 6.630093 -5.1630 -1.79941 -1.8941 2.207e+00 0.23380
## sit7 6.610543 -5.1237 -1.86706 -2.0834 2.157e+00 0.21970
## sit8 -9.760174 2.4409 0.93313 -0.7862 -8.666e-04 -0.80961
## sit9 -9.575158 2.4206 0.94986 -0.9792 -6.139e-02 -0.84206
## sit10 -9.575158 2.4868 0.91846 -1.0169 -7.596e-02 -0.85195
## sit11 -9.575158 2.5529 0.88707 -1.0546 -9.054e-02 -0.86185
## sit12 -2.822081 -0.5348 2.61212 -6.7609 -1.782e+00 -1.69483
## sit13 -9.113573 2.5138 -1.18252 2.2045 1.628e+00 -0.03349
## sit14 4.509020 -3.9903 -1.85996 -0.8941 -9.232e+00 -0.20161
## sit15 -11.887855 3.8976 0.15997 0.7358 4.254e-01 -0.61957
## sit16 -11.887855 3.9638 0.12858 0.6981 4.108e-01 -0.62946
## sit17 -11.887855 4.0299 0.09719 0.6604 3.962e-01 -0.63936
## sit18 -2.413905 -0.2126 0.46540 -3.2719 -2.770e-02 -0.88637
## sit19 -2.633034 -0.1130 0.31856 -3.4615 -6.945e-02 -0.57369
## sit20 -0.512565 -0.9371 -4.12787 3.4055 3.737e+00 0.95921
## sit21 -4.840092 1.1493 -3.48128 4.0666 3.285e+00 0.72967
## sit22 -9.113573 3.1091 -1.46507 1.8651 1.497e+00 -0.12257
## sit23 -4.952149 1.2980 -3.60438 3.9173 3.243e+00 0.71694
## sit24 -9.113573 3.2414 -1.52785 1.7897 1.468e+00 -0.14237
## sit25 -11.887855 4.5591 -0.15397 0.3587 2.796e-01 -0.71854
## sit26 -11.887855 4.6252 -0.18536 0.3210 2.650e-01 -0.72844
## sit27 -2.824467 0.5689 -3.17656 1.9805 2.657e+00 0.41803
## sit28 -11.887855 4.7575 -0.24815 0.2456 2.359e-01 -0.74824
## sit29 -9.575158 3.7436 0.32198 -1.7334 -3.529e-01 -1.04001
## sit30 -9.760174 3.8961 0.24246 -1.6158 -3.216e-01 -1.02736
## sit31 8.624789 -0.9010 6.09941 3.4335 9.501e-01 7.55698
## sit32 8.568686 -0.9413 8.06383 -0.2809 -8.792e-01 -2.62209
## sit33 -1.676663 1.6178 3.47697 -3.4711 -1.251e+00 21.33440
## sit34 1.538085 2.4745 6.17242 5.5452 8.374e-01 -1.78498
## sit35 12.729155 -2.5756 3.73462 5.4187 2.701e+00 -0.89784
## sit36 8.476178 -0.6335 7.91419 -0.3541 -9.146e-01 -2.65040
## sit37 8.568686 -0.6106 7.90686 -0.4695 -9.521e-01 -2.67158
## sit38 15.899754 -4.1308 3.39528 5.5592 -8.325e+00 -1.13831
## sit39 17.821566 -4.6561 3.14785 4.1322 2.793e+00 -0.80249
## sit40 15.132186 -4.1957 1.66891 2.3210 2.481e+00 -0.64276
## sit41 6.772244 -2.8498 -2.82553 -2.9230 1.469e+00 -0.11288
## sit42 15.142443 -4.0689 1.59935 2.2742 2.311e+00 -0.35282
## sit43 6.722601 -2.7588 -2.93693 -3.3671 1.645e+00 -0.14369
## sit44 6.610543 -2.6762 -3.02864 -3.4787 1.618e+00 -0.14652
## sit45 15.014856 -3.8424 1.46357 2.0257 2.534e+00 -0.68648
## sit46 15.126914 -3.7927 1.49249 2.0619 2.532e+00 -0.70345
## sit47 -4.240005 2.1900 -5.64630 6.3839 -1.084e+01 0.64692
## sit48 -0.005114 0.4396 -5.84267 4.8826 -7.014e+00 0.77233
## sit49 6.430799 -2.2652 -3.24568 -3.4792 1.453e+00 -0.17216
## sit50 -0.409514 0.9919 -5.06952 2.2621 3.000e+00 0.65359
## sit51 6.537585 -2.1432 -3.23620 -3.5135 1.574e+00 -0.20032
## sit52 6.610543 -2.1471 -3.27979 -3.7804 1.501e+00 -0.22570
## sit53 -11.887855 6.4112 -1.03300 -0.6972 -1.286e-01 -0.99568
## sit54 -5.412302 3.4531 0.61987 -6.1705 -1.751e+00 -1.79484
## sit55 -2.729573 2.2663 1.28624 -8.4601 -2.432e+00 -2.13171
##
##
## Site constraints (linear combinations of constraining variables)
##
## RDA1 PC1 PC2 PC3 PC4 PC5
## con1 -5.4579 -4.9531 -1.34340 -0.4852 -9.076e+00 -0.10256
## con2 -5.2557 -1.1876 -2.28327 2.8419 2.987e+00 0.63585
## con3 -5.0536 -5.3882 -1.74148 -1.9326 2.216e+00 0.25929
## con4 -4.8514 -4.4628 -0.96024 -2.1477 -2.919e+00 -0.18358
## con5 -4.6493 2.1561 1.07543 -0.8284 -3.073e-03 -0.80247
## con6 -4.4472 -5.1630 -1.79941 -1.8941 2.207e+00 0.23380
## con7 -4.2450 -5.1237 -1.86706 -2.0834 2.157e+00 0.21970
## con8 -4.0429 2.4409 0.93313 -0.7862 -8.666e-04 -0.80961
## con9 -3.8407 2.4206 0.94986 -0.9792 -6.139e-02 -0.84206
## con10 -3.6386 2.4868 0.91846 -1.0169 -7.596e-02 -0.85195
## con11 -3.4364 2.5529 0.88707 -1.0546 -9.054e-02 -0.86185
## con12 -3.2343 -0.5348 2.61212 -6.7609 -1.782e+00 -1.69483
## con13 -3.0322 2.5138 -1.18252 2.2045 1.628e+00 -0.03349
## con14 -2.8300 -3.9903 -1.85996 -0.8941 -9.232e+00 -0.20161
## con15 -2.6279 3.8976 0.15997 0.7358 4.254e-01 -0.61957
## con16 -2.4257 3.9638 0.12858 0.6981 4.108e-01 -0.62946
## con17 -2.2236 4.0299 0.09719 0.6604 3.962e-01 -0.63936
## con18 -2.0214 -0.2126 0.46540 -3.2719 -2.770e-02 -0.88637
## con19 -1.8193 -0.1130 0.31856 -3.4615 -6.945e-02 -0.57369
## con20 -1.6171 -0.9371 -4.12787 3.4055 3.737e+00 0.95921
## con21 -1.4150 1.1493 -3.48128 4.0666 3.285e+00 0.72967
## con22 -1.2129 3.1091 -1.46507 1.8651 1.497e+00 -0.12257
## con23 -1.0107 1.2980 -3.60438 3.9173 3.243e+00 0.71694
## con24 -0.8086 3.2414 -1.52785 1.7897 1.468e+00 -0.14237
## con25 -0.6064 4.5591 -0.15397 0.3587 2.796e-01 -0.71854
## con26 -0.4043 4.6252 -0.18536 0.3210 2.650e-01 -0.72844
## con27 -0.2021 0.5689 -3.17656 1.9805 2.657e+00 0.41803
## con28 0.0000 4.7575 -0.24815 0.2456 2.359e-01 -0.74824
## con29 0.2021 3.7436 0.32198 -1.7334 -3.529e-01 -1.04001
## con30 0.4043 3.8961 0.24246 -1.6158 -3.216e-01 -1.02736
## con31 0.6064 -0.9010 6.09941 3.4335 9.501e-01 7.55698
## con32 0.8086 -0.9413 8.06383 -0.2809 -8.792e-01 -2.62209
## con33 1.0107 1.6178 3.47697 -3.4711 -1.251e+00 21.33440
## con34 1.2129 2.4745 6.17242 5.5452 8.374e-01 -1.78498
## con35 1.4150 -2.5756 3.73462 5.4187 2.701e+00 -0.89784
## con36 1.6171 -0.6335 7.91419 -0.3541 -9.146e-01 -2.65040
## con37 1.8193 -0.6106 7.90686 -0.4695 -9.521e-01 -2.67158
## con38 2.0214 -4.1308 3.39528 5.5592 -8.325e+00 -1.13831
## con39 2.2236 -4.6561 3.14785 4.1322 2.793e+00 -0.80249
## con40 2.4257 -4.1957 1.66891 2.3210 2.481e+00 -0.64276
## con41 2.6279 -2.8498 -2.82553 -2.9230 1.469e+00 -0.11288
## con42 2.8300 -4.0689 1.59935 2.2742 2.311e+00 -0.35282
## con43 3.0322 -2.7588 -2.93693 -3.3671 1.645e+00 -0.14369
## con44 3.2343 -2.6762 -3.02864 -3.4787 1.618e+00 -0.14652
## con45 3.4364 -3.8424 1.46357 2.0257 2.534e+00 -0.68648
## con46 3.6386 -3.7927 1.49249 2.0619 2.532e+00 -0.70345
## con47 3.8407 2.1900 -5.64630 6.3839 -1.084e+01 0.64692
## con48 4.0429 0.4396 -5.84267 4.8826 -7.014e+00 0.77233
## con49 4.2450 -2.2652 -3.24568 -3.4792 1.453e+00 -0.17216
## con50 4.4472 0.9919 -5.06952 2.2621 3.000e+00 0.65359
## con51 4.6493 -2.1432 -3.23620 -3.5135 1.574e+00 -0.20032
## con52 4.8514 -2.1471 -3.27979 -3.7804 1.501e+00 -0.22570
## con53 5.0536 6.4112 -1.03300 -0.6972 -1.286e-01 -0.99568
## con54 5.2557 3.4531 0.61987 -6.1705 -1.751e+00 -1.79484
## con55 5.4579 2.2663 1.28624 -8.4601 -2.432e+00 -2.13171
##
##
## Biplot scores for constraining variables
##
## RDA1 PC1 PC2 PC3 PC4 PC5
## bip1 1 0 0 0 0 0</code></pre>
<p>This is even worse.</p>
<p>Now, for examples from this week’s reading:</p>
</div>
<div id="pcnmmem" class="section level4">
<h4>PCNM/MEM</h4>
<p>We will begin by looking at the locations only and calculating a PCoA based only on the distances between the locations. So we’re not looking at the actual occurrence data yet, just the locations where the data were taken from.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">trans.dm <-<span class="st"> </span><span class="kw">dist</span>(trans.dist) <span class="co"># create distance matrix</span>
thresh <-<span class="st"> </span><span class="dv">1</span> <span class="co"># truncation distance set to 1</span>
trans.dm[trans.dm ><span class="st"> </span>thresh] <-<span class="st"> </span><span class="dv">4</span> *<span class="st"> </span>thresh <span class="co"># truncation to threshold</span>
<span class="co"># Make the PCoA</span>
trans.pcoa <-<span class="st"> </span><span class="kw">cmdscale</span>(trans.dm, <span class="dt">eig=</span><span class="ot">TRUE</span>, <span class="dt">k=</span><span class="dv">54</span>) <span class="co"># this is the highest possible value of k in this case, see the textbook for other possibilities</span></code></pre></div>
<pre><code>## Warning in cmdscale(trans.dm, eig = TRUE, k = 54): only 38 of the first 54
## eigenvalues are > 0</code></pre>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Count the positive eigenvalues</span>
nb.ev <-<span class="st"> </span><span class="kw">length</span>(<span class="kw">which</span>(trans.pcoa$eig ><span class="st"> </span><span class="fl">0.0000000000001</span>))
<span class="co"># Matrix of PCNM variables</span>
trans.PCNM <-<span class="st"> </span><span class="kw">as.data.frame</span>(trans.pcoa$points[,<span class="dv">1</span>:nb.ev])
<span class="co"># Plot some of these</span>
<span class="kw">par</span>(<span class="dt">mfrow=</span><span class="kw">c</span>(<span class="dv">3</span>,<span class="dv">2</span>))
somePCNM <-<span class="st"> </span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">4</span>,<span class="dv">8</span>,<span class="dv">16</span>,<span class="dv">37</span>)
for(i in <span class="dv">1</span>:<span class="kw">length</span>(somePCNM)) {
<span class="kw">plot</span>(trans.PCNM[,somePCNM[i]],<span class="dt">type=</span><span class="st">"l"</span>,<span class="dt">ylab=</span><span class="kw">c</span>(<span class="st">"PCNM"</span>,somePCNM[i]))
}</code></pre></div>
<p><img src="images/08-C/unnamed-chunk-5-1.png" width="672" /></p>
<p>So, these are some of the possible autocorrleation patterns that we might expect to see in the data. We can now test these against the actual data.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Detrend the data</span>
trans.dist.x <-<span class="st"> </span><span class="kw">as.data.frame</span>(trans.dist) <span class="co"># need to make this a data frame in order to detrend</span>
data.D <-<span class="st"> </span><span class="kw">dist</span>(data)
data.det <-<span class="st"> </span><span class="kw">resid</span>(<span class="kw">lm</span>(<span class="kw">as.matrix</span>(data.D) ~<span class="st"> </span>., <span class="dt">data=</span>trans.dist.x))
<span class="co"># Run PCNM</span>
PCNM <-<span class="st"> </span><span class="kw">rda</span>(data.det,trans.PCNM)
<span class="kw">anova.cca</span>(PCNM)</code></pre></div>
<pre><code>## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 999
##
## Model: rda(X = data.det, Y = trans.PCNM)
## Df Variance F Pr(>F)
## Model 37 82321 2.5016 0.001 ***
## Residual 17 15120
## ---
## 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"># Compute adj R2, run forward selection of variables</span>
R2a <-<span class="st"> </span><span class="kw">RsquareAdj</span>(PCNM)$adj.r.squared
PCNM.fwd <-<span class="st"> </span><span class="kw">forward.sel</span>(data.det, <span class="kw">as.matrix</span>(trans.PCNM),<span class="dt">adjR2thresh=</span>R2a)</code></pre></div>
<pre><code>## Testing variable 1
## Testing variable 2
## Testing variable 3