-
Notifications
You must be signed in to change notification settings - Fork 0
/
MI.rmd
257 lines (194 loc) · 8.38 KB
/
MI.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
---
title: "Mitotic Indices analyses"
author: "Kira Turnham"
date: "12/16/2022"
---
```{r}
library(tidyverse)
library(ggpubr)
library(dplyr)
library(ggplot2)
library(grid)
library(fBasics)
library(tidyr)
library(reshape2)
library(agricolae)
library(Rmisc)
library(gdata)
library(rlist)
library("ggsci")
library(MASS)
library (splines)
library(lmerTest)
library(emmeans)
dat=read.csv("MI.data.csv")
datum<-na.omit(dat)
#assign spp. colors
group.colors <- c("Clatusorum"= "#8b5e3c", "Dglynnii"= "#fbb040")
#subset data according to different experiments
time<-subset(dat, expt == "overtime")
seasonal_all<-subset(datum, peak = 930)
seasonal<-seasonal_all[!(seasonal_all$treatment=="heated"),]
heated<-subset(datum, expt == "thermal")
#summarize data
sum.time<-summarySE(time, measurevar="perc.dividing", groupvars=c( "tod", "sym.spp"))
sum.seasonal<-summarySE(seasonal, measurevar="perc.dividing", groupvars=c("sym.spp", "season"))
# sym.spp season N perc.dividing sd se ci
#1 Clat summer 36 1.109313 0.836785 0.1394642 0.2831273
#2 Clat winter 12 5.401673 2.308938 0.6665330 1.4670293
#3 Dglynnii summer 60 7.820687 5.132804 0.6626421 1.3259438
#4 Dglynnii winter 12 3.168082 1.652788 0.4771187 1.0501311
sum.heated<-summarySE(heated, measurevar="perc.dividing", groupvars=c("sym.spp", "treatment"))
# sym.spp treatment N perc.dividing sd se ci
#1 Clat control 12 1.1823396 0.7012431 0.2024314 0.4455486
#2 Clat heated 12 0.4492592 0.3479834 0.1004542 0.2210981
#3 Dglynnii control 24 4.4927022 1.3357705 0.2726630 0.5640464
#4 Dglynnii heated 24 11.5860321 6.1437878 1.2540954 2.5942941
```
```{r setup, include=FALSE}
#plot mitotic indices thorughout day
sum.time1<-na.omit(sum.time)
sum.time1$tod <- as.factor(sum.time1$tod)
plot<- ggplot(sum.time,aes(x=tod,y=perc.dividing,color=sym.spp))+
#geom_line(y=perc.dividing, ymin=perc.dividing-se, ymax=perc.dividing+se)+
geom_point()+
geom_line()+
geom_errorbar(aes(ymin=perc.dividing-sd, ymax=perc.dividing+sd), width=.2,
position=position_dodge(0.05))
theme_classic()+
labs(x=('Time of day (h)'),y=('Average percent of dividing cells'), title = 'Summer mitotic indices thoughout a day')+
labels = c(expression(italic("C. latusorum")), (expression(italic("D. glynnii"))))+
geom_errorbar(aes(ymin="perc.dividing"-sd, ymax="perc.dividing"+sd), width=.1)
# #smoothed line of dividing cells thorugohut the day in colonies with Clat or Dglynnii
MIp<-ggplot(time, aes(x=tod,y=perc.dividing, colour=sym.spp, group=sym.spp)) +
stat_smooth(method="loess", formula=perc.dividing ~ tod, span=0.1, se=TRUE, aes(fill=sym.spp), alpha=0.3) +
theme_bw()+
scale_fill_manual(group.colors)+
geom_smooth()
stat_smooth(mapping = NULL, data = NULL, geom = "smooth",
position = "identity", method = "auto",
formula = y ~ x, se = TRUE, n = 80, fullrange = FALSE,
level = 0.95, na.rm = FALSE, ...)
#another visual
MIp<-ggplot(sum.time, aes(x=tod,y=perc.dividing, colour=sym.spp)) +
geom_point() +
geom_line()+
theme_bw()+
scale_fill_manual(group.colors)
```
```{r setup, include=FALSE}
# #barplot for seasonal measurements of mitotic indices, here w/ SD
plotseason <- ggplot(data=sum.seasonal, aes(x=season,y=perc.dividing,fill=sym.spp))+
geom_bar(position="dodge",stat='identity')+
labs(x="Symbiont species",y='Percent of dividing cells', title = "Seasonal mitotic indices")+
theme_classic()+
theme(legend.position="none")+
geom_errorbar(aes(ymin=perc.dividing-sd, ymax=perc.dividing+sd), width=.2,
position=position_dodge(.9))+
theme(legend.position="right") +
scale_fill_manual(values=c("#48404d","lightsalmon"), name="Symbiont spp.",
labels = c(expression(italic("C. latusorum")), (expression(italic("D. glynnii")))))+
ylim(0, 10)
#lmer testing for seasonal MI data
season_lmer<- lmer(perc.dividing ~ season * sym.spp + (1|colony) + (1|rep), data=seasonal)
step(season_lmer, reduce.random = F) #tests model factors by AIC
anova(season_lmer)
#post hoc comparisons with emmeans
print(emmeans(season_lmer, list(pairwise ~ sym.spp|season)), adjust = c('mvt'))
print(emmeans(season_lmer, list(pairwise ~ season|sym.spp)), adjust = c('mvt'))
#line graph for seasonal MI data (another visual representation of change)
lineseasonal<- ggplot(sum.seasonal,aes(x=season,y=perc.dividing,group=sym.spp, color=sym.spp))+
geom_line()+
theme_classic()+
geom_errorbar(aes(ymin=perc.dividing-ci, ymax=perc.dividing+ci), width=.1)+
scale_fill_manual(group.color)
```
```{r setup, include=FALSE}
#barplot for mitotic indices during thermal experiment
plotheat <- ggplot(data=sum.heated, aes(x=treatment,y=perc.dividing, fill=sym.spp))+
geom_bar(position="dodge",stat='identity')+
labs(x="Treatment",y='Percent of dividing cells', title = "Mitotic indices during thermal experiment")+
theme_classic()+
theme(legend.position="none")+
geom_errorbar(aes(ymin=perc.dividing-sd, ymax=perc.dividing+sd), width=.2,
position=position_dodge(.9))+
theme(legend.position="right") +
scale_fill_manual(values=c("#48404d","lightsalmon"), name="Symbiont spp.",
labels = c(expression(italic("C. latusorum")), (expression(italic("D. glynnii")))))+
ylim(0, 20)
#lmer testing for heat treatment
heat_lmer<- lmer(perc.dividing ~ treatment * sym.spp + (1|colony) + (1|rep), data=heated)
step(heat_lmer, reduce.random = F) #tests model factors by AIC
anova(heat_lmer)
#post hoc comparisons with emmeans
print(emmeans(heat_lmer, list(pairwise ~ sym.spp|treatment)), adjust = c('mvt'))
print(emmeans(heat_lmer, list(pairwise ~ treatment|sym.spp)), adjust = c('mvt'))
#line plot of thermal experiment
linethermal<- ggplot(sum.heated,aes(x=treatment,y=perc.dividing,group=sym.spp, color=sym.spp))+
geom_line()+
theme_classic()+
geom_errorbar(aes(ymin=perc.dividing-ci, ymax=perc.dividing+ci), width=.1)+
scale_fill_manual(group.color)
#test normality of residuals vs .
with(time, shapiro.test(perc.dividing[sym.spp == "Dglynnii"]))# p = 0.4602
# Shapiro-Wilk normality test for Clat's perc. dividing seasonal
with(time, shapiro.test(perc.dividing[sym.spp == "Clatusorum"])) # p = 0.7543
```
```{r}
###CHECK ASSUMPTIONS
#check for outliers
seasonal %>%
group_by(season, sym.spp) %>%
identify_outliers(perc.dividing)
seasonal_nooutliers<-seasonal_all[!(seasonal_all$perc.dividing=="10.791367"),]
seasonal_nooutliers2<-seasonal_all[!(seasonal_all$perc.dividing=="7.407407"),]
df2<-subset(seasonal_nooutliers, perc.dividing!="7.407407")
sno_outliers<- seasonal_nooutliers[-c(96), ]
sno_outliers %>%
group_by(season, sym.spp) %>%
identify_outliers(perc.dividing)
seasonal %>%
group_by(season, sym.spp) %>%
shapiro_test(perc.dividing)
ggqqplot(seasonal, "perc.dividing", ggtheme = theme_bw())+
facet_grid(season~sym.spp, labeller ="label_both")
res.aov <- aov(perc.dividing ~ season + sym.spp + season:sym.spp, data = df)
summary(res.aov)
# Df Sum Sq Mean Sq F value Pr(>F)
#season 1 4.69 4.69 1.68 0.199
#sym.spp 1 87.89 87.89 31.51 2.77e-07 ***
#season:sym.spp 1 157.84 157.84 56.59 6.93e-11 ***
#Residuals 80 223.15 2.79
#---
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
seasonaldata <- tibble::rowid_to_column(seasonal, "ID")
df <- seasonaldata %>%
dplyr::select(ID, sym.spp, perc.dividing, season)
df <- df %>%
dplyr::group_by(ID, sym.spp, season) %>%
dplyr::summarise(perc.dividing = mean(perc.dividing))
df <- df %>%
convert_as_factor(ID, sym.spp, season)
df$Time <- as.numeric(df$perc.dividing)
df <- ungroup(df)
heated %>%
group_by(treatment, sym.spp) %>%
identify_outliers(perc.dividing)
#outliers present, colony 108
# look at outliers when remove colony 108
heated_no108<-heated[!(heated$X=="colony108?"),]
heated_no108 %>%
group_by(treatment, sym.spp) %>%
identify_outliers(perc.dividing)
#outliers present
heated_no108 %>%
group_by(treatment, sym.spp) %>%
shapiro_test(perc.dividing)
#all are normal except D. glynnii in heated
#visualize normality with qqplot
ggqqplot(heated, "perc.dividing", ggtheme = theme_bw())+
facet_grid(treatment~sym.spp, labeller ="label_both")
ggqqplot(heated_no108, "perc.dividing", ggtheme = theme_bw())+
facet_grid(treatment~sym.spp, labeller ="label_both")
#both are appox equal distributions
```