-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResults_figures.Rmd
235 lines (202 loc) · 9.87 KB
/
Results_figures.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
---
title: "Results_figures"
author: Kristoffer Wild
date: "`r Sys.Date()`"
output:
word_document:
reference_docx: template.docx
editor_options:
chunk_output_type: console
---
``````{r setup, include=FALSE, eval = T, echo = FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
options(digits = 3)
rm(list=ls())
sessionInfo()
# Packages
pacman::p_load("dplyr", "car", "ggplot2", "ggdist", "performance", "magick", "cowplot","broom", "emmeans" ,"kableExtra","flextable")
```
# Results
```{r tick results, echo = FALSE, include = FALSE}
tick_data <- read.csv("Data/Ticks_data_final.csv")
####
# sample sizes and Yate's chi square analysis
####
# totals
n_total <- tick_data %>%
summarise(n = n())
n_sex <- tick_data %>%
group_by(Sex) %>%
summarise(total = n())
# TICK - by sex
n_tick_sex <- tick_data %>%
group_by(Sex, Ticks_Y_N) %>%
summarise(count = n())
# TICK percent - by sex
percentage_df <- left_join(n_tick_sex, n_sex, by = "Sex")
percentage_sex <- percentage_df %>%
mutate(percentage = count / total * 100) %>%
mutate_if(is.numeric, round, 0)
####
# Logistic regression SVL and tick presence males and females
####
logit_male_model <- readRDS(file = "Models/logit_male_model.RDS")%>%
tidy()
logit_female_model <- readRDS(file = "Models/logit_female_model.RDS")%>%
tidy()
####
# TEST chi square
####
sex_yates <- readRDS(file = "Models/sex_yates.rds")
sex_yates_tbl <- tidy(sex_yates) %>%
mutate(n = n_total$n)
####
# Sprint speed results: 25CM & 2M
####
# model - sprint 25
sprint_25CM <- readRDS(file = "Models/sprint_25CM.rds")
sprint_25CM_summary <- summary(sprint_25CM)
# LS mean - sprint 25
sprint_25CM_LS <- emmeans(sprint_25CM, pairwise ~ Ticks_Y_N)
sprint_25CM_LS_emmean <- as.data.frame(sprint_25CM_LS$emmeans)
sprint_25CM_LS_contrast <- as.data.frame(sprint_25CM_LS$contrasts)
# model - sprint_2M
sprint_2M <- readRDS(file = "Models/sprint_2M.rds")
sprint_2M_summary <- summary(sprint_2M)
# LS mean - sprint 25
sprint_2M_LS <- emmeans(sprint_2M, pairwise ~ Ticks_Y_N)
sprint_2M_LS_emmean <- as.data.frame(sprint_2M_LS$emmeans)
sprint_2M_LS_contrast <- as.data.frame(sprint_2M_LS$contrasts)
########
# body condition
########
bci_mod <- readRDS(file = "Models/BCI_ticks.rds")
bci_mod_summary <- as.data.frame(anova(bci_mod))
```
*3.1 | Results*
<p>A total of `r n_total[1,1]` lizards were captured (females n= `r n_sex[1,2]`; males `r n_sex[2,2]`) during the 2014 and 2015 field seasons. There was a positive relationship between male body size, and the probability of tick infection (F$_{1,51}$ = `r logit_male_model[2,2]`, p = `r logit_male_model[2,5]`), where larger males had a higher probability of tick infection than smaller males (Fig. 1A). For females, there was no relationship between body size and the probability of tick infection (F$_{1,37}$ = `r logit_female_model[2,2]`, p = `r logit_female_model[2,5]`; Fig. 1B). The probability of tick infection was highly sex-specific, with the frequency of tick infection being over 2 times higher in males (n = `r percentage_sex[4,3]`; `r percentage_sex[4,5]`%) than in females (n = `r percentage_sex[2,3]`; `r percentage_sex[2,5]`%). Females were therefore precluded from further statistical analysis because the difference in tick infections was significantly different between sex (x$^2$ = `r sex_yates_tbl[1,1]`; df = `r sex_yates_tbl[1,3]`; n = `r sex_yates_tbl[1,5]`; p = `r sex_yates_tbl[1,2]`). Infection rate for males ranged one to seven ticks per individual.Maximum sprint speed was significantly higher in uninfected lizards (LS mean = `r sprint_25CM_LS_emmean[1,2]`m/sec, 95%CI:`r sprint_25CM_LS_emmean[1,5]` - `r sprint_25CM_LS_emmean[1,6]`) in comparison to infected lizards (LS mean = `r sprint_25CM_LS_emmean[2,2]`m/sec, 95%CI:`r sprint_25CM_LS_emmean[2,5]` - `r sprint_25CM_LS_emmean[2,6]`; F$_{2,51}$ = 16.12; p = `r sprint_25CM_LS_contrast[1,6]`; Fig. 2a). Maximum 2-meter run speed was significantly higher in uninfected lizards (LS mean = `r sprint_2M_LS_emmean[1,2]`m/sec, 95%CI:`r sprint_2M_LS_emmean[1,5]` - `r sprint_2M_LS_emmean[1,6]`) than in infected lizards (LS mean = `r sprint_2M_LS_emmean[2,2]`m/sec, 95%CI:`r sprint_2M_LS_emmean[2,5]` - `r sprint_2M_LS_emmean[2,6]`; F$_{2,51}$ = 15.01; p = `r sprint_2M_LS_contrast[1,6]`; Fig. 2b). There were no differences in body condition indices between uninfected and infected lizards (F$_{2,51}$ = 0.025; p = `r bci_mod_summary[1,5]`). <p>
\newpage
```{r Fig1,echo= FALSE}
########
# Logistic regression for presence/abcense and body size in males
########
tick_data <- read.csv(file = "Data/Ticks_data_final.csv")
logit_male_dat <- tick_data %>%
filter(Sex == "M")
# Logistic regression: model summary
logit_male_model<- glm(Ticks_1Y_0N ~ SVL, data=logit_male_dat, family=binomial(link="logit"))
# Logistic regression: create a new data frame for predictions
newdata <- data.frame(SVL = seq(min(logit_male_dat$SVL),
max(logit_male_dat$SVL),
length.out = 100))
# Logistic regression: compute the fitted lines and SE's
predicitions <-predict(logit_male_model,
newdata = newdata,
type = "link",
se.fit = TRUE) %>%
data.frame() %>%
mutate(ll = fit - 1.96 * se.fit,
ul = fit + 1.96 * se.fit) %>%
select(-residual.scale, -se.fit) %>%
mutate_all(plogis) %>%
bind_cols(newdata)
# Logistic regression: plotting model
logistic_regression_males <- predicitions %>%
ggplot(aes(x = SVL)) +
geom_ribbon(aes(ymin = ll, ymax = ul),
alpha = 1/2) +
geom_line(aes(y = fit)) +
stat_dots(data = logit_male_dat %>%
mutate(Ticks = factor(Ticks_1Y_0N,
levels = c("Yes", "No"))),
aes(y = Ticks_1Y_0N,
side = ifelse(Ticks_1Y_0N == 0, "top", "bottom"),
color = Ticks_Y_N),
scale = 0.07, shape = 19) +
scale_color_manual("Tick Presence", values = c("grey", "#D55E00")) +
scale_x_continuous("SVL (mm)") +
scale_y_continuous("probability of infection",
expand = c(0, 0)) +
theme_bw() +
theme(strip.text = element_text(face = "bold"),
legend.position = "none")
# bring Legend image
Tick_image <- magick::image_read("Final_figures/Legend_LR.png") %>%
magick::image_background("none")
image <- image_fill(Tick_image, 'none')
tick_raster <- as.raster(image)
# Regression final plot
Regression_final <- ggdraw() +
draw_plot(logistic_regression_males) +
draw_image(tick_raster, scale = .185, x = -.32, y= 0.38)
#save this figure in the correct folder and bring in to knit
knitr::include_graphics("Final_figures/Figure_1.pdf")
```
Figure 1. Relationship between body size (SVL) and probability of tick infection for male (A) and female (B) Eastern Fence Lizards. The line represents the probability function from logistic regression. Raw data points are shown with circles that distinguish if lizards were infected by ticks (yellow) or lizards that were not (grey).
\newpage
```{r Fig2,echo= FALSE}
tick_data <- read.csv(file = "Data/Ticks_data_final.csv")
sprint_25cm_data <- tick_data %>%
filter(Sex == "M") %>%
select(HLL, Mass, SVL, Ticks_Y_N, Max_25cm)
# model
sprint_25cm_mod <- lm(Max_25cm ~ HLL + Ticks_Y_N, data=sprint_25cm_data)
# plot
sprint_25cm_plot <- ggplot(sprint_25cm_mod,
aes(x=HLL, y=Max_25cm,
color=Ticks_Y_N, shape=Ticks_Y_N)) +
geom_point() +
stat_smooth(method=lm, alpha = .22) +
scale_color_manual("Tick Presence", values = c("grey", "#D55E00")) +
scale_shape_manual("Tick Presence", values = c(16, 17)) +
scale_y_continuous(limits=c(1.3,4.01), breaks = seq(1.5, 4, by = .5)) +
ylab(expression("Speed"~(~ms^{"-1"}))) +
xlab("hind limb length (mm)") +
annotate("text", x = 35, y = 4.0, label = "Maximum sprint speed", fontface = "bold", size = 5)+
theme_bw() +
theme(strip.text = element_text(face = "bold"),
legend.position = "none")
# bring Legend image
Tick_image <- magick::image_read("Final_figures/Treatment_leg.png") %>%
magick::image_background("none")
image <- image_fill(Tick_image, 'none')
tick_raster <- as.raster(image)
# 25CM final plot
Sprint_25cm_final <- ggdraw() +
draw_plot(sprint_25cm_plot) +
draw_image(tick_raster, scale = .185, x = -.32, y= 0.38)
########
# ANCOVA : 2m sprint speed
# MALES
########
sprint_2m_data <- tick_data %>%
filter(Sex == "M") %>%
select(HLL, Mass, SVL, Ticks_Y_N, Max_2m)
# model
sprint_2m_mod <- lm(Max_2m ~ HLL + Ticks_Y_N, data=sprint_2m_data)
# plot
sprint_2m_plot <- ggplot(sprint_2m_mod,
aes(x=HLL, y=Max_2m,
color=Ticks_Y_N, shape=Ticks_Y_N)) +
geom_point() +
stat_smooth(method=lm, alpha = .22) +
scale_color_manual("Tick Presence", values = c("grey", "#D55E00")) +
scale_shape_manual("Tick Presence", values = c(16, 17)) +
scale_y_continuous(limits=c(.3,3), breaks = seq(.5, 3, by = .5)) +
ylab(expression("Speed"~(~ms^{"-1"}))) +
xlab("hind limb length (mm)") +
annotate("text", x = 33.3, y = 3.0, label = "2 Meter run", fontface = "bold", size = 5)+
theme_bw() +
theme(strip.text = element_text(face = "bold"),
legend.position = "none")
# add legend
Sprint_2m_final <- ggdraw() +
draw_plot(sprint_2m_plot) +
draw_image(tick_raster, scale = .185, x = -.32, y= 0.38)
# final plot with both
Final_sprint <- plot_grid(Sprint_25cm_final, Sprint_2m_final, labels = c('A', 'B'))
#save this figure in the correct folder and bring in to knit
knitr::include_graphics("Final_figures/Figure_2.pdf")
```
Figure 2. ANCOVA results of maximum sprint speed (a) and two-meter run speed (b) of male lizards. Hindlimb length (mm) was used as a covariate to remove the effect of body size on performance. The presence of ticks (yellow) significantly reduced maximum sprint speed (p < 0.01) and two-meter run speed (p = 0.02) in comparison to lizards with no ticks (grey).