-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoverview_0.html
More file actions
878 lines (778 loc) · 28 KB
/
overview_0.html
File metadata and controls
878 lines (778 loc) · 28 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Overview: General introduction to RangeShiftR</title>
<script src="site_libs/header-attrs-2.29/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.5.2/css/all.min.css" rel="stylesheet" />
<link href="site_libs/font-awesome-6.5.2/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">
.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>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Former versions
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="installing_v2.0.html">RangeShiftR v1.1.2 (based on RangeShifter 2.0)</a>
</li>
<li>
<a href="overview_0_v2.0.html">0. General package introduction v1.1.2</a>
</li>
<li>
<a href="tutorial_1_v2.0.html">1. Range expansion v1.1.2</a>
</li>
<li>
<a href="tutorial_2_v2.0.html">2. Patch connectivity v1.1.2</a>
</li>
<li>
<a href="tutorial_3_v2.0.html">3. Dynamic landscapes & SMS paths v1.1.2</a>
</li>
<li>
<a href="tutorial_4_v2.0.html">4. Evolution of dispersal v1.1.2</a>
</li>
<li>
<a href="appendix_tutorial_3_v2.0.html">Appendix A3. Create dynamic landscapes v1.1.2</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="mailto:RangeShiftR@uni-potsdam.de">
<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">Overview: General introduction to
RangeShiftR</h1>
</div>
<script>
addClassKlippyTo("pre.r, pre.markdown");
addKlippy('right', 'top', 'auto', '1', 'Copy code', 'Copied!');
</script>
<p>In this overview, we quickly go through the main functionality of the
<em>RangeShiftR</em> R-package in order to get a first overview of the
basic structure.</p>
<div id="the-basics" class="section level1" number="1">
<h1><span class="header-section-number">1</span> The basics</h1>
<p>Within the standard workflow of <em>RangeShiftR</em>, a simulation is
defined by:</p>
<ol style="list-style-type: decimal">
<li>a so-called parameter master object that contains the simulation
modules, which represent the model structure, as well as the (numeric)
values of all necessary simulation parameters, and</li>
<li>the path to the working directory on the disc where the simulation
inputs and outputs are stored.</li>
</ol>
<p>The standard workflow of <em>RangeShiftR</em> is to load input maps
from ASCII raster files and to write all simulation output into text
files. Therefore, the specified working directory needs to have a
certain folder structure: It should contain 3 sub-folders named
‘Inputs’, ‘Outputs’ and ‘Output_Maps’.</p>
<div id="running-a-first-working-example" class="section level2"
number="1.1">
<h2><span class="header-section-number">1.1</span> Running a first
working example</h2>
<p>Load the package by typing:</p>
<pre class="r"><code>library(RangeShiftR)</code></pre>
<pre><code>## RangeshiftR version 3.0.0 (24.03.2026)
## Copyright (C) 2020-2026 Anne-Kathleen Malchow, Greta Bocedi, Stephen C.F. Palmer, Justin M.J. Travis, Jette Wolff, Damaris Zurell
##
## This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
## You are welcome to redistribute it and/or modify it under certain conditions;
## type 'RangeShiftR_license()' for details.</code></pre>
<p>Create a parameter master object with all the default settings and
store it:</p>
<pre class="r"><code>s <- RSsim()</code></pre>
<p>If you have already created a suitable directory for your simulation
on your disc, store its path in a variable. This can either be the
relative path from your R working directory or the absolute path.</p>
<pre class="r"><code>dirpath = "Overview/"</code></pre>
<p>Create the RS folder structure, if it doesn’t yet exist:</p>
<pre class="r"><code>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>With this, we are already set to run our first simulation by
typing:</p>
<pre class="r"><code>RunRS(s,dirpath)</code></pre>
<pre><code>## Checking Control parameters
##
## Control Parameters checked
##
## Run Simulation(s) with random seed ...
## ReadLandParamsR() done
## ReadParametersR() done.
## ReadEmigrationR() done.
## ReadTransferR() done.
## ReadSettlementR() done.
## ReadInitialisationR() done.
##
## Running simulation nr. 1
## RunModel(): completed initialisation
## Starting year 0...
## Starting year 1...
## Starting year 2...
## Starting year 3...
## Starting year 10...
## Starting year 20...
## Starting year 30...
## RunModel(): completed initialisation
## Starting year 0...
## Starting year 1...
## Starting year 2...
## Starting year 3...
## Starting year 10...
## Starting year 20...
## Starting year 30...
##
## ***** Elapsed time: 1 seconds
##
## *****
## ***** Simulation completed
## ***** Outputs folder: Overview/Outputs/
## *****</code></pre>
<pre><code>## $Errors
## [1] 0</code></pre>
<p>You should find the generated output - the simulation results as well
as some log files - in the ‘Outputs’ folder.</p>
</div>
</div>
<div id="simulation-modules" class="section level1" number="2">
<h1><span class="header-section-number">2</span> Simulation modules</h1>
<p>To look at the parameter master in more detail, simply type:</p>
<pre class="r"><code>s</code></pre>
<pre><code>## Batch # 1
##
## Simulation # 1
## -----------------
## Replicates = 2
## Years = 50
## Absorbing = FALSE
## File Outputs:
## Range, every 1 years
## Populations, every 1 years, starting year 0
##
## Artificial landscape: random structure, binary habitat/matrix code
## Size : 65 x 65 cells
## Resolution : 100 meters
## Proportion of suitable habitat: 0.5
## K or 1/b : 10
##
## Demography:
## Unstructured population:
## Rmax : 1.5
## bc : 1
## Reproduction Type : 0 (female only)
##
## Dispersal:
## Emigration:
## Emigration probabilities:
## [,1]
## [1,] 0
##
## Transfer:
## Dispersal Kernel
## Dispersal kernel traits:
## [,1]
## [1,] 100
## Constant mortality prob = 0
##
## Settlement:
## Settlement conditions:
## [1] 0
## FindMate =
## [1] FALSE
##
## Management:
## [1] FALSE
##
## Initialisation:
## InitType = 0 : Free initialisation
## of all suitable cells/patches.
## InitDens = 1 : At half K_or_DensDep</code></pre>
<p>It contains of a number of parameter modules that each define
different aspects of the RangeShifter simulation. Specifically, there
are:</p>
<ul>
<li>Simulation</li>
<li>Landscape</li>
<li>Demography</li>
<li>Dispersal</li>
<li>Genetics</li>
<li>Management</li>
<li>Initialisation</li>
</ul>
<p>Here is a schematic overview of the module constructors and their
relations: <img src="figures/function_overview_3.0.png"
alt="RangeshiftR function overview" /></p>
<p>In the following, we go through some of the most relevant aspects of
each module.</p>
<div id="simulation" class="section level2" number="2.1">
<h2><span class="header-section-number">2.1</span> Simulation</h2>
<p>This module is used to set general simulation parameters
(e.g. simulation ID, number of replicates, and number of years to
simulate) and to control output types (plus some more specific
settings). For this overview, we will stick to the defaults:</p>
<pre class="r"><code>sim <- Simulation(Simulation = 2,
Years = 50,
Replicates = 2,
OutIntPop = 50)</code></pre>
<p>For detailed information on this module (or any other), please see
the documentation.</p>
<pre class="r"><code>?Simulation</code></pre>
</div>
<div id="landscape" class="section level2" number="2.2">
<h2><span class="header-section-number">2.2</span> Landscape</h2>
<p><em>RangeShiftR</em> can either import a map from an ASCII raster
file in the ‘Inputs’ folder or generate a random map to use in the
simulation.</p>
<p>For each option, there is a corresponding function to create a
Landscape parameter object</p>
<pre class="r"><code>land <- ImportedLandscape()
land <- ArtificialLandscape()</code></pre>
<p>Imported landscapes can provide either (binary or continuous) habitat
suitability or land type codes. Furthermore, they can be either patch-
or cell-based. We cover both types of landscapes in the remaining
tutorials.</p>
<p>Artificially generated landscapes can only contain (binary or
continuous) habitat suitability and are always cell-based.</p>
<p>For our example, we define an artificial landscape:</p>
<pre class="r"><code>land <- ArtificialLandscape(Resolution = 10, # in meters
K_or_DensDep = 1500, # ~ 15 inds/cell
propSuit = 0.2,
dimX = 129, dimY = 257,
fractal = T, hurst = 0.3,
continuous = F)</code></pre>
</div>
<div id="demography" class="section level2" number="2.3">
<h2><span class="header-section-number">2.3</span> Demography</h2>
<p>The Demography module contains all the local population dynamics of
your simulated species. Generally there are two types:</p>
<ul>
<li>Unstructured model / non-overlapping generations</li>
<li>Stage-structured model / overlapping generations</li>
</ul>
<p>For the first case, create a simple <code>Demography()</code> module
(the maximum growth rate <code>Rmax</code> is the only required
parameter)</p>
<pre class="r"><code>demo <- Demography(Rmax = 2.2, ReproductionType = 1, PropMales = 0.45)</code></pre>
<p>The option <code>ReproductionType</code> determines the way that
different sexes are considered:</p>
<p>0 = asexual / only female model<br />
1 = simple sexual model<br />
2 = sexual model with explicit mating system</p>
<p>In order to make a stage-structured model, we have to additionally
create a stage-structure sub-module within the Demography module. Here,
we have already defined a Demography object and can use ‘+’ to add the
StageStructure sub-module.</p>
<pre class="r"><code>stg <- StageStructure(Stages = 3,
TransMatrix = matrix(c(0,1,0,5.7,.5,.4,3.4,0,.9),nrow = 3),
FecDensDep = T,
SurvDensDep = T)
demo <- demo + stg</code></pre>
<p>Alternatively, we define the sub-module within the Demography
module:</p>
<pre class="r"><code>demo <- Demography(StageStruct = stg, ReproductionType = 1, PropMales = 0.45)</code></pre>
<p><em>RangeShiftR</em> provides a number of useful functions to explore
the model set-up. For example, we can plot the rates from the transition
matrix:</p>
<pre class="r"><code>plotProbs(stg)</code></pre>
<p><img src="overview_0_files/figure-html/unnamed-chunk-16-1.png" width="672" /></p>
</div>
<div id="dispersal" class="section level2" number="2.4">
<h2><span class="header-section-number">2.4</span> Dispersal</h2>
<p>The dispersal process is modelled wih three sub-processes (see the
schematic figure above): <code>Emigration()</code>,
<code>Transfer()</code> and <code>Settlement()</code>.</p>
<pre class="r"><code>disp <- Dispersal(Emigration = Emigration(EmigProb = 0.2),
Transfer = DispersalKernel(Distances = 50),
Settlement = Settlement() )</code></pre>
<p>We can use the function <code>plotProbs()</code> to plot various
functional relationships, for example a dispersal kernel with a
stage-dependent mean transfer distance:</p>
<pre class="r"><code>plotProbs(DispersalKernel(Distances = matrix(c(0,1,2,70,50,30),nrow = 3), StageDep = T))</code></pre>
<p><img src="overview_0_files/figure-html/unnamed-chunk-18-1.png" width="672" /></p>
<p>This is using mostly default options. For example, we can change the
settlement condition so that a female individual, that arrives in an
unsuitable cell, will wait for another time step and disperse again,
while the males will die if arriving in an unsuitable cell:</p>
<pre class="r"><code>disp <- disp + Settlement(SexDep = T,
Settle = matrix(c(0,1,1,0), nrow = 2),
FindMate = matrix(c(1,0,F,F), nrow = 2))</code></pre>
<p>The dispersal traits of every phase can be set to vary between
individuals (<code>IndVar = TRUE</code>). This also makes the dispersal
traits heritable and thus allows for evolution, for example, evolving
emigration probability:</p>
<pre class="r"><code>disp2 <- disp + Emigration(IndVar = TRUE)</code></pre>
<p>In case of inter-individual variability in dispersal traits, these
parameters need to be defined in the Genetics module. For our example,
we need to define the EmigrationGenes and the genetics.</p>
</div>
<div id="genetics" class="section level2" number="2.5">
<h2><span class="header-section-number">2.5</span> Genetics</h2>
<p>The genetics module controls the heritability and evolution of traits
and is needed if inter-individual variability is enabled
(<code>IndVar = TRUE</code>) e.g. for at least one dispersal trait.</p>
<pre class="r"><code>emig_gene <- EmigrationTraits(Positions = list("random"),
NbOfPositions = 5,
ExpressionType = "additive",
InitialAlleleDistribution = "normal",
InitialAlleleParameters = matrix(c(0.7,0.1), nrow=1),
IsInherited = FALSE,
MutationDistribution = "normal",
MutationParameters = matrix(c(0.5,0.2), nrow=1),
MutationRate = 0.0001,
OutputValues = FALSE
)
gene <- Genetics(GenomeSize = 10, Traits = Traits(EmigrationGenes = emig_gene))</code></pre>
<p>Genetics can simulate neutral loci, genetic loads and/or dispersal
trait evolution.</p>
</div>
<div id="initialisation" class="section level2" number="2.6">
<h2><span class="header-section-number">2.6</span> Initialisation</h2>
<p>In order to control the initial distribution of individuals in the
landscape at year <em>0</em>, we set initialisation rules. We choose to
initialise <em>3</em> individuals per habitat cell. Additionally, since
we define a stage-structured model, we have to specify the initial
proportion of stages:</p>
<pre class="r"><code>init <- Initialise(FreeType = 0,
NrCells = 2250,
InitDens = 2,
IndsHaCell = 3,
PropStages = c(0,0.7,0.3))
init</code></pre>
<pre><code>## Initialisation:
## InitType = 0 : Free initialisation
## of 2250 random suitable cells/patches.
## InitDens = 2 : 3 individuals per cell/hectare
## PropStages = 0 0.7 0.3
## InitAge = 2 : Quasi-equilibrium</code></pre>
</div>
<div id="parameter-master" class="section level2" number="2.7">
<h2><span class="header-section-number">2.7</span> Parameter master</h2>
<p>After all settings have been made in their respective modules, we are
ready to combine them to a parameter master object, which is needed to
run the simulation.</p>
<pre class="r"><code>s <- RSsim(simul = sim, land = land, demog = demo, dispersal = disp2, gene = gene, init = init)
# Alternative notation:
# s <- RSsim() + land + demo + disp + sim + init + gene</code></pre>
<p>We can check the parameter master (or any single module) for
potential parameter conflicts:</p>
<pre class="r"><code>validateRSparams(s)</code></pre>
<pre><code>## [1] TRUE</code></pre>
</div>
<div id="run-the-simulation" class="section level2" number="2.8">
<h2><span class="header-section-number">2.8</span> Run the
simulation</h2>
<p>Once the parameter master has been defined, we can run the
simulations in the specified RS directory.</p>
<pre class="r"><code>RunRS(s, dirpath)</code></pre>
</div>
</div>
<div id="plot-results" class="section level1" number="3">
<h1><span class="header-section-number">3</span> Plot results</h1>
<p>All results are stored in the Outputs folder. <em>RangeShiftR</em>
provides some in-built functions to access and plot these results. Here,
we plot the abundance and occupancy time series:</p>
<pre class="r"><code>range_df <- readRange(s, dirpath)
# ...with replicates:
par(mfrow=c(1,2))
plotAbundance(range_df)
plotOccupancy(range_df)</code></pre>
<p><img src="overview_0_files/figure-html/unnamed-chunk-26-1.png" width="672" /></p>
<pre class="r"><code># ...with standard deviation:
par(mfrow=c(1,2))
plotAbundance(range_df, sd=T, replicates = F)
plotOccupancy(range_df, sd=T, replicates = F)</code></pre>
<p><img src="overview_0_files/figure-html/unnamed-chunk-26-2.png" width="672" /></p>
<p>Although <em>RangeShiftR</em> provides a number of functions for easy
post-processing and plotting of results, it may also be desirable to
further process the results yourself. As a simple example for such a
workflow, let’s plot the spatial distribution of abundance. For doing
so, we load the data from the population output files and process it
using the <code>terra</code> package:</p>
<pre class="r"><code># read population output file into a dataframe
pop_df <- readPop(s, dirpath)
# Not all years have the same number of populated and thus listed cells. For stacking, we set a common extent with the values used in the landscape module:
ext <- c(0,1290,0,2570)
res <- 10
# Make stack of different raster layers for each year and for only one repetition (Rep==0):
pop_wide_rep0 <- reshape(subset(pop_df,Rep==0)[,c('Year','x','y','NInd')], timevar='Year', v.names=c('NInd'), idvar=c('x','y'), direction='wide')
# use terra package to make a raster from the data frame and viridis for colouring
library(terra)
library(viridis)
stack_years_rep0 <- terra::rast(pop_wide_rep0, type="xyz")
names(stack_years_rep0) <- c('Year.0', 'Year.50')
terra::plot(stack_years_rep0, range = c(0,7), col = magma(14), type="continuous")</code></pre>
<p><img src="overview_0_files/figure-html/unnamed-chunk-27-1.png" width="672" /></p>
</div>
<!DOCTYPE html>
<html>
<br>
<hr />
<div id="footer">
<p>Anne-Kathleen Malchow, Greta Bocedi, Steve Palmer, Justin Travis & Damaris Zurell <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/" >(CC BY-NC-ND 4.0)</a>. </p>
</div>
</html>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open');
});
});
</script>
<!-- code folding -->
<script>
$(document).ready(function () {
// temporarily add toc-ignore selector to headers for the consistency with Pandoc
$('.unlisted.unnumbered').addClass('toc-ignore')
// 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, '_');
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = true;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>