-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabundance-density-tl-SI.Rtex
792 lines (575 loc) · 33.5 KB
/
abundance-density-tl-SI.Rtex
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
%--------------------------------------------------------------------------------------------------------------------------------%
% Code for "Supplementary information: A mechanistic model to compare the importance of interrelated population measures: population size, population density and colony size"
% by Tim CD Lucas, Hilde Herbots and Kate Jones
%
%---------------------------------------------------------------------------------------------------------------------------------%
%%begin.rcode settings, echo = FALSE, cache = FALSE, message = FALSE, results = 'hide', eval = TRUE
# There are figures created in the data analysis which are not in the final chapter document.
# If TRUE, they will be included in the output.
# Use 'hide' to remove them.
extraFigs <- 'hide'
#knitr options
# Set figure prefix as A so that no figures will be overwritten.
opts_chunk$set(cache.path = '.SICache/', fig.path = 'figure/')
source('misc/KnitrOptions.R')
%%end.rcode
%%begin.rcode libs, cache = FALSE
# ggplot2 theme.
source('misc/theme_tcdl.R')
theme_set(theme_grey() + theme_pub)
library(xtable)
library(palettetown)
library(binom)
library(ggplot2)
library(dplyr)
library(MetapopEpi)
library(broom)
%%end.rcode
\begin{table}[h!]
\captionsetup{width=\textwidth}
\centering
\small
\caption{A summary of all symbols used along with their units and default values.
The justifications for parameter values are given in the main manuscript.}
\begin{tabular}{@{}lp{7cm}p{2.9cm}r@{}}
\toprule
Symbol & Explanation & Units & Value\\
\midrule
$\rho$ & Number of pathogens && 2\\
$x, y$ & Group (colony) index &&\\
$p$ & Pathogen index i.e.\ $p\in\{1,2\}$ for pathogens 1 and 2 & &\\
$q$ & Disease class i.e.\ $q\in\{1,2,12\}$&\\
$S_x$ & Number of susceptible individuals in group $x$ &&\\
$I_{qx}$ & Number of individuals infected with disease(s) $q \in \{1, 2, 12\}$ in group $x$ &&\\
$R_x$ & Number of individuals in group $x$ in the recovered with immunity class &&\\
$N$ & Total Population size && 2,000 -- 32,000\\
$m$ & Number of groups && 5 -- 80\\
$n$ & Group size && 100 -- 1600\\
$a$ & Area & km\textsuperscript{2}& 2,500 -- 40,000\\
$d$ & Density & individuals.km$^{-2}$ & 0.2 -- 3.2\\
$\beta$ & Transmission rate & & 0.1 -- 0.3\\
$\alpha$ & Coinfection adjustment factor & & 0.1\\
$\gamma$ & Recovery rate & year$^{-1}.$individual$^{-1}$ & 1\\
$\xi$ & Dispersal rate & year$^{-1}.$individual$^{-1}$ & 0.01\\
$\Lambda$ & Birth rate & year$^{-1}.$individual$^{-1}$ & 0.05\\
$\mu$ & Death rate & year$^{-1}.$individual$^{-1}$ & 0.05\\
$g$ & Population growth rate & & 1\\
$k_y$ & Degree of node $y$ (number of groups that individuals from group $y$ can disperse to) &&\\
$\delta$ & Waiting time until next event & years &\\
$e_i$ & The rate at which event $i$ occurs & year$^{-1}$&\\
$R_0$ & The (single subpopulation) basic reproduction number & infections & \\
%$b_i$ & Regression coefficient & & \\
%$c$ & Regression intercept & & \\
%$\epsilon$ & Binomially distributed regression error term & & \\
\bottomrule
\end{tabular}
\label{t:params}
\end{table}
\clearpage
\section{Supplementary materials and methods: Stochastic simulations} \label{sup:stochmodel}
We examined the model using stochastic, continuous-time simulations implemented in \emph{R} \cite{R}.
The implementation is available as an \emph{R} package on GitHub \cite{metapopepi}.
The model can be written as a continuous-time Markov chain.
The Markov chain contains the random variables $((S_x)_{x = 1\ldots m}, (I_{x, q})_{x =1\ldots m,\:q \in \{1, 2, 12\}}, (R_x)_{x = 1\ldots m})$.
Here, $(S_x)_{x = 1\ldots m}$ is a length $m$ vector of the number of susceptibles in each group
$(I_{x, q})_{x =1\ldots m, q \in \{1, 2, 12\}}$ is a length $m \times 3$ vector describing the number of individuals of each disease class ($q \in \{1, 2, 12\}$) in each group.
Finally, $(R_x)_{x = 1\ldots m}$ is a length $m$ vector of the number of individuals in the recovered class.
The model is a Markov chain where extinction of either pathogen species and extinction of the host population are absorbing states.
The expected time for the host population to go extinct is much larger than the duration of the simulations.
At any time, suppose the system is in state $((s_x), (i_{x,q}), (r_x))$.
At each step in the simulation we calculate the rate at which each possible event might occur.
One event is then randomly chosen, weighted by its rate
\begin{align}
p(\text{event } i) = \frac{e_i}{\sum_j e_j},
\end{align}
where $e_i$ is the rate at which event $i$ occurs and $\sum_j e_j$ is the sum of the rates of all possible events.
Finally, the length of the time step, $\delta$, is drawn from an exponential distribution
\begin{align}
\delta \sim \operatorname{Exp}\left(\sum_j e_j \right).
\end{align}
We can now write down the rates of all events.
Assuming asexual reproduction, that all classes reproduce at the same rate and that individuals are born into the susceptible class we get
\begin{align}
s_x \rightarrow s_x + 1 \;\;\;\text{at a rate of}\;\; \Lambda\left( s_{x}+\sum_q i_{qx} + r_{x}\right)
\end{align}
where $s_x \rightarrow s_x + 1$ is the event that the number of susceptibles in group $x$ will increase by 1 (a single birth) and $\sum_q i_{qx}$ is the sum of all infection classes $q~\in~\{1, 2, 12\}$.
The rates of death, given a death rate $\mu$, and no increased mortality due to infection, are given by
\begin{align}
s_x \rightarrow s_x-1 &\;\;\;\text{at a rate of}\;\; \mu s_x, \\
i_{qx} \rightarrow i_{qx}-1 &\;\;\text{at a rate of}\;\; \mu i_{qx},\\
r_x \rightarrow r_x-1 &\;\;\;\text{at a rate of}\;\; \mu r_x.
\end{align}
We modelled transmission as being density-dependent.
This assumption was more suitable than frequency-dependent transmission as we were modelling a disease transmitted by saliva or urine in highly dense populations confined to caves, buildings or potentially a small number of tree roosts.
We were notably not modelling a sexually transmitted disease (STD) as spillover of STDs from bats to humans is likely to be rare.
Infection of a susceptible with either Pathogen 1 or 2 is therefore given by
\begin{align}
i_{1x} \rightarrow i_{1x}+1,\;\;\; s_x \rightarrow s_x-1 &\;\;\text{at a rate of}\;\; \beta s_x\left(i_{1x} + i_{12x}\right),\\
i_{2x} \rightarrow i_{2x}+1,\;\;\; s_x \rightarrow s_x-1 &\;\;\text{at a rate of}\;\; \beta s_x\left(i_{2x} + i_{12x}\right),
\end{align}
while coinfection, given the coinfection adjustment factor $\alpha$, is given by
\begin{align}
i_{12,x} \rightarrow i_{12,x}+1,\;\;\; i_{1x} \rightarrow i_{1x}-1 &\;\;\text{at a rate of}\;\; \alpha\beta i_{1x}\left(i_{2x} + i_{12x}\right),\\
i_{12,x} \rightarrow i_{12,x}+1,\;\;\; i_{2x} \rightarrow i_{2x}-1 &\;\;\text{at a rate of}\;\; \alpha\beta i_{2x}\left(i_{1x} + i_{12x}\right).
\end{align}
Note that lower values of $\alpha$ give lower rates of coinfection as in \cite{castillo1989epidemiological}.
The rate of migration from group $y$ (with degree $k_y$) to group $x$, given a dispersal rate $\xi$ is given by
\begin{align}
s_x \rightarrow s_x+1,\;\;\; s_y \rightarrow s_y-1 &\;\;\text{at a rate of}\;\; \frac{\xi s_y}{k_y},\\
i_{qx} \rightarrow i_{qx}+1,\;\;\; i_{qy} \rightarrow i_{qy}-1 &\;\;\text{at a rate of}\;\; \frac{\xi i_{qy}}{k_y},\\
r_x \rightarrow r_x+1,\;\;\; r_y \rightarrow r_y-1 &\;\;\text{at a rate of}\;\; \frac{\xi r_y}{k_y}.
\end{align}
Note that the dispersal rate does not change with infection.
As above, this is due to the low virulence of bat viruses.
Finally, recovery from any infectious class occurs at a rate $\gamma$
\begin{align}
i_{qx} \rightarrow i_{qx}-1,\;\; r_x \rightarrow r_x+1 \;\;\text{at a rate of}\;\; \gamma i_{qx}.
\end{align}
\clearpage
\section{Supplementary materials and methods: Deterministic model}
% todo Align equal signs across groups
% http://tex.stackexchange.com/questions/11855/alignment-of-equals-sign-in-multiple-align-environments
%
% Should probably put whole, single patch model into sympy and see what I get out...
We can study the model analytically if we restrict the population to a single subpopulation.
We first study the endemic pathogen.
We then have a typical SIR model with vital dynamics \cite{Kermack1932}.
\begin{align}
\frac{dS}{dt} & = \Lambda n - \mu S - \beta S I_1, \label{smodel2} \\
\frac{dI_1}{dt} & = \beta S I_1 - (\gamma + \mu) I_1, \\
\frac{dR}{dt} & = \gamma I_1 - \mu R.
\end{align}
\subsubsection{Equilibrium values of single pathogen model}
To find the equilibrium number of susceptibles, $S^\ast$, we set $\frac{dI_1}{dt} = 0$.
We then have the trival steady state of $S^* = n$ and $I_1^* = 0$.
To find the endemic steady state ($I_1^* \ne 0$) we write
\begin{align}
\beta S^\ast I_1^\ast &= (\gamma + \mu) I_1^\ast,\\
S^\ast &= \frac{\gamma + \mu}{\beta} \label{sstar}.
\end{align}
To find $I^\ast$ we substitute Equation \ref{sstar} into Equation \ref{smodel2} and set $\frac{dI_1}{dt} = 0$ giving
\begin{align}
0 = & \Lambda n - \mu S^\ast - \beta S^\ast I_1^\ast , \\
0 = & \Lambda n - \frac{\mu \left(\gamma + \mu\right)}{\beta} - \left(\gamma + \mu\right)I_1^\ast , \\
I_1^\ast = & \frac{\Lambda n}{\gamma + \mu} - \frac{\mu }{\beta} \label{istar}.
\end{align}
\subsubsection{Second pathogen}
We assume that Pathogen 2 is introduced when the endemic pathogen is at equilibrium.
The introduction of Pathogen 2 will cause the system to shift to a new equilibrium.
However, we continue to use $S^*$ and $I_1^*$ to mean the values above.
Initially, the dynamics of Pathogen 2 are governed by
\begin{align}
\frac{dI_2}{dt} & = \beta S^\ast I_2 + \alpha \beta I_1^\ast I_2 - (\gamma + \mu) I_2 \label{path2I}
\end{align}
where $\beta S^\ast I_2$ is the number of infections per unit time, $ \alpha \beta I_1^\ast I_2$ is the number of coinfections per unit time and $(\gamma + \mu) I_2 $ is the number of deaths and recoveries per unit time.
$I_2$ is therefore the number of individuals infected with Pathogen 2 regardless of whether they are infected with Pathogen 1.
In this sense it is the combined size of classes $I_2$ and $I_{12}$ as used in the stochastic model (Section \ref{sup:stochmodel}).
For simplicity here we simply label this group $I_2$.
Substituting in Equations \ref{sstar} and \ref{istar}, and noting that $R_0 = \frac{\beta n }{\gamma + \mu}$ we get
\begin{align}
\frac{dI_2}{dt} & = (\gamma + \mu) I_2 + \alpha \beta \left( \frac{\Lambda n}{\gamma + \mu} - \frac{\mu}{\beta} \right) I_2 - (\gamma + \mu) I_2, \\
\frac{dI_2}{dt} & = \alpha\left( \frac{\beta \Lambda n}{\gamma + \mu} - \mu \right) I_2, \\
\frac{dI_2}{dt} & = \alpha\left( \Lambda R_0 - \mu \right) I_2.
\end{align}
This is greater than zero when
\begin{align}
\alpha\left( \Lambda R_0 - \mu \right) I_2 > 0
\end{align}
As $I_2$ is positive, this is greater than zero when $ \Lambda R_0 - \mu > 0$ and $\alpha > 0$.
As $\Lambda = \mu$ due to the assumption of stable population size, $ \Lambda R_0 - \mu > 0$ is true as long as $R_0 > 1$.
$R_0$ is greater than one (as we have assumed that Pathogen 1 is endemic),
Therefore, $\frac{dI_2}{dt}$ is greater than zero provided $\alpha$ is greater than zero.
\clearpage
%%begin.rcode rawDataTables, cache = FALSE
dens1 <- read.csv('Data/DensSims.csv') %>% dplyr::select(-X)
dens1Means <- dens1 %>%
#filter(nExtantDis > 0) %>%
group_by(transmission, colonySize, colonyNumber) %>%
summarise(`Area \\tiny{($\\times 1000$ km$^2$)}` = mean(area / 1000),
`$N$ \\tiny{($\\times 1000$)}` = mean(as.numeric(as.character(pop)) / 1000) ,
`Density \\tiny{(km$^{-2}$)}` = mean(as.numeric(as.character(pop))) / mean(as.numeric(as.character(area))),
Invasions = sum(nExtantDis == 2)) %>%
rename(`$\\beta$` = transmission, `$n$` = colonySize, `$m$` = colonyNumber)
# Constant density, altered colony number
dens2 <- read.csv('Data/Dens2Sims.csv') %>% dplyr::select(-X)
dens2Means <- dens2 %>%
#filter(nExtantDis > 0) %>%
group_by(transmission, colonySize, colonyNumber) %>%
summarise(`Area \\tiny{($\\times 1000$ km$^2$)}` = mean(area / 1000),
`$N$ \\tiny{($\\times 1000$)}` = mean(as.numeric(as.character(pop)) / 1000) ,
`Density \\tiny{(km$^{-2}$)}` = mean(as.numeric(as.character(pop))) / mean(as.numeric(as.character(area))),
Invasions = sum(nExtantDis == 2)) %>%
rename(`$\\beta$` = transmission, `$n$` = colonySize, `$m$` = colonyNumber)
# Constant population, altered area
pop <- read.csv('Data/PopSims.csv') %>% dplyr::select(-X)
popMeans <- pop %>%
#filter(nExtantDis > 0) %>%
group_by(transmission, area) %>%
summarise(`$\\beta$` = mean(transmission),
`$n$` = mean(colonySize),
`$m$` = mean(colonyNumber),
`Area \\tiny{($\\times 1000$ km$^2$)}` = mean(area / 1000),
`$N$ \\tiny{($\\times 1000$)}` = mean(as.numeric(as.character(pop)) / 1000) ,
`Density \\tiny{(km$^{-2}$)}` = mean(as.numeric(as.character(pop))) / mean(as.numeric(as.character(area))),
Invasions = sum(nExtantDis == 2)) %>%
ungroup %>%
dplyr::select(-area, -transmission)
%%end.rcode
% ----------------------------------------------- %
% Print tables
% ----------------------------------------------- %
%%begin.rcode pop, results = 'asis'
popTitle <- "
Raw data for geographic range size simulations
"
popCapt <- "
Raw data for geographic range size simulations.
The population parameters are shown along with the number of invasions.
$\\beta$ is the transmission rate, $n$ is group size, $m$ is the number of groups and $N$ is the total population size.
"
print(xtable(popMeans,
caption = c(popCapt, popTitle),
label = "C-pop",
digits = c(0, 1, 0, 0, 1, 0, 1, 0),
align = c('r', '@{}r', 'r', 'r', 'r', 'r', 'r', 'r@{}')),
size = "small", #Change size; useful for bigger tables
include.rownames = FALSE, #Don't print rownames
include.colnames = TRUE,
sanitize.colnames.function = function(x){x},
caption.placement = "top",
booktabs = TRUE
)
%%end.rcode
%%begin.rcode dens1, results = 'asis'
dens1Title <- "
Raw data for group size simulations
"
dens1Capt <- "
Raw data for group size simulations.
The population parameters are shown along with the number of invasions.
$\\beta$ is the transmission rate, $n$ is group size, $m$ is the number of groups and $N$ is the total population size.
"
print(xtable(dens1Means,
caption = c(dens1Capt, dens1Title),
label = "C-dens1",
digits = c(0, 1, 0, 0, 1, 0, 1, 0),
align = c('r', '@{}r', 'r', 'r', 'r', 'r', 'r', 'r@{}')),
size = "small", #Change size; useful for bigger tables
include.rownames = FALSE, #Don't print rownames
include.colnames = TRUE,
sanitize.colnames.function = function(x){x},
caption.placement = "top",
booktabs = TRUE
)
%%end.rcode
%%begin.rcode dens2, results = 'asis'
dens2Title <- "
Raw data for number of groups simulations
"
dens2Capt <- "
Raw data for number of groups simulations.
The population parameters are shown along with the number of invasions.
$\\beta$ is the transmission rate, $n$ is group size, $m$ is the number of groups and $N$ is the total population size.
"
print(xtable(dens2Means,
caption = c(dens2Capt, dens2Title),
label = "C-dens2",
digits = c(0, 1, 0, 0, 1, 0, 1, 0),
align = c('r', '@{}r', 'r', 'r', 'r', 'r', 'r', 'r@{}')),
size = "small", #Change size; useful for bigger tables
include.rownames = FALSE, #Don't print rownames
include.colnames = TRUE,
sanitize.colnames.function = function(x){x},
caption.placement = "top",
booktabs = TRUE
)
%%end.rcode
%%begin.rcode colonyNetCaptions
colonyNetTitle <- 'Relationship between geographic range size and metapopulation network structure'
colonyNetCapt <- '
The relationship between geographic range size and metapopulation network structure.
Groups are shown by circles.
Groups that are close enough for animals to disperse between (i.e.\\ within 100 km of each other) are joined by a line.
Groups are placed randomly in spaces of various sizes (grey dashed lines).
A and C) the default geographic range size (10000 km\\textsuperscript{2}).
B and D) the largest geographic range size (40000 km\\textsuperscript{2}).
A and B) the smallest number of groups (five).
C and D) the default number of groups (20).
The mean number of connections per subpopulation, $\\bar{k}$, is shown for each metapopulation.
'
%%end.rcode
\clearpage
%%begin.rcode colonyNetworkPlots, fig.height = 5, fig.cap = colonyNetCapt, fig.scap = colonyNetTitle, out.width = '0.7\\textwidth', fig.showtext = TRUE
set.seed(3)
# Area and meanColonySize are the actal input arguments
pop <- c(2000, 4000, 8000, 16000, 32000)
colonySize <- 400
colonyNumber <- pop / colonySize
area <- pop / 0.8
side <- sqrt(area)
# Make the population.
p1 <- makePop(space = side[3],
transmission = 0.1,
meanColonySize = colonySize,
nColonies = colonyNumber[1],
model = 'SIR',
events = 20,
sample = 2,
maxDistance = 100)
k1 <- sum(p1$adjacency != 0 )/p1$parameters['nColonies']
# Make the population.
p2 <- makePop(space = side[5],
transmission = 0.1,
meanColonySize = colonySize,
nColonies = colonyNumber[3],
model = 'SIR',
events = 20,
sample = 2,
maxDistance = 100)
k2 <- sum(p2$adjacency != 0 )/p2$parameters['nColonies']
# Make the population.
p3 <- makePop(space = side[3],
transmission = 0.1,
meanColonySize = colonySize,
nColonies = colonyNumber[3],
model = 'SIR',
events = 20,
sample = 2,
maxDistance = 100)
k3 <- sum(p3$adjacency != 0 )/p3$parameters['nColonies']
# Make the population.
p4 <- makePop(space = side[5],
transmission = 0.1,
meanColonySize = colonySize,
nColonies = colonyNumber[1],
model = 'SIR',
events = 20,
sample = 2,
maxDistance = 100)
k4 <- sum(p4$adjacency != 0 )/p4$parameters['nColonies']
labSz <- 1.1
bigy <- 8
bigx <- 6
titleSz <- 3
axSz <- 2
points <- 0.35
par(mfrow = c(2,2))
plotColonyNet(p1, area = side[5], cex = points, mar = c(bigx, bigy, 2, 2), alpha = 1, lowgrey = 0.2, highgrey = 0.7, col = pokepal('Charizard')[c(4, 14)])
#axis(2, col = 'grey', cex.axis = axSz, at = c(0, 50, 100, 150, 200), labels = c('0', '', '100', '', '200'), col.axis = '#a4a4a4')
axis(1)
#title(main = bquote(italic(bar(k)) ~ '='~ .(k1)), cex.main = titleSz, line = -1.18)
mtext(side = 2, line = 4, text = 'Latitude', cex = labSz, col = "#8B8B8B")
lines(x = c(0, 100, 100), y = c(100, 100, 0), lty = 2, col = 'grey')
mtext(side = 3, line = -0.3, text = 'A)', cex = 1, at = -62)
plotColonyNet(p4, area = side[5], cex = points, mar = c(bigx, 6, 2, 2), alpha = 1, lowgrey = 0.2, highgrey = 0.7, col = pokepal('Charizard')[c(4, 14)])
axis(2, col = 'grey', labels = FALSE)
axis(1, col = 'grey', labels = FALSE)
#title(main = bquote(italic(bar(k)) ~ '='~ .(k4)), cex.main = titleSz, line = -1.18)
mtext(side = 3, line = -0.3, text = 'B)', cex = 1, at = -22)
plotColonyNet(p3, area = side[5], cex = points, mar = c(bigx, bigy, 0, 2), alpha = 1, lowgrey = 0.2, highgrey = 0.7, col = pokepal('Charizard')[c(4, 14)])
axis(2, col = 'grey', cex.axis = axSz, col.axis = '#a4a4a4', at = c(0, 50, 100, 150, 200), labels = c('0', '', '100', '', '200'))
axis(1, col = 'grey', labels = FALSE)
axis(1, col = 'grey', cex.axis = axSz, col.axis = '#a4a4a4', at = c(0, 100, 200), labels = c('0', '100', '200'), line = 0.5, lwd = 0)
#title(main = bquote(italic(bar(k)) ~ '='~ .(k3)), cex.main = titleSz, line = -1.18)
mtext(side = 2, line = 4, text = 'Latitude', cex = labSz, col = "#8B8B8B")
mtext(side = 1, line = 4.4, text = 'Longitude', cex = labSz, col = "#8B8B8B")
lines(x = c(0, 100, 100), y = c(100, 100, 0), lty = 2, col = 'grey')
mtext(side = 3, line = -0.3, text = 'C)', cex = 1, at = -62)
plotColonyNet(p2, area = side[5], cex = points, mar = c(bigx, 6, 0, 2), alpha = 1, lowgrey = 0.2, highgrey = 0.7, col = pokepal('Charizard')[c(4, 14)])
axis(1, col = 'grey', labels = FALSE)
axis(1, col = 'grey', cex.axis = axSz, col.axis = '#a4a4a4', at = c(0, 100, 200), labels = c('0', '100', '200'), line = 0.5, lwd = 0)
axis(2, col = 'grey', labels = FALSE)
#title(main = bquote(italic(bar(k)) ~ '='~ .(k2)), cex.main = titleSz, line = -1.18)
mtext(side = 1, line = 4.4, text = 'Longitude', cex = labSz, col = "#8B8B8B")
mtext(side = 3, line = -0.3, text = 'D)', cex = 1, at = -22)
%%end.rcode
%%begin.rcode plotKcapt
plotKcapt <- '
Change in average metapopulation network degree ($\\bar{k}$) with increasing geographic range size.
Bars show the median, boxes show the interquartile range, vertical lines show the range and grey dots indicate outlier values.
Notches indicate the 95\\% confidence interval of the median.
All simulations had 20 groups, meaning 19 is the maximum value of $\\bar{k}$.
'
plotKtitle <- 'Change in average network degree with increasing geographic range size'
%%end.rcode
%%begin.rcode plotK, fig.cap = plotKcapt, fig.scap = plotKtitle, cache = FALSE, fig.height = 4, fig.show = TRUE, out.width = '0.7\\textwidth'
ggplot(dens1, aes(x = factor(area), y = meanK, colour = 'a', fill = 'a')) +
geom_boxplot(outlier.size = 1, size = 0.3, outlier.colour = grey(0.3),
notch = TRUE, width = 0.4, notchwidth = 0.6) +
scale_colour_manual(values = pokepal('vileplume')[4]) +
scale_fill_manual(values = pokepal('vileplume')[7]) +
stat_summary(geom = "crossbar", width = 0.2, fatten = 2,
fun.data = function(x){ return(c(y = median(x), ymin = median(x), ymax = median(x))) }) +
theme(legend.position = 'none', panel.grid.major.x = element_blank()) +
scale_x_discrete(labels = c('2.5', '5', '10', '20', '40')) +
xlab(expression(paste('Area ', (1000 %*% km^2)))) +
ylab(expression(paste('Mean degree, ', italic(bar(k))))) +
ylim(0, 20)
%%end.rcode
%%begin.rcode calcMeans
# Constant density, altered colony size
# Need to remove rows with errors to auto find classes of columns
dens1text <- readLines('Data/DensSims.csv')
rmerrors <- dens1text[!grepl('Error in', dens1text)]
rmerrors <- rmerrors[nchar(rmerrors) > 3]
dens1 <- read.csv(text = rmerrors) %>%
dplyr::select(-X)
dens1Means <- dens1 %>%
#dplyr::filter(nExtantDis > 0) %>%
group_by(transmission, colonySize, colonyNumber) %>%
summarise(success = sum(nExtantDis == 2), sampleSize = n(), pop = mean(pop)) %>%
ungroup %>%
cbind(., vary = 'colonySize', binom.confint(.$success, .$sampleSize, conf.level = 0.95, methods = "exact"))
# fit glms to each transmission value
colonySizeModel <- dens1 %>%
mutate(invasion = nExtantDis == 2 ) %>%
mutate(ValueChange = log2(colonySize / median(colonySize))) %>%
#filter(nExtantDis != 0) %>%
group_by(transmission) %>%
do(glm(invasion ~ ValueChange, data = ., family = 'binomial') %>% tidy(conf.int = TRUE))
colonySizePredictions <- dens1 %>%
mutate(invasion = nExtantDis == 2 ) %>%
mutate(ValueChange = colonySize / median(colonySize)) %>%
#filter(nExtantDis != 0) %>%
group_by(transmission) %>%
do(augment(glm(invasion ~ log2(ValueChange), data = ., family = 'binomial'),
newdata = data.frame(ValueChange = seq(min(.$ValueChange), max(.$ValueChange),
length.out = 1000)),
type.predict = 'response')) %>%
mutate(vary = 'colonySize')
# Constant density, altered colony number
dens2 <- read.csv('Data/Dens2Sims.csv') %>% dplyr::select(-X) %>% as.data.frame
dens2Means <- dens2 %>%
#dplyr::filter(nExtantDis > 0) %>%
group_by(transmission, colonySize, colonyNumber) %>%
summarise(success = sum(nExtantDis == 2), sampleSize = n(), pop = mean(pop)) %>%
ungroup %>%
cbind(., vary = 'colonyNumber', binom.confint(.$success, .$sampleSize, conf.level = 0.95, methods = "exact"))
# Fit glms to each transmission value
colonyNumberModel <- dens2 %>%
mutate(invasion = nExtantDis == 2 ) %>%
mutate(ValueChange = log2(colonyNumber / median(colonyNumber))) %>%
#filter(nExtantDis != 0) %>%
group_by(transmission) %>%
do(glm(invasion ~ ValueChange, data = ., family = 'binomial') %>% tidy(conf.int = TRUE))
colonyNumberPredictions <- dens2 %>%
mutate(invasion = nExtantDis == 2 ) %>%
mutate(ValueChange = colonyNumber / median(colonyNumber)) %>%
#filter(nExtantDis != 0) %>%
group_by(transmission) %>%
do(augment(glm(invasion ~ log2(ValueChange), data = ., family = 'binomial'),
newdata = data.frame(ValueChange = seq(min(.$ValueChange), max(.$ValueChange),
length.out = 1000)),
type.predict = 'response')) %>%
mutate(vary = 'colonyNumber')
# Constant population, altered area
pop <- read.csv('Data/PopSims.csv') %>% dplyr::select(-X) %>% as.data.frame
popMeans <- pop %>%
#dplyr::filter(nExtantDis > 0) %>%
group_by(transmission, dens) %>%
summarise(success = sum(nExtantDis == 2), sampleSize = n()) %>%
ungroup %>%
cbind(., binom.confint(.$success, .$sampleSize, conf.level = 0.95, methods = "exact"))
# fit glms to each transmission value
areaModel <- pop %>%
mutate(invasion = nExtantDis == 2 ) %>%
mutate(ValueChange = log2(dens / median(dens))) %>%
#filter(nExtantDis != 0) %>%
group_by(transmission) %>%
do(glm(invasion ~ ValueChange, data = ., family = 'binomial') %>% tidy(conf.int = TRUE))
areaPredictions <- pop %>%
mutate(invasion = nExtantDis == 2 ) %>%
mutate(ValueChange = dens / median(dens)) %>%
#filter(nExtantDis != 0) %>%
group_by(transmission) %>%
do(augment(glm(invasion ~ log2(ValueChange), data = ., family = 'binomial'),
newdata = data.frame(ValueChange = seq(min(.$ValueChange), max(.$ValueChange),
length.out = 1000)),
type.predict = 'response')) %>%
mutate(vary = 'Density')
%%end.rcode
%%begin.rcode plotCoeffsCapts
plotCoeffsCapt <- '
GLM regression coefficients for for three sets of simulations at three transmission, $\\beta$ values.
To examine whether host density or population size affects pathogen invasion more strongly we compare the orange and blue bars.
To examine whether group size or number of groups affects pathogen invasion more strongly we compare the second and third bar in each facet.
'
plotCoeffsTitle <- 'Regression coefficients'
%%end.rcode
%%begin.rcode plotCoeffs, fig.cap = plotCoeffsCapt, fig.scap = plotCoeffsTitle, out.width = '0.7\\textwidth', fig.show = TRUE, cache = FALSE, fig.height = 3.9, fig.width = 9
allModels <- rbind(areaModel %>% mutate(varied = 'Host density'),
colonyNumberModel %>% mutate(varied = 'Number of groups'),
colonySizeModel %>% mutate(varied = 'Group size')) %>%
filter(term == 'ValueChange') %>%
mutate(variedSort = factor(varied, levels = unique(varied)[c(2, 3, 1)])) %>%
mutate(Density = ifelse(varied == 'Host density', 'Host density', 'Pop. size'))
allModels$transmission <- factor(allModels$transmission, labels = c('beta == 0.1', '0.2', '0.3'))
ggplot(allModels, aes(x = variedSort, y = estimate, colour = Density)) +
facet_grid(. ~ transmission, labeller = label_parsed) +
geom_point() +
geom_errorbar(aes(ymax = conf.high, ymin = conf.low), width = 0.3) +
xlab('Population-level trait') +
ylab('Regression estimate') +
scale_colour_poke(pokemon = 'Charizard', spread = 2, guide_legend(title = '')) +
coord_flip() +
theme(legend.position = 'bottom')
%%end.rcode
%%begin.rcode transMeansCapt
transMeansCapt <- '
Comparison of the effect of host population size on probability of invasion when population size is altered by changing group size or number of groups.
Relationships are shown separately for each transmission value, $\\beta$.
It can be seen that changes in group size give a much greater increase in invasion probability than changes in the number of groups.
Note that this is the same data as Figure~3 but with the $x$-axis scaled by population size, rather than relative parameter change.
'
transMeansTitle <- 'Comparison of the probability of the affect of group size and number of groups on probability of invasion'
%%end.rcode
%%begin.rcode plotTransMeans, fig.cap = transMeansCapt, fig.scap = transMeansTitle, out.width = '0.7\\textwidth', fig.show = TRUE, cache = FALSE, fig.height = 5
# Convert to percentage change in density, colonysize or colony number.
d2 <- rbind(dens1Means %>%
mutate(ValueChange = colonySize/median(colonySize), vary = 'colonySize') %>%
dplyr::select(pop, transmission, mean, lower, upper, vary),
dens2Means %>%
mutate(ValueChange = colonyNumber/median(colonyNumber), vary = 'colonyNumber') %>%
dplyr::select(pop, transmission, mean, lower, upper, vary)
)
d2$vary <- factor(d2$vary, levels = unique(d2$vary)[c(2, 3, 1)])
d2$transmission <- factor(d2$transmission, labels = c('beta == 0.1', '0.2', '0.3'))
# Join predictions
colonySizePredictions2 <- dens1 %>%
mutate(invasion = nExtantDis == 2 ) %>%
#filter(nExtantDis != 0) %>%
group_by(transmission) %>%
do(augment(glm(invasion ~ pop, data = ., family = 'binomial'),
newdata = data.frame(pop = seq(min(.$pop), max(.$pop),
length.out = 1000)),
type.predict = 'response')) %>%
mutate(vary = 'colonySize')
colonyNumberPredictions2 <- dens2 %>%
mutate(invasion = nExtantDis == 2 ) %>%
#filter(nExtantDis != 0) %>%
group_by(transmission) %>%
do(augment(glm(invasion ~ pop, data = ., family = 'binomial'),
newdata = data.frame(pop = seq(min(.$pop), max(.$pop),
length.out = 1000)),
type.predict = 'response')) %>%
mutate(vary = 'colonyNumber')
percChangePreds2 <- rbind(colonySizePredictions2, colonyNumberPredictions2)
percChangePreds2$transmission <- factor(percChangePreds2$transmission, labels = c('beta == 0.1', '0.2', '0.3'))
ggplot(d2, aes(x = pop, y = mean, colour = vary)) +
geom_line(data = percChangePreds2, aes(x = pop, y = .fitted, colour = vary)) +
geom_point() +
geom_errorbar(aes(ymin = lower, ymax = upper),
width=.2) +
ylab('Prop. Invasions') +
xlab('Population size') +
ylim(0, 1) +
scale_colour_manual(name = "Population-level trait",
labels = c('Number of groups', 'Group Size'),
values = pokepal('Swampert', spread = 3)[2:1]) +
scale_y_continuous(breaks = c(0, 0.5, 1), labels = c('0.0', '0.5', '1.0')) +
scale_x_continuous(limits = c(0, 32000),
breaks = c(0, 1e4, 2e4, 3e4),
label = c('0', '10000', '20000', '30000')) +
facet_grid(transmission ~ ., labeller = label_parsed) +
theme(legend.position = 'bottom', legend.direction = 'vertical')
%%end.rcode