-
Notifications
You must be signed in to change notification settings - Fork 1
/
Appendix4.Rtex
187 lines (130 loc) · 6.64 KB
/
Appendix4.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
%--------------------------------------------------------------------------------------------------------------------------------%
% Code for "Appendix C: A mechanistic model to compare the importance of interrelated population measures: population size, population density and colony size"
% Appendix for Chapter 4 of thesis "The role of population structure and size in determining bat pathogen richness"
% by Tim CD Lucas
%
%---------------------------------------------------------------------------------------------------------------------------------%
%%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 = '.AppCh4Cache/', fig.path = 'figure/C-')
source('misc/KnitrOptions.R')
# ggplot2 theme.
source('misc/theme_tcdl.R')
theme_set(theme_grey() + theme_tcdl)
library(xtable)
%%end.rcode
%%begin.rcode rawDataTables, cache = FALSE
dens1 <- read.csv('data/Chapter4/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),
Sims = n()) %>%
rename(`$\\beta$` = transmission, `$n$` = colonySize, `$m$` = colonyNumber)
# Constant density, altered colony number
dens2 <- read.csv('data/Chapter4/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),
Sims = n()) %>%
rename(`$\\beta$` = transmission, `$n$` = colonySize, `$m$` = colonyNumber)
# Constant population, altered area
pop <- read.csv('data/Chapter4/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),
Sims = n()) %>%
ungroup %>%
select(-area, -transmission)
%%end.rcode
% ----------------------------------------------- %
% Print tables
% ----------------------------------------------- %
%%begin.rcode pop, results = 'asis'
popTitle <- "
Raw data for range size simulations
"
popCapt <- "
Raw data for range size simulations.
The population parameters are shown along with the number of invasions and the number of simulations.
Note that simulations where both pathogens went extinct have been removed (100 simulations were originally run for each parameter set).
$\\beta$ is the transmission rate, $n$ is colony size, $m$ is the number of colonies 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, 0),
align = c('r', '@{}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 colony size simulations
"
dens1Capt <- "
Raw data for colony size simulations.
The population parameters are shown along with the number of invasions and the number of simulations.
Note that simulations where both pathogens went extinct have been removed (100 simulations were originally run for each parameter set).
$\\beta$ is the transmission rate, $n$ is colony size, $m$ is the number of colonies 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, 0),
align = c('r', '@{}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 colonies simulations
"
dens2Capt <- "
Raw data for number of colonies simulations.
The population parameters are shown along with the number of invasions and the number of simulations.
Note that simulations where both pathogens went extinct have been removed (100 simulations were originally run for each parameter set).
$\\beta$ is the transmission rate, $n$ is colony size, $m$ is the number of colonies 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, 0),
align = c('r', '@{}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