-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworksSummer2021-ColonyMovement.Rmd
219 lines (188 loc) · 7.64 KB
/
NetworksSummer2021-ColonyMovement.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
---
title: "Colony Movement Analysis"
author: "Matina Donaldson-Matasci"
date: "2024-05-07"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
require(tidyverse)
require(broom)
require(ggthemes)
require(grDevices)
require(lme4)
require(glmmTMB)
require(bbmle) #for AICtab
# theme_set(theme_test(base_size=18)) # For poster
# 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)]
nest.names <- c("A2","B3","C1","D2","E1","F1","G1","H1")
names(nest.palette) = nest.names
```
## Hypotheses / Questions
We would like to explore the movement and turning choices of individual ants moving through a branch maze when they are in a colony context. Some questions:
1. Do the turning choices (left, right, u-turn) at individual junctions match those that were observed in the individual movement trials? If not, are they more extreme? This could indicate positive feedback.
2. How do the turning choices at individual junctions change over time? Do they become more extreme? This is another, stronger indicator of positive feedback.
3. What is the proportion of arrivals at each nest? Do the overall numbers match what's expected from the individual movement trials? If not, are they more concentrated at specific nests?
4. What is the temporal pattern of arrivals at each nest? Are arrivals temporally autocorrelated?
## Nest arrivals
First, let's load in the colony-level tracking data. This gives information on all the turns taken within the first 30 minutes of the colony experiment.
```{r}
BA2 <- read.csv("data/BA2-Colony-90min-edges.csv")
SP2 <- read.csv("data/SP2-Colony-90min-edges.csv")
MW3 <- read.csv("data/MW3-Colony-90min-edges.csv")
SP3 <- read.csv("data/SP3-Colony-90min-edges.csv")
colony_turns <- bind_rows("21-BA2" = BA2, "21-SP2" = SP2,
"21-MW3" = MW3, "21-SP3" = SP3,
.id="Colony") %>%
mutate(Colony = factor(Colony,
levels= c("21-MW3","21-BA2","21-SP3","21-SP2"),
))
colony_turns <- colony_turns %>%
mutate(Junction = as.numeric(str_sub(roi, 5, -1))) %>%
mutate(Direction.From = case_when(
edge0 == "Left" ~ "left",
edge0 == "Right" ~ "right",
edge0 == "Base" ~ "main"
)) %>%
mutate(Direction.To = case_when(
edge1 == "Left" ~ "left",
edge1 == "Right" ~ "right",
edge1 == "Base" ~ "main"
))
turns <- read.csv("data/NetworksSummer2021-Turns.csv")
colony_turn_choices <- colony_turns %>%
left_join(turns,
by=c("Junction", "Direction.From", "Direction.To"))
```
Now let's just filter out turns where ants are headed toward a nest. We can use this to plot a running tally of arrivals at each nest over time.
```{r}
tip_ref <- read.csv("data/NetworksSummer2021-TipReference.csv")
colony_nest_arrivals <- colony_turn_choices %>%
left_join(tip_ref,
by=c("Node.To" = "Tip")) %>%
filter(Type=="nest") %>%
group_by(Colony,Location) %>%
mutate(Tally=1) %>%
mutate(Cumulative.Arrivals = cumsum(Type=="nest"))
colony_nest_arrivals %>%
ggplot(aes(x=t1,y=Cumulative.Arrivals,color=Location)) +
geom_line() +
scale_color_manual(values=nest.palette,drop=F) +
xlab("Time after experiment start (min)") +
ylab("Cumulative arrivals at nest") +
facet_wrap(. ~ Colony, scales="free_y")
```
We could also try to include the nest departures to get a kind of running tally.
```{r}
colony_nest_departures <- colony_turn_choices %>%
left_join(tip_ref,
by=c("Node.From" = "Tip")) %>%
filter(Type=="nest") %>%
group_by(Colony,Location) %>%
mutate(Tally=-1) %>%
mutate(Cumulative.Departures = -cumsum(Type=="nest"))
colony_nest_tally <- bind_rows(colony_nest_arrivals,
colony_nest_departures) %>%
group_by(Colony) %>%
arrange(t0, .by_group=TRUE) %>%
group_by(Colony,Location) %>%
mutate(Cumulative.Tally = cumsum(Tally))
colony_nest_tally %>%
ggplot(aes(x=t1,y=Cumulative.Tally,color=Location)) +
geom_line() +
scale_color_manual(values=nest.palette,drop=F) +
xlab("Time after experiment start (min)") +
ylab("Cumulative tally at nest") +
facet_wrap(. ~ Colony, scales="free_y")
```
This doesn't look great, we should not have negative numbers here. Hmmm.
```{r}
colony_tip_arrivals <- colony_turn_choices %>%
inner_join(tip_ref,
by=c("Node.To" = "Tip")) %>%
group_by(Colony,Location) %>%
mutate(Type = case_when(Type=="empty" ~ "other",
Type=="tag" ~ "other",
.default = Type)) %>%
mutate(Type = factor(Type,
levels = c("nest", "trunk",
"water", "sugar",
"other"))) %>%
separate_wider_position(Location, widths=c(Section=1),
too_many="drop",
cols_remove=FALSE) %>%
mutate(Tally=1) %>%
mutate(Cumulative.Arrivals = cumsum(Tally))
#tip.palette <- rep("grey", nrow(tip_ref))
#tip.palette <- rep(nest.palette, each=4)
section.palette <- nest.palette
names(section.palette) <- LETTERS[0:8]
#tip.palette[names(nest.palette)] <- nest.palette
tip.linetypes <- c(nest=1,water=2,sugar=3,other=4,trunk=6)
tip.linewidths <- c(nest=1,water=0.5,sugar=0.5,other=0.5,trunk=1)
colony_tip_arrivals %>%
ggplot(aes(x=t1,y=Cumulative.Arrivals,color=Section,
linetype = Type, linewidth = Type)) +
geom_line() +
scale_color_manual(values=section.palette) +
scale_linetype_manual(values=tip.linetypes) +
scale_linewidth_manual(values=tip.linewidths) +
xlab("Time after experiment start (min)") +
ylab("Cumulative arrivals at branch tips") +
facet_grid(Colony~., scales="free_y")
ggsave("images/ColonyChoice-Tracking90min-TALK.eps",
width = 6.5, height = 7, units = "in")
```
Let's try to plot what's happening at all the different junctions.
```{r}
colony_turn_choices <- colony_turn_choices %>%
mutate(
Branch.From = case_when(
Direction.From == "main" ~ "main",
Direction.From == "left" & Junction.Handedness == "LH" ~ "secondary",
Direction.From == "left" & Junction.Handedness == "RH" ~ "primary",
Direction.From == "right" & Junction.Handedness == "LH" ~ "primary",
Direction.From == "right" & Junction.Handedness == "RH" ~ "secondary"
)
) %>%
group_by(Colony, roi, Branch.From) %>%
mutate(
Angle.Numeric = case_when(
Turn.Angle == "shallow" ~ 1,
Turn.Angle == "sharp" ~ -1,
.default = 0),
Angle.Tally = cumsum(Angle.Numeric)
) %>%
separate_wider_delim(roi, "_", names=c(NA,"roi.Number"),
cols_remove=FALSE) %>%
mutate(roi.Section = case_when(
str_starts(roi.Number, "3") ~ "A",
str_starts(roi.Number, "5") ~ "B",
str_starts(roi.Number, "7") ~ "B",
str_starts(roi.Number, "11") ~ "C",
str_starts(roi.Number, "12") ~ "D",
str_starts(roi.Number, "4") ~ "E",
str_starts(roi.Number, "8") ~ "F",
str_starts(roi.Number, "6") ~ "F",
str_starts(roi.Number, "21") ~ "G",
str_starts(roi.Number, "22") ~ "H",
.default = "none"
)) %>%
mutate(roi.Depth = as.character(str_length(roi.Number)))
section.palette = c("Grey",nest.palette)
names(section.palette) = c("none", LETTERS[0:8])
colony_turn_choices %>%
ggplot(aes(x=t0, y=Angle.Tally, color=roi.Section, linetype=roi.Depth)) +
geom_line(aes(group=roi.Number)) +
scale_color_manual(values=section.palette, drop=F) +
facet_grid(Colony ~ Branch.From, scales="free_y")
```
```{r}
colony_turn_choices %>%
filter(Colony == "21-SP2") %>%
ggplot(aes(x=t0, y=Angle.Tally, color=Branch.From)) +
geom_line() +
facet_wrap(vars(roi.Number))
```