data_forage <- read.csv("../data_raw/ForagingAssayData_2021_10_08_10.03.csv")
data_forage <- data_forage %>%
mutate(Tutor = factor(ifelse(Population == Tutor_pop, 'same', 'diff'))) %>%
filter(Sex != 'dead') %>%
filter(!(ID %in% c('ALF2_1O2O.2.6', 'AHF2_1O3Y.2.2', 'ALF2_1O3O.3.3', 'ALF2_1P2Y.2.4', 'ALF2_1P2Y.2.8', 'ALF2_3G4G.1.4', 'ALF2_1P3G.4.4', 'ALF2_1O3Y.3.7', 'ALF2_1P4G.3.4'))) %>%
mutate(Sex = droplevels(Sex, c('', 'dead')))
kable(head(data_forage))
Population | ID | Sex | Mom_ID | Litter | Treatment | Pred_Tutor | Pred | Tutor_pop | Birth.Day | Day | Date | Time | Water | Latency | Attempts | Notes | Tutor |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AH | AHF2_1G4G.3.3 | F | AHF2_1G4G | 3 | pred-/same | pred-/AH | pred- | AH | 2 | 22-Mar | pred- | 16 | 17 | same | |||
AH | AHF2_1G4G.3.3 | F | AHF2_1G4G | 3 | pred-/same | pred-/AH | pred- | AH | 1 | 21-Mar | pred+ | 73 | 99 | same | |||
AH | AHF2_1G4G.6.2 | F | AHF2_1G4G | 6 | pred-/same | pred-/AH | pred- | AH | 1 | 29-Sep | 3:17 PM | pred- | 35 | 166 | first few in middle | same | |
AH | AHF2_1G4G.6.2 | F | AHF2_1G4G | 6 | pred-/same | pred-/AH | pred- | AH | 2 | 30-Sep | 3:06 PM | pred+ | 58 | 7 | same | ||
AH | AHF2_1G4P.2.1 | F | AHF2_1G4P | 2 | pred-/same | pred-/AH | pred- | AH | 2 | 3-Mar | pred- | 310 | 72 | same | |||
AH | AHF2_1G4P.2.1 | F | AHF2_1G4P | 2 | pred-/same | pred-/AH | pred- | AH | 1 | 2-Mar | pred+ | 39 | 55 | same |
First we analyze only females.
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
model_pecks <- glm.nb(Attempts ~ Population + Tutor_pop + Pred * Water, subset(data_forage, Sex == 'F'))
kable(summary(model_pecks)$coefficients)
Estimate | Std. Error | z value | Pr(>|z|) | |
---|---|---|---|---|
(Intercept) | 3.6955872 | 0.1578089 | 23.418118 | 0.0000000 |
PopulationAL | -0.9051030 | 0.1298345 | -6.971208 | 0.0000000 |
Tutor_popAL | -0.1830963 | 0.1294927 | -1.413951 | 0.1573763 |
Predpred+ | 0.2280355 | 0.1814321 | 1.256864 | 0.2088029 |
Waterpred+ | -0.3658130 | 0.1859709 | -1.967045 | 0.0491781 |
Predpred+:Waterpred+ | 0.4479214 | 0.2585255 | 1.732600 | 0.0831668 |
(NOTE: We tested interactions up to 3-way, and removed non-significant ones)
There is a significant effect of population, whereby LP fish eat less than HP fish.
Testing water may have an effect whereby fish raised in pred- water forage less in pred+ water, but that is not the case for fish raised in pred+ water.
There is no clear effect of tutor
We can now try to plot the results.
plot_forag <- data_forage %>%
filter(Sex == 'F') %>%
group_by(Population) %>%
ggplot(aes(y = Attempts, x = Pred, fill = Water)) +
geom_boxplot() + facet_wrap(~ Population) +
theme_bw()
plot_forag
## Warning: Removed 2 rows containing non-finite values (stat_boxplot).
Now we will repeat the same for males
model_pecks <- glm.nb(Attempts ~ Population + (Pred + Tutor_pop + Water)^2, subset(data_forage, Sex == 'M'))
kable(summary(model_pecks)$coefficients)
Estimate | Std. Error | z value | Pr(>|z|) | |
---|---|---|---|---|
(Intercept) | 3.1238026 | 0.1932053 | 16.1683108 | 0.0000000 |
PopulationAL | -0.5044678 | 0.1396303 | -3.6128825 | 0.0003028 |
Predpred+ | 0.0526737 | 0.2417398 | 0.2178942 | 0.8275116 |
Tutor_popAL | 0.0136720 | 0.2315790 | 0.0590384 | 0.9529216 |
Waterpred+ | -0.1157790 | 0.2326853 | -0.4975777 | 0.6187817 |
Predpred+:Tutor_popAL | 0.0168372 | 0.2806450 | 0.0599947 | 0.9521598 |
Predpred+:Waterpred+ | -0.3800185 | 0.2806144 | -1.3542373 | 0.1756607 |
Tutor_popAL:Waterpred+ | 0.4595863 | 0.2780435 | 1.6529297 | 0.0983452 |
plot_forag <- data_forage %>%
filter(Sex == 'M') %>%
group_by(Population) %>%
ggplot(aes(y = Attempts, x = Tutor_pop, fill = Water)) +
geom_boxplot() + facet_wrap(~ Population) +
theme_bw()
plot_forag
This is time-to-event data, and we will analyze it using Cox models.
First we need to convert the Latency
variable into a Surv object. We will call it time2peck
library(coxme)
## Warning: package 'survival' was built under R version 3.6.2
data_forage <- data_forage %>%
mutate(event = ifelse (Latency ==600, 0, 1),
time2peck = Surv(Latency, event = event))
Now we can run the cox model
model_latency <- coxph(time2peck ~ Population + Pred + Tutor + Water, subset(data_forage, Sex == 'F'))
kable(summary(model_latency)$coefficients)
coef | exp(coef) | se(coef) | z | Pr(>|z|) | |
---|---|---|---|---|---|
PopulationAL | -0.5806389 | 0.5595408 | 0.1173234 | -4.9490468 | 0.0000007 |
Predpred+ | 0.0692910 | 1.0717481 | 0.1157988 | 0.5983744 | 0.5495901 |
Tutorsame | 0.2660450 | 1.3047937 | 0.1174636 | 2.2649145 | 0.0235179 |
Waterpred+ | -0.0821559 | 0.9211283 | 0.1154480 | -0.7116267 | 0.4766960 |
Let’s plot the population differences crossed with water.
library(ggfortify)
## Warning: package 'ggfortify' was built under R version 3.6.2
data_forage <- data_forage %>%
mutate(popwater = factor(paste(Population, Water)))
autoplot(survfit(time2peck ~ popwater, subset(data_forage, Sex == 'F')))
And the males:
model_latency <- coxph(time2peck ~ Population + Pred + Tutor_pop + Water + Tutor_pop:Water + Population:Pred, subset(data_forage, Sex == 'M'))
kable(summary(model_latency)$coefficients)
coef | exp(coef) | se(coef) | z | Pr(>|z|) | |
---|---|---|---|---|---|
PopulationAL | -0.1627945 | 0.8497658 | 0.1680416 | -0.9687751 | 0.3326574 |
Predpred+ | 0.4191978 | 1.5207411 | 0.1855000 | 2.2598262 | 0.0238320 |
Tutor_popAL | -0.1815125 | 0.8340079 | 0.1771369 | -1.0247013 | 0.3055041 |
Waterpred+ | -0.3697676 | 0.6908949 | 0.1780368 | -2.0769162 | 0.0378093 |
Tutor_popAL:Waterpred+ | 0.3267695 | 1.3864818 | 0.2523559 | 1.2948754 | 0.1953632 |
PopulationAL:Predpred+ | -0.3543520 | 0.7016280 | 0.2557136 | -1.3857373 | 0.1658271 |
Fig1. Comparison of foraging behaviors (attacks and latency) among the two populations of origin.
fig1a <- ggplot(data_forage, aes(Population, Attempts)) +
stat_summary(fun = mean, geom = "point") +
stat_summary(fun.data = mean_se, geom = "errorbar", width = 0.07) +
theme_bw()
fig1a
## Warning: Removed 2 rows containing non-finite values (stat_summary).
## Warning: Removed 2 rows containing non-finite values (stat_summary).
missing Fig2b: latency
Fig2. Effect of testing water on the feeding attempts (attacks) of fis from different origins, sexes, and treatments.
fig2 <- data_forage %>%
drop_na(Sex) %>%
mutate(Tutor_pop = recode(Tutor_pop, "AH" = "HP", "AL" = "LP"),
Population = recode(Population, "AH" = "HP", "AL" = "LP"),
Sex = recode(Sex, "M" = "Male", "F" = "Female")) %>%
group_by(Pred, Tutor) %>%
ggplot(aes(y = Latency, x = Water, group = Pred_Tutor, col = Pred, linetype = Tutor_pop)) +
stat_summary(fun = mean, geom = "point") +
stat_summary(fun = mean, geom = "line") +
stat_summary(fun.data = "mean_se", geom = "errorbar", width = 0.1) +
facet_grid(Sex ~ Population, drop = T) +
theme_bw() + scale_colour_grey(start = 0, end = 0.7) +
labs(col = "Raising Environment", linetype ="Tutor Origin") +
theme(strip.background = element_blank(),
strip.text.x = element_text(size = 15), strip.text.y = element_text(size = 15),
axis.title.x = element_text(size = 15),
axis.title.y = element_text(size = 15),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12))
fig2
## Warning: Removed 2 rows containing non-finite values (stat_summary).
## Warning: Removed 2 rows containing non-finite values (stat_summary).
## Warning: Removed 2 rows containing non-finite values (stat_summary).
Fig3 Environment (Pred) vs. Learning (Tutor) effect.