-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtutorial_2.html
1164 lines (1045 loc) · 48.9 KB
/
tutorial_2.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>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Tutorial 2: Landscape-scale connectivity, matrix permeability and dispersal behaviour</title>
<script src="site_libs/header-attrs-2.23/header-attrs.js"></script>
<script src="site_libs/jquery-3.6.0/jquery-3.6.0.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>
<style>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;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="site_libs/jqueryui-1.13.2/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>
<link href="site_libs/highlightjs-9.12.0/textmate.css" rel="stylesheet" />
<script src="site_libs/highlightjs-9.12.0/highlight.js"></script>
<script src="site_libs/clipboard-1.7.1/clipboard.min.js"></script>
<link href="site_libs/primer-tooltips-1.4.0/build.css" rel="stylesheet" />
<link href="site_libs/klippy-0.0.0.9500/css/klippy.min.css" rel="stylesheet" />
<script src="site_libs/klippy-0.0.0.9500/js/klippy.min.js"></script>
<link href="site_libs/font-awesome-6.4.0/css/all.min.css" rel="stylesheet" />
<link href="site_libs/font-awesome-6.4.0/css/v4-shims.min.css" rel="stylesheet" />
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">code{white-space: pre;}</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<style type="text/css">
/* for pandoc --citeproc since 2.11 */
div.csl-bib-body { }
div.csl-entry {
clear: both;
}
.hanging div.csl-entry {
margin-left:2em;
text-indent:-2em;
}
div.csl-left-margin {
min-width:2em;
float:left;
}
div.csl-right-inline {
margin-left:2em;
padding-left:1em;
}
div.csl-indent {
margin-left: 2em;
}
</style>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<style type="text/css">
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #adb5bd;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</style>
<script type="text/javascript">
// 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 the anchor link active (and if it's in a dropdown, also mark that active)
var dropdown = menuAnchor.closest('li.dropdown');
if (window.bootstrap) { // Bootstrap 4+
menuAnchor.addClass('active');
dropdown.find('> .dropdown-toggle').addClass('active');
} else { // Bootstrap 3
menuAnchor.parent().addClass('active');
dropdown.addClass('active');
}
// Navbar adjustments
var navHeight = $(".navbar").first().height() + 15;
var style = document.createElement('style');
var pt = "padding-top: " + navHeight + "px; ";
var mt = "margin-top: -" + navHeight + "px; ";
var css = "";
// offset scroll position for anchor links (for fixed navbar)
for (var i = 1; i <= 6; i++) {
css += ".section h" + i + "{ " + pt + mt + "}\n";
}
style.innerHTML = "body {" + pt + "padding-bottom: 40px; }\n" + css;
document.head.appendChild(style);
});
</script>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "\e259";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "\e258";
font-family: 'Glyphicons Halflings';
border: none;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.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;
}
.tocify .list-group-item {
border-radius: 0px;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<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-bs-toggle="collapse" data-target="#navbar" data-bs-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">RangeShiftR tutorials</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">About RangeShiftR</a>
</li>
<li>
<a href="installing.html">Installing RangeShiftR</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
RangeShiftR tutorials
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="overview_0.html">0. General package introduction</a>
</li>
<li>
<a href="tutorial_1.html">1. Range expansion</a>
</li>
<li>
<a href="tutorial_2.html">2. Patch connectivity</a>
</li>
<li>
<a href="tutorial_3.html">3. Dynamic landscapes & SMS paths</a>
</li>
<li>
<a href="tutorial_4.html">4. Evolution of dispersal</a>
</li>
<li>
<a href="appendix_tutorial_3.html">Appendix A3. Create dynamic landscapes</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="mailto:[email protected]">
<span class="fa fa-envelope"></span>
</a>
</li>
<li>
<a href="https://rangeshifter.github.io">
<span class="fa fa-home"></span>
</a>
</li>
<li>
<a href="https://github.com/RangeShifter">
<span class="fa fa-github"></span>
</a>
</li>
<li>
<a href="https://twitter.com/ZurellLab">
<span class="fa fa-twitter"></span>
</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div id="header">
<h1 class="title toc-ignore">Tutorial 2: Landscape-scale connectivity,
matrix permeability and dispersal behaviour</h1>
</div>
<script>
addClassKlippyTo("pre.r, pre.markdown");
addKlippy('right', 'top', 'auto', '1', 'Copy code', 'Copied!');
</script>
<p>In this second example, <code>RangeShiftR</code> is used at the
landscape scale to model functional connectivity of a woodland network
for a hypothetical woodland species. The aims are:</p>
<ul>
<li>to illustrate how the platform can be used to investigate
connectivity issues as well as species spatial dynamics at local and
landscape scales;</li>
<li>to show how the platform can run a model as patch-based;</li>
<li>to show how additional complexity in the population dynamics and
dispersal behaviour can be incorporated;</li>
<li>and to show how the connectivity analyses can be dependent upon the
type of model and on the modelled dispersal behaviour.</li>
</ul>
<p>We want to reproduce Figure 3 of <span class="citation">Bocedi et al.
(2014)</span>. To this end, we run four different scenarios:</p>
<ol style="list-style-type: lower-alpha">
<li>Explicit sexual model. Constant per-step mortality probability of
<em>0.01</em>; individuals settle only if at least one individual of the
opposite sex is present in the patch (Figure 3b in the paper).</li>
<li>As in (a), but with different settlement rules. Females settle in
suitable patches, while males will settle only if at least one female is
present in the patch (Figure 3c in the paper).</li>
<li>Only-female model. Constant per-step mortality probability of
<em>0.01</em>; females settle in suitable patches (Figure 3d in the
paper).</li>
<li>As in (a), but with habitat-specific per-step mortality (Figure 3e
in the paper).</li>
</ol>
<p><span class="citation">Bocedi et al. (2014)</span> defined the
measures ‘final probability of occupancy’ and the ‘mean time to first
colonisation’ to illustrate the connectivity between the initial patch
and the rest of the woodland network. These measures allow rapidly
assessing the effects of landscape characteristics and species movement
abilities on connectivity and, importantly, also on the population
dynamics. Note that both measures represent multi-generation
connectivity.</p>
<div id="getting-started" class="section level1" number="1">
<h1><span class="header-section-number">1</span> Getting started</h1>
<div id="create-a-rs-directory" class="section level2" number="1.1">
<h2><span class="header-section-number">1.1</span> Create a RS
directory</h2>
<p>We need to set up the folder structure again with the three
sub-folders named ‘Inputs’, ‘Outputs’ and ‘Output_Maps’.</p>
<pre class="r"><code>library(RangeShiftR)
library(terra)
library(RColorBrewer)
library(viridis)
library(grid)
library(gridExtra)
# relative path from working directory:
dirpath = "Tutorial_02/"
dir.create(paste0(dirpath,"Inputs"), showWarnings = TRUE)
dir.create(paste0(dirpath,"Outputs"), showWarnings = TRUE)
dir.create(paste0(dirpath,"Output_Maps"), showWarnings = TRUE)</code></pre>
<p>Copy the input files provided for exercise 2 into the ‘Inputs’
folder. The files can be downloaded <a
href="files/Tutorial2_Inputs.zip">here</a>.</p>
</div>
<div id="landscape-parameters" class="section level2" number="1.2">
<h2><span class="header-section-number">1.2</span> Landscape
parameters</h2>
<p>We use a typical British lowland, agricultural landscape having small
fragments of woodland, as used by Forest Research, UK, in Watts et
al. (2010). The landscape map has an extent of <em>10km</em> by
<em>6km</em> and a resolution of <em>10m</em>. Land-covers were
aggregated into seven categories (Figure 3a in <span
class="citation">Bocedi et al. (2014)</span>). Similar to tutorial 1,
the map, <em>landscape_10m_batch.txt</em>, is a raster map with codes
for different land-cover types. Land-covers were aggregated into seven
categories which have to be given as sequential integer numbers,
starting from one:</p>
<ul>
<li>1 = semi-natural broad-leaved woodland</li>
<li>2 = planted/felled broad-leaved and mixed woodland, shrubs and
bracken</li>
<li>3 = heathland, marshy grassland</li>
<li>4 = unimproved grassland, mire</li>
<li>5 = planted/felled coniferous woodland, semi-improved grassland,
swamp</li>
<li>6 = improved grasslands, arable, water</li>
<li>7 = roads, buildings</li>
</ul>
<pre class="r"><code>landsc <- terra::rast(paste0(dirpath, "Inputs/landscape_10m_batch.txt"))
# Plot land cover map and highlight cells with initial species distribution - option 2 with categorical legend:
landsc.f <- as.factor(landsc)
# add the land cover classes to the raster attribute table
rat <- levels(landsc.f)[[1]][-2]
rat[["landcover"]] <- c("semi-natural broad-leaved woodland", "planted/felled broad-leaved and mixed woodland", "heathland, marshy grassland", "unimproved grassland", "planted/felled coniferous woodland", "improved grasslands, arable, water", "roads, buildings")
levels(landsc.f) <- rat
plot(landsc.f, axes = F, col=brewer.pal(n = 7, name = "Spectral"))</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-3-1.png" width="672" /></p>
<p>The second text file, <em>woodland_1ha_patchIDs.txt</em>, contains
the patch-matrix landscape. It has the same extent and resolution as the
land-type map, and each cell contains a unique patch ID that indicates
to which patch it belongs. Patch number <em>0</em> designates the matrix
patch, i.e. all unsuitable habitat.</p>
<pre class="r"><code>patch <- terra::rast(paste0(dirpath, "Inputs/woodland_1ha_patchIDs.txt"))
# We can have a glimpse at how many cells the different patches contain:
table(values(patch))</code></pre>
<pre><code>##
## 0 1 2 3 4 5 6 7 8 9 10
## 585734 287 232 243 996 240 238 181 141 990 162
## 11 12 13 14 15 16 17 18 19 20 21
## 221 311 207 594 694 118 137 172 245 361 423
## 22 23 24 25 26 27 28 29 30 31 32
## 349 145 1141 138 401 280 336 706 1919 249 154
## 33 34 35 36 37 38 39 40 41 42 43
## 166 524 215 1277 383 735 113 1008 447 125 100
## 44 45 46 47 48 49 50
## 547 116 225 675 189 110 301</code></pre>
<pre class="r"><code># Plot the patches in different colours:
plot(patch, axes=F, legend=F,
col = c('black',rep(brewer.pal(n = 12, name = "Paired"),5))
) </code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
<p>The last text file, <em>patch30.txt</em>, is a map that specifies the
patches that contain the initial distribution of the species. In our
case, this is only the patch with ID <em>30</em>.</p>
<pre class="r"><code>patch30 <- terra::rast(paste0(dirpath, "Inputs/patch30.txt"))
# Look at initial patch:
plot(patch30, type="continuous")</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-5-1.png" width="672" /></p>
<p>We are ready to set up the landscape parameter object with these
maps, their respective resolutions, and the demographic density
dependence for all land cover types. In contrast to tutorial 1, we will
use a stage-structured population model here (defined below), so that
the values in <code>K_or_DensDep</code> will be used as the parameter
<em>1/b</em> in the population dynamics (see
<code>?StageStructure</code>), describing the strength density
dependence (in fecundity, development and survival).</p>
<p>We choose to define only ‘semi-natural broad-leaved woodland’ (code
1) as suitable for our species.</p>
<pre class="r"><code>land <- ImportedLandscape(LandscapeFile = "landscape_10m_batch.txt",
PatchFile = "woodland_1ha_patchIDs.txt",
Resolution = 10,
Nhabitats = 7,
K_or_DensDep = c(10, rep(0,6)),
SpDistFile = "patch30.txt",
SpDistResolution = 10)</code></pre>
</div>
</div>
<div id="scenario-a-sexual-model-with-mate-finding"
class="section level1" number="2">
<h1><span class="header-section-number">2</span> Scenario a: sexual
model with mate finding</h1>
<div id="demographic-and-dispersal-parameters" class="section level2"
number="2.1">
<h2><span class="header-section-number">2.1</span> Demographic and
dispersal parameters</h2>
<p>We will simulate a sexual species with simple, two-staged structured
population dynamics. The parameters are chosen to be representative of
species having moderately high fecundity, high juvenile mortality and
low adult mortality. This is encoded in the following transition
matrix</p>
<pre class="r"><code>(trans_mat <- matrix(c(0, 1, 0, 0, 0.1, 0.4, 5, 0, 0.8), nrow = 3, byrow = F))</code></pre>
<pre><code>## [,1] [,2] [,3]
## [1,] 0 0.0 5.0
## [2,] 1 0.1 0.0
## [3,] 0 0.4 0.8</code></pre>
<p>The first row and column describe the juvenile stage, the others the
two adult stages. Juveniles will develop to the first adult stage at the
end of their first year with a probability of <em>1.0</em>, which allows
for juvenile dispersal before any mortality happens.</p>
<p>In order to add a stage-structure to our population dynamics, we use
the <code>StageStructure()</code> function within the demography module.
The reproduction type <em>1</em> denotes a simple sexual model,
i.e. mating is not explicitly modelled.</p>
<pre class="r"><code>stg <- StageStructure(Stages=3, # 1 juvenile + 2 adult stages
TransMatrix=trans_mat,
MaxAge=1000,
SurvSched=2,
FecDensDep=T)
demo <- Demography(StageStruct = stg,
ReproductionType = 1) # simple sexual model</code></pre>
<p>After reproduction, we allow only juveniles to disperse, and define a
density-dependent emigration probability. To do so, we enable the
options <code>DensDep=T</code> and <code>StageDep=T</code>, and in the
matrix <code>EmigProb</code> we set the parameters D<sub>0</sub> =
<em>0.5</em>, α = <em>10.0</em> and β = <em>1.0</em> for juveniles and
to zero for all adult stages.</p>
<p>To account for functional connectivity, we use a mechanistic movement
model which enables individuals to interact with the landscape and
determine their path according to what they can perceive in the
landscape. Therefore we will simulate movements with a stochastic
movement simulator (<code>SMS()</code>) where individuals move stepwise
(each step goes from one cell to a neighbouring cell) and the direction
chosen at each step is determined by the land cover costs (specified for
each land type), the species’ perceptual range (<code>PR</code>) and
directional persistence (<code>DP</code>). We set these parameters so
that individuals have a perceptual range of <em>50m</em>, use the
arithmetic mean method (the default) for calculating effective cost
(which tends to emphasise the avoidance of high-cost landscape
features), and tend to follow highly correlated paths within the
landscape. We also set a constant per-step mortality probability
(<code>StepMort</code>).</p>
<p>Once arrived in a new patch, an individual decides to settle or not
based on certain settlement rules. Finding suitable habitat is a
necessary condition in all cases. Additionally, we set mate availability
as requirement, i.e. there has to be at least one individual of the
opposite sex present in the patch to be considered suitable for
settlement.</p>
<pre class="r"><code>disp <- Dispersal(Emigration = Emigration(DensDep=T, StageDep=T,
EmigProb = cbind(0:2,c(0.5,0,0),c(10.0,0,0),c(1.0,0,0)) ),
Transfer = SMS(PR=5, DP=10, Costs = c(1,1,3,5,10,20,50), StepMort = 0.01),
Settlement = Settlement(FindMate = T) )</code></pre>
<p>We can visualise the defined processes by plotting some of the rates
and probabilities that we have parameterised:</p>
<pre class="r"><code>par(mfrow=c(1,2))
plotProbs(demo@StageStruct)
plotProbs(disp@Emigration)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-10-1.png" width="672" /></p>
</div>
<div id="initialisation-simulation" class="section level2" number="2.2">
<h2><span class="header-section-number">2.2</span> Initialisation &
simulation</h2>
<p>We choose to initialise our simulation in all initial patches
(specified in initial distribution map; in our case only patch
#<em>30</em>) at a density of <em>10</em> individuals per hectare, with
an equal number of individuals in stages 1 and 2 at their respective
minimum age.</p>
<pre class="r"><code># Population is initialised in Patch 30:
init <- Initialise(InitType = 1, # from loaded species distribution map
SpType = 0, # all suitable cells
InitDens = 2, # user-specified density
IndsHaCell = 10,
PropStages = c(0,0.5,0.5),
InitAge = 0)</code></pre>
<p>We set the simulation time to <em>100</em> years and <em>20</em>
replicates, and set the output types to write the files for population,
occupancy and range data every year.</p>
<pre class="r"><code>sim <- Simulation(Simulation = 0,
Replicates = 20,
Years = 100,
OutIntPop = 1,
OutIntOcc = 1,
OutIntRange = 1)</code></pre>
<p>As before, we need to stitch all modules together to a parameter
master. Within <code>RSsim()</code>, we can also set a seed for the
random number generator to make our results reproducible:</p>
<pre class="r"><code>s <- RSsim(batchnum = 3, land = land, demog = demo, dispersal = disp, simul = sim, init = init, seed = 324135)</code></pre>
<p>Run the simulation:</p>
<pre class="r"><code>RunRS(s, dirpath)</code></pre>
</div>
<div id="analyse-output" class="section level2" number="2.3">
<h2><span class="header-section-number">2.3</span> Analyse output</h2>
<p>To analyse the simulation output, we first plot the meta-population
results. Note here that - in contrast to the cell-based model from
exercise 1 - the plotted occupancy refers to occupied patches rather
than cells.</p>
<pre class="r"><code>par(mfrow=c(1,2))
plotAbundance(s, dirpath)
plotOccupancy(s, dirpath)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-15-1.png" width="672" /></p>
<p>In order to create occupancy maps, we first plot the landscape with
the suitable patches in green and the initial patch in red. This color
scheme was also used in Fig. 3a of <span class="citation">Bocedi et al.
(2014)</span>.</p>
<pre class="r"><code># We have initiated the population in the patch with ID=30. We highlight this in the map.
values(patch30)[values(patch30)<1] <- NA
values(patch)[values(patch)<1] <- NA
plot(landsc, axes=F,breaks=seq(.5,7.5,by=1),
col = rev(brewer.pal(n = 7, name = "Greys") ), legend=F)
plot(patch, axes=F, col="green4", legend=F, add=T)
plot(as.polygons(patch30, dissolve=T), col=NA, border='red',lwd=2, add=T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-16-1.png" width="672" /></p>
<pre class="r"><code># Store underlying landscape map display for later:
bg <- function(main=NULL){
plot(landsc, axes=F, breaks=seq(.5,7.5,by=1), legend=F,
col = rev(brewer.pal(n = 7, name = "Greys") ), main=ifelse(is.null(main),"",main))
}
# as well as the extent of the landscape:
e <- ext(landsc)</code></pre>
<p>To reproduce Fig. 3b of <span class="citation">Bocedi et al.
(2014)</span>, we map the mean occupancy probability for each patch in
year <em>100</em> (left panel in the paper) as well as the mean time to
colonisation (right panel), both calculated over the <em>20</em>
replicates. We can use the built-in function
<code>ColonisationStats()</code> for this. It calculates the mean
occupancy probability of given years as well as the time to colonisation
for all replicates:</p>
<pre class="r"><code>col_stats_a <- ColonisationStats(s, dirpath, years = 100, maps = T)</code></pre>
<pre><code>## Warning: [rast] the first raster was empty and was ignored</code></pre>
<pre class="r"><code># mean occupancy probability in year 100
head(col_stats_a$occ_prob)</code></pre>
<pre><code>## patch 100
## 1 15 0.10
## 2 17 0.10
## 3 18 0.00
## 4 20 0.15
## 5 23 1.00
## 6 24 1.00</code></pre>
<pre class="r"><code># time to colonisation
head(col_stats_a$col_time)</code></pre>
<pre><code>## patch rep.0 rep.1 rep.2 rep.3 rep.4 rep.5 rep.6 rep.7 rep.8 rep.9 rep.10
## 1 15 NA NA NA NA NA NA 69 NA NA 63 NA
## 2 17 NA NA NA NA NA 75 NA NA NA NA NA
## 3 18 NA NA NA NA NA NA NA NA NA NA NA
## 4 20 89 NA NA NA 49 NA NA NA NA 49 NA
## 5 23 35 39 34 46 25 37 35 47 64 35 23
## 6 24 9 23 15 29 3 11 1 28 36 20 12
## rep.11 rep.12 rep.13 rep.14 rep.15 rep.16 rep.17 rep.18 rep.19
## 1 NA NA 44 NA NA NA 80 NA NA
## 2 43 80 45 NA NA NA 86 NA NA
## 3 NA NA 87 NA NA NA NA NA NA
## 4 NA NA 19 NA 35 44 60 52 NA
## 5 28 43 24 55 84 33 42 37 50
## 6 14 17 6 39 24 16 25 17 36</code></pre>
<p>For mapping the results, we can use the optional raster output: If
enabled, the function <code>ColonisationStats()</code> returns a raster
stack with the mean occupancy probabilities of the given years as well
as a raster with the mean time to colonisation over all replicates. We
plot these maps on top of our landscape:</p>
<pre class="r"><code># map occupancy probability
mycol_occprob <- colorRampPalette(c('blue','orangered','gold'))
plot(col_stats_a$map_occ_prob, axes=F, range=c(0,1), col=mycol_occprob(10), type="continuous")</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-19-1.png" width="672" /></p>
<pre class="r"><code># map occupancy probability on landscape background
bg()
plot(col_stats_a$map_occ_prob, axes=F, range=c(0,1), col=mycol_occprob(10), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-19-2.png" width="672" /></p>
<pre class="r"><code># map colonisation time
mycol_coltime <- colorRampPalette(c('orangered','gold','yellow','PowderBlue','LightSeaGreen'))
plot(col_stats_a$map_col_time, axes=F, breaks=c(-9,seq(-9,100,length=11)), col=c('blue',mycol_coltime(20)), type="continuous")</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-19-3.png" width="672" /></p>
<pre class="r"><code># map colonisation time on landscape background
bg()
plot(col_stats_a$map_col_time, axes=F, breaks=c(-9,seq(-9,100,length=11)), col=c('blue',mycol_coltime(20)), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-19-4.png" width="672" /></p>
</div>
</div>
<div id="scenario-b-females-settle-independent-of-males"
class="section level1" number="3">
<h1><span class="header-section-number">3</span> Scenario b: females
settle independent of males</h1>
<p>This experiment was designed to provide an example of how the
dispersal behaviour of the species and the specification of settlement
rules can change the estimated connectivity of a habitat network. We
will relax the mating requirement a little by making it sex-dependent
and only setting it for males. This means that female dispersers will
settle in suitable patches regardless of males, while males settle only
when finding a female.</p>
<pre class="r"><code># Change Settlement rules
disp_b <- Dispersal(Emigration = Emigration(DensDep=T, StageDep=T,
EmigProb = cbind(0:2,c(0.5,0,0),c(10.0,0,0),c(1.0,0,0)) ),
Transfer = SMS(PR=5, DP=10, Costs = c(1,1,3,5,10,20,50), StepMort = 0.01),
Settlement = Settlement(FindMate = c(F,T), SexDep=T, Settle=cbind(c(0,1)) ) )
# Update simulation
sim_b <- Simulation(Simulation = 1,
Replicates = 20,
Years = 100,
OutIntPop = 1,
OutIntOcc = 1,
OutIntRange = 1)
# Update parameter master
s_b <- s + disp_b + sim_b</code></pre>
<pre class="r"><code># run simulation
RunRS(s_b, dirpath)</code></pre>
<p>Now, let’s post-process the simulation results and plot the maps.</p>
<pre class="r"><code># Get colonisation stats
col_stats_b <- ColonisationStats(s_b, dirpath, years = 100, maps = T)</code></pre>
<pre><code>## Warning: [rast] the first raster was empty and was ignored</code></pre>
<pre class="r"><code># Map occupancy probabilities:
bg()
plot(col_stats_b$map_occ_prob, axes=F, range=c(0,1), col=mycol_occprob(11), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-22-1.png" width="672" /></p>
<pre class="r"><code># map colonisation time + background
bg()
plot(col_stats_b$map_col_time, axes=F, breaks=c(-9,seq(-9,100,length=11)), col=c('blue',mycol_coltime(20)), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-22-2.png" width="672" /></p>
<p>From both the visualisation and the results, we see that relaxing the
mate-finding rules substantially increased the number of occupied
patches, their probability of occupancy and the mean time to
colonisation. This results in higher functional connectivity of the
woodland network over <em>100</em> years.</p>
</div>
<div id="scenario-c-asexual-female-only-model" class="section level1"
number="4">
<h1><span class="header-section-number">4</span> Scenario c: asexual /
female-only model</h1>
<p>Here we change the demography module to represent a female-only
model. This change also has important consequences for the dispersal
process and potential implications for patterns of colonisation across a
landscape. Female-only models assume that males are not limiting, and
that the population dynamics are driven only by females. It also means
that sexes are not modelled explicitly and it is not possible to account
for behaviours like mate-finding in the settlement decisions; females
will settle in suitable habitat patches and then will automatically be
able to attempt reproduction.</p>
<p>The stage-structure of the model remains the same apart from
accounting for the female-only case. In particular, in female-only
models, we ignore the male part of the population and offspring.
Therefore, we set the fecundity of stage 3 to <em>2.5</em> instead of
<em>5.0</em> and the demographic density dependence <em>1/b</em>
(<code>K_or_DensDep</code>) to <em>5</em> instead of <em>10</em>.
Sex-dependent settlement options are no longer available.</p>
<pre class="r"><code># Change demographic density dependence to half its value of the sexual model
land_c <- ImportedLandscape(LandscapeFile = "landscape_10m_batch.txt",
PatchFile = "woodland_1ha_patchIDs.txt",
Resolution = 10,
Nhabitats = 7,
K_or_DensDep = c(5, rep(0,6)),
SpDistFile = "patch30.txt",
SpDistResolution = 10)
# Change demography settings
stg_c <- StageStructure(Stages=3,
TransMatrix=matrix(c(0, 1, 0, 0, 0.1, 0.4, 2.5, 0, 0.8), nrow = 3, byrow = F),
MaxAge=1000,
SurvSched=2,
FecDensDep=T)
demo_c <- Demography(StageStruct = stg_c,
ReproductionType = 0) # female-only model
# Remove settlement rules
disp_c <- Dispersal(Emigration = Emigration(DensDep=T, StageDep=T,
EmigProb = cbind(0:2,c(0.5,0,0),c(10.0,0,0),c(1.0,0,0)) ),
Transfer = SMS(PR=5, DP=10, Costs = c(1,1,3,5,10,20,50), StepMort = 0.01),
Settlement = Settlement()
)
# Update simulation
sim_c <- Simulation(Simulation = 2,
Replicates = 20,
Years = 100,
OutIntPop = 1,
OutIntOcc = 1,
OutIntRange = 1)
# parameter master
s_c <- RSsim(batchnum = 3, land = land_c, demog = demo_c, dispersal = disp_c, simul = sim_c, init = init, seed = 48263)</code></pre>
<pre class="r"><code>RunRS(s_c, dirpath)</code></pre>
<p>Process the output and plot the occupancy maps:</p>
<pre class="r"><code># Get colonisation stats
col_stats_c <- ColonisationStats(s_c, dirpath, years = 100, maps = T)</code></pre>
<pre><code>## Warning: [rast] the first raster was empty and was ignored</code></pre>
<pre class="r"><code># Map occupancy probabilities:
bg()
plot(col_stats_c$map_occ_prob, axes=F, range=c(0,1), col=mycol_occprob(11), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-25-1.png" width="672" /></p>
<pre class="r"><code># Map colonisation time + background
bg()
plot(col_stats_c$map_col_time, axes=F, breaks=c(-9,seq(-9,100,length=11)), col=c('blue',mycol_coltime(20)), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-25-2.png" width="672" /></p>
<p>As we see from the results, the asexual model without mate finding as
settlement rule leads to a drastic increase in the overall occupancy of
the habitat network after <em>100</em> years.</p>
</div>
<div id="scenario-d-habitat-specific-per-step-mortality"
class="section level1" number="5">
<h1><span class="header-section-number">5</span> Scenario d:
habitat-specific per-step mortality</h1>
<p>In this last simulation, we will demonstrate how
<code>RangeshiftR</code> can incorporate more complexity in the way that
movement is modelled. We relax the unrealistic assumption that the
per-step mortality is constant across all land-cover types, and assign
different mortality values to each habitat. To set up this simulation,
we use the parameters from scenario a) and only add a modified transfer
module. Here, we define <code>StepMort</code> as habitat-dependent by
providing a vector with mortality probabilities for each land cover
type.</p>
<pre class="r"><code># Update Transfer sub-module within the dispersal module
disp_d <- disp + SMS(PR=5, DP=10, Costs = c(1,1,3,5,10,20,50),
StepMort = c(0,0,0,0.01,0.01,0.02,0.05)
)
# Update simulation
sim_d <- Simulation(Simulation = 3,
Replicates = 20,
Years = 100,
OutIntPop = 1,
OutIntOcc = 1,
OutIntRange = 1)
# Use parameter master from a) and add new transfer module
s_d <- s + disp_d + sim_d</code></pre>
<p>Run the simulation:</p>
<pre class="r"><code>RunRS(s_d, dirpath)</code></pre>
<p>Process and map results:</p>
<pre class="r"><code># Get colonisation stats
col_stats_d <- ColonisationStats(s_d, dirpath, years = 100, maps = T)</code></pre>
<pre><code>## Warning: [rast] the first raster was empty and was ignored</code></pre>
<pre class="r"><code># Map occupancy probabilities:
bg()
plot(col_stats_d$map_occ_prob, axes=F, range=c(0,1), col=mycol_occprob(11), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-28-1.png" width="672" /></p>
<pre class="r"><code># map colonisation time + background
bg()
plot(col_stats_d$map_col_time, axes=F, breaks=c(-9,seq(-9,100,length=11)), col=c('blue',mycol_coltime(20)), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-28-2.png" width="672" /></p>
<p>We see that such small changes in the per-step mortality, in
interaction with the landscape structure, make a big difference in the
results, in this case decreasing the functional connectivity of the
network.</p>
</div>
<div id="scenario-comparison" class="section level1" number="6">
<h1><span class="header-section-number">6</span> Scenario
comparison</h1>
<p>Let’s plot all maps next to each other.</p>
<pre class="r"><code># Plot occupancy probabilities for all scenarios
par(mfrow=c(2,2))
bg(main="Scenario A")
plot(col_stats_a$map_occ_prob, axes=F, range=c(0,1), col=mycol_occprob(11), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)
bg(main="Scenario B")
plot(col_stats_b$map_occ_prob, axes=F, range=c(0,1), col=mycol_occprob(11), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)
bg(main="Scenario C")
plot(col_stats_c$map_occ_prob, axes=F, range=c(0,1), col=mycol_occprob(11), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)
bg(main="Scenario D")
plot(col_stats_d$map_occ_prob, axes=F, range=c(0,1), col=mycol_occprob(11), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-29-1.png" width="672" /></p>
<pre class="r"><code># Plot colonisation times for all scenarios
par(mfrow=c(2,2))
bg(main="Scenario A")
plot(col_stats_a$map_col_time, axes=F, breaks=c(-9,seq(-9,100,length=11)), col=c('blue',mycol_coltime(20)), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)
bg(main="Scenario B")
plot(col_stats_b$map_col_time, axes=F, breaks=c(-9,seq(-9,100,length=11)), col=c('blue',mycol_coltime(20)), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)
bg(main="Scenario C")
plot(col_stats_c$map_col_time, axes=F, breaks=c(-9,seq(-9,100,length=11)), col=c('blue',mycol_coltime(20)), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)
bg(main="Scenario D")
plot(col_stats_d$map_col_time, axes=F, breaks=c(-9,seq(-9,100,length=11)), col=c('blue',mycol_coltime(20)), type="continuous", plg=list(x="bottom", ext=c(e$xmin+400, e$xmax-400, e$ymin-150, e$ymin-50)), add =T)</code></pre>
<p><img src="tutorial_2_files/figure-html/unnamed-chunk-29-2.png" width="672" /></p>
<pre class="r"><code># reset plot layout
par(mfrow=c(1,1))</code></pre>
</div>
<div id="dispersal-heatmap" class="section level1" number="7">
<h1><span class="header-section-number">7</span> Dispersal heatmap</h1>
<p>As an additional tool to analyse the connectivity of a landscape and
to assess how the matrix is used by dispersing individuals, the option
to output a dispersal heatmap is provided (available only in case of SMS
as the transfer method). In this section, we re-run scenario c) as an
example to show how to create and plot such a heatmap.</p>
<p>We use an alternative option for the initialisation of the
population. Instead of providing a species distribution map, a text file
can be given that specifies a list of initial patches (or cells, in a
cell-based model) and initial local populations. This text file must
contain a specific list of columns that also depend on your model
settings (please see <code>?Initialise</code>). For sexual models, you
need to include the column “Sex”; for stage-structured models, you need
to include the columns “Age” and “Stage”. For the correct format of the
initial individuals file, please refer to the documentation and the
example file given with this tutorial.</p>
<p>The corresponding initialisation module is specified like this:</p>
<pre class="r"><code># alternative initialisation in patch 30:
init_alt <- Initialise(InitType = 2, # = from initial individuals list file
InitIndsFile = "initial_inds_c.txt")</code></pre>
<p>The output of the SMS heatmaps is enabled in the simulation module
using the parameter <code>SMSHeatMap</code>.</p>
<pre class="r"><code># update simulation module
sim_c2 <- Simulation(SMSHeatMap = T,
Simulation = 4,
Replicates = 20,
Years = 100,
OutIntPop = 0,
OutIntRange = 0)</code></pre>
<p>With these changes and all other modules from scenario c) as defined
above, we create the modified parameter master and run the
simulation.</p>