-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworksSummer2021-ColonyChoice.Rmd
272 lines (224 loc) · 10.5 KB
/
NetworksSummer2021-ColonyChoice.Rmd
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
---
title: "Ant Networks Summer 2021: Colony Choice"
author: "Matina Donaldson-Matasci"
date: "6/15/2022"
output:
pdf_document:
latex_engine: xelatex
html_document: default
---
```{r setup, include=FALSE}
require(tidyverse)
require(lubridate)
require(glmmTMB)
require(sjPlot)
#theme_set(theme_test(base_size=10)) # for paper
theme_set(theme_test(base_size=14)) # for talk
nest.palette <- palette.colors(n = 9, palette = "Classic Tableau")[c(1:7,9)]
names(nest.palette) = c("A2","B3","C1","D2","E1","F1","G1","H1")
```
# Ant Networks Experiments Summer 2021: Colony Choice
## Hypotheses / Questions
In a modular, artificial tree branch populated with 8 nests, which nest(s) will colonies preferentially move into? Nest properties (volume, entrance size, darkness, etc.) are identical but the locations differ. All nests are equidistant from the colony's access point, but the geometry of the junctions and branches they must navigate differ.
Hypotheses:
1. Colonies choose nests on thicker branches
1. Colonies choose nests closer to the trunk
1. Colonies choose nests according to individual encounter rate
For each of these hypotheses, we can make two predictions: one about which nests will contain more ants in the final post-experiment census, and another about which nests will become populated first in the daily experiment checks.
## Data Description
To test these hypotheses, we'll need three different sets of data: (1) the colony experiment full census, (2) the colony experiment daily checks, and (3) the frequency with which individual ants visited each of the nests in the individual experiments.
First, let's load in the full census data. This contains counts and locations of all ants before and after each experiment.
```{r}
census <- read.csv("data/NetworksSummer2021-ColonyChoice-FullCensus.csv",
colClasses=c("Colony.Name"="factor",
"When"="factor",
"Nest"="character"),
na.strings="NA")
census <- census %>%
dplyr::select(-starts_with("X")) %>%
mutate(Date=mdy(Date)) %>%
mutate(Brood=if_else(Brood=="y",T,F)) %>%
mutate(Nest=if_else(Nest=="2111","2112",Nest)) %>% # mislabeling of nest
mutate(Nest.Label=as.numeric(Nest)) %>%
mutate(Nest.Label=factor(Nest.Label,
levels=c("321","72","1112","1221","412",
"82","2112","2212"))) %>%
rename(Census.Location=Nest) %>%
filter(When=="post")
```
To make the graphs a little easier to look at, we'll rename the colonies in order of size from smallest to largest. First, let's count the total number of ants in each colony. Then, we'll create a colony ID in order from smallest to largest.
```{r}
census %>% group_by(Colony.Name) %>%
summarize(totalAnts=sum(Workers,Soldiers, Queen, Winged.Queens, Males))
census <- census %>%
mutate(Colony.Name = factor(Colony.Name,
levels= c("21-MW3","21-BA2","21-SP3","21-SP2")
))
```
We want to join this with information about each nest.
```{r}
tips <- read.csv("data/NetworksSummer2021-TipReference.csv",
colClasses=c("Tip"="character", "Type"="factor",
"Location"="factor", "Distance.from.Trunk"="numeric"),
na.strings="")
census <- census %>% left_join(tips,by=c("Nest.Label"="Tip")) %>%
rename("Nest.Location"="Location") %>%
mutate(Branch.Level=str_length(Nest.Label))
```
Let's take a look at the number of ants in each nest after each of the colony choice experiments.
```{r}
census %>%
filter(!is.na(Nest.Label)) %>%
ggplot(aes(x=Nest.Location,y=Workers,fill=Nest.Location)) +
geom_col() +
scale_fill_manual(values=nest.palette,drop=F) +
# scale_y_log10() +
facet_grid(Colony.Name ~ .) +
xlab("Nest Location") + ylab("Number of workers") +
labs(fill="Nest Location") +
# labs(title = "Nest Choice (Colony Experiment)") +
theme(legend.position="none",plot.title = element_text(hjust = 0.5))
#ggsave("images/ColonyChoice-NumWorkers-POSTER.png",
# dpi=300, width = 8, height = 5, units = "in")
#ggsave("images/ColonyChoice-NumWorkers-PAPER.eps",
# width = 3, height = 2.5, units = "in")
ggsave("images/ColonyChoice-NumWorkers-TALK.eps",
width = 6.5, height = 7, units = "in")
```
Next, let's load in the daily checks of each nest during the experiment. This contains a qualitative assessment of the number of ants in each nest periodically during each colony choice experiment.
```{r}
daily <- read.csv("data/NetworksSummer2021-ColonyChoice-DailyChecks.csv",
colClasses=c("Colony"="factor",
"Nest"="character"),
na.strings=c("NA",""))
daily <- daily %>%
fill(Date,Experiment.Day,Time) %>%
mutate(Datetime=mdy_hm(paste(Date,Time))) %>%
mutate(Date=mdy(Date)) %>%
mutate(Experiment.Time=days(Experiment.Day)+hm(Time)) %>%
dplyr::select(-Time) %>%
rename_with(~gsub('\\.\\..*','',.x)) %>%
mutate(Colony.Name = factor(Colony,
levels= c("21-MW3","21-BA2","21-SP3","21-SP2"),
)) %>%
rename(Nest.Label=Nest) %>%
mutate(Nest.Label=if_else(Nest.Label=="2111","2112",Nest.Label)) %>% # mislabeling of nest
mutate(Number.of.ants=factor(tolower(Number.of.ants),
levels=c("none","few","many"))) %>%
mutate(Nest.Label=factor(Nest.Label,
levels=c("321","72","1112","1221","412",
"82","2112","2212"))) %>%
mutate(Brood=case_when(Brood=="y" ~ T,
Brood=="n" ~ F,
TRUE ~ F)) %>%
mutate(Queen=case_when(Queen=="y" ~ T,
Queen=="n" ~ F,
TRUE ~ F))
daily <- daily %>% left_join(tips,by=c("Nest.Label"="Tip")) %>%
rename("Nest.Location"="Location") %>%
mutate(Branch.Level=str_length(Nest.Label))
```
```{r}
checktimes <- c(0,0,1,1,2,2,3,3) + c((12+5)/24,(12+9)/24)
checktimelabels <- rep(c("5pm","9pm"), times=4)
daily %>%
filter(Number.of.ants != "none") %>%
ggplot(aes(x=as.numeric(Experiment.Time,"days"),
y=Nest.Location, color=Nest.Location,
linewidth=Number.of.ants)) +
geom_line() +
scale_color_manual(values=nest.palette,drop=F) +
scale_linewidth_manual(name="Nest occupation",
values=c(0.3,1.5), labels=c("few ants", "many ants")) +
scale_x_continuous(breaks = c(1,2,3,4), minor_breaks = checktimes) +
facet_grid(Colony.Name ~ .) +
theme(axis.text.y = element_blank(), axis.ticks.y= element_blank(),
panel.grid.minor.x = element_line(color = "grey",
linewidth = 0.25,
linetype = 1)) +
xlab("Day of Experiment") +
ylab("Nest Location") +
# labs(title = "Nest Occupation (Colony Experiment)") +
guides(color="none")
#ggsave("images/ColonyChoice-DailyCheck-POSTER.png",
# dpi=300, width = 8, height = 5, units = "in")
#ggsave("images/ColonyChoice-DailyCheck-PAPER.eps",
# width = 6.5, height = 2, units = "in")
ggsave("images/ColonyChoice-DailyCheck-TALK.eps",
width = 6.5, height = 7, units = "in")
```
## Do colonies show a preference for specific nests?
Next, let's create a model to look for a preference for specific nests. The first is based on the number of workers per nest. This shows that the highest numbers of workers were observed in nests B3 (mean 48, 95% CI 14--162) and F1 (mean 8, 95% CI 2--30).
```{r}
model.workers.bynest <- glmmTMB(Workers ~ Nest.Location +
(1|Colony.Name) -1,
family="nbinom2", data=census)
summary(model.workers.bynest)
sjPlot::tab_model(model.workers.bynest)
```
Let's also check for a preference in how often those nests were heavily occupied during the daily checks. This shows that again, nest B3 was most likely to be occupied by many ants (odds ratio 13.0, 95% CI 2.6-63.1), with nest F1 being the second most likely (odds ratio 1.1, 95% CI 0.3--4.4).
**This is not an appropriate analysis because it treats multiple timepoints within the same colony as independent measures.**
```{r}
model.daily.bynest <- glmmTMB(Number.of.ants=="many" ~ Nest.Location +
(1|Colony) - 1,
family="binomial", data=daily)
summary(model.daily.bynest)
sjPlot::tab_model(model.daily.bynest)
```
## Do colonies move more ants into nests on thicker branches?
First, I'll replot the data with a reordering of the nests in terms of total occupation.
```{r}
census %>%
filter(!is.na(Nest.Label)) %>%
ggplot(aes(x=reorder(Nest.Location,Branch.Level),y=Workers,fill=Nest.Location)) +
geom_col() +
scale_fill_manual(values=nest.palette,drop=F) +
facet_grid(Colony.Name~.) +
xlab("Nest Location") + ylab("Number of workers") +
labs(fill="Nest Location")
```
## Do colonies populate nests on thicker branches more quickly?
```{r}
daily %>%
ggplot(aes(x=as.numeric(Experiment.Time,"days"),
y=reorder(Nest.Location,Branch.Level),
color=reorder(Nest.Location,Branch.Level),
size=Number.of.ants)) +
geom_line() +
scale_color_manual(values=nest.palette,drop=F) +
scale_size_manual(values=c(0,0.25,1.5)) +
facet_grid(Colony~.) +
theme(axis.text.y = element_blank(), axis.ticks= element_blank()) +
xlab("Day of Experiment") +
ylab("Nest Location") +
labs(color="Nest Location", size="Number of ants")
```
## Do colonies move more ants into nests close to the trunk?
```{r}
census %>%
filter(!is.na(Nest.Label)) %>%
ggplot(aes(x=reorder(Nest.Location,Distance.from.Trunk),y=Workers,fill=Nest.Location)) +
geom_col() +
scale_fill_manual(values=nest.palette,drop=F) +
facet_grid(Colony.Name~.) +
xlab("Nest Location") + ylab("Number of workers") +
labs(fill="Nest Location")
```
## Do colonies populate nests near the trunk more quickly?
```{r}
daily %>%
ggplot(aes(x=as.numeric(Experiment.Time,"days"),
y=reorder(Nest.Location,Distance.from.Trunk),
color=reorder(Nest.Location,Distance.from.Trunk),
size=Number.of.ants)) +
geom_line() +
scale_color_manual(values=nest.palette,drop=F) +
scale_size_manual(values=c(0,0.25,1.5)) +
facet_grid(Colony~.) +
theme(axis.text.y = element_blank(), axis.ticks= element_blank()) +
xlab("Day of Experiment") +
ylab("Nest Location") +
labs(color="Nest Location", size="Number of ants")
```
## Do colonies move more ants into nests with a higher individual encounter rate?
## Do colonies populate nests with a higher individual encounter rate more quickly?