-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_Performance.Rmd
2662 lines (2021 loc) · 99 KB
/
04_Performance.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Coral Performance Following Reciprocal Transplant"
author: "Serena Hackerott and Carly Travers"
date: "1/3/2024"
output:
html_notebook:
toc: yes
toc_float: yes
html_document:
toc: yes
df_print: paged
---
# Setup
```{r Setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```
### Load Packages
```{r}
##Install Packages if Needed
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("cowplot")) install.packages("cowplot")
if (!require("lubridate")) install.packages("lubridate")
if (!require("corrplot")) install.packages("corrplot")
if (!require("lme4")) install.packages("lme4")
if (!require("vegan")) install.packages("vegan")
if (!require("DHARMa")) install.packages("DHARMa")
if (!require("effectsize")) install.packages("effectsize")
if (!require("emmeans")) install.packages("emmeans")
if (!require("lmerTest")) install.packages("lmerTest")
if (!require("tidyr")) install.packages("tidyr")
if (!require("dplyr")) install.packages("dplyr")
if (!require("plotrix")) install.packages("plotrix")
if (!require("Rmisc")) install.packages("Rmisc")
if (!require("ggpubr")) install.packages("ggpubr")
##Load Packages
library(ggplot2) #Required for ggplots
library(cowplot) #Required for plotting panel figures
library(lubridate) #Required for date and time formatting
library(corrplot) #Required for correlation plot
library(lme4) #Required for mixed effects modeling
library(vegan) #Required for multivariate analysis PERM
library(DHARMa) #Required to check residuals of mixed effects models
library(effectsize) #Required for eta_squared effect sizes
library(emmeans) #Required for pairwise comparisons
library(lmerTest) #Required for p values with lme4 model summaries
library(tidyr) #Required for pivot_wider function
library(dplyr) #Required for group_by function
library(plotrix) #Required for Standard error function
library(Rmisc) #Required for SummarySE function
library(ggpubr) #Required for stat brackets
```
### Graphing Parameters
```{r}
#Note: Run "Graphing Parameters" section from 01_ExperimentalSetup.Rmd file
```
# Sample Data and Metadata
### Load and Organize Data
```{r}
##Growth
Length<-read.csv("Data/LengthFull.csv", header=TRUE)
Dates<-read.csv("Data/BonaireDates.csv", header=TRUE)
##Set date variables
Dates$Date<-as.Date(Dates$Date, format='%m/%d/%Y')
##Set factor variables
Length$Site<-factor(Length$Site, levels=c("KL", "SS"))
Length$Genotype<-factor(Length$Genotype, levels=c("AC8", "AC10", "AC12"))
Length$Orig<-factor(Length$Orig, levels=c("N", "T"))
Length$Origin<-factor(Length$Origin, levels=c("Native", "Transplant"))
##Add a Sample Set Variable
Length$Set<-paste(Length$Site, Length$Genotype, Length$Orig, sep=".")
Length$Set<-factor(Length$Set)
##Add Site.Orig variable
Length$Site.Orig<-paste(Length$Site, Length$Orig, sep=".")
Length$Site.Orig<-factor(Length$Site.Orig, levels=c("KL.N", "KL.T", "SS.N", "SS.T"))
##Bleaching Metrics
#Note: Physiological metrics calculated in 02_PhysiologyMetrics.R file
Thermal<-read.csv("Outputs/ThermData.csv", header=TRUE)
##Set factor variables
Thermal$TimeP<-factor(Thermal$TimeP, levels=c("IN", "TP1", "TP2", "TP3", "TP4"))
Thermal$Site<-factor(Thermal$Site, levels=c("KL", "SS"))
Thermal$Genotype<-factor(Thermal$Genotype, levels=c("AC8", "AC10", "AC12"))
Thermal$Orig<-factor(Thermal$Orig, levels=c("N", "T"))
Thermal$Origin<-factor(Thermal$Origin, levels=c("Native", "Transplant"))
```
# Growth
### Growth Rate TP1 to TP2
#### Calculate Days
```{r}
##Subset Dates for TP 1 and TP 2 Growth
Growth.Dates_TP1.2<-subset(Dates, Task=="Growth" & TimeP=="TP1" |
Task=="Growth" & TimeP=="TP2" )
##Convert to Wide format
Growth.Dates_TP1.2<-Growth.Dates_TP1.2 %>% pivot_wider(names_from = TimeP, values_from = Date)
##Calculate Number of Days
#TP 1 to TP2
Growth.Dates_TP1.2$TP1.2_days<-time_length(Growth.Dates_TP1.2$TP2-Growth.Dates_TP1.2$TP1, unit="days")
```
#### Calculate Total Linear Extension
```{r}
##Merge Length Data with Growth Dates
#Merges by Site column
#Adds TP1.2_days column
Growth_TP1.2<-merge(Length, Growth.Dates_TP1.2[,c(-2)], all.x=TRUE)
##Calculate Linear Extension (cm)
Growth_TP1.2$Ext_cm<-Growth_TP1.2$TL.TP2_cm-Growth_TP1.2$TL.TP1_cm
##Calculate Growth_TP1.2 Rate (cm/day)
Growth_TP1.2$TLE_cm.day<-Growth_TP1.2$Ext_cm/Growth_TP1.2$TP1.2_days
```
#### Data QC
```{r}
##Remove Corals not Measured in T1 to T2
Growth_TP1.2<-Growth_TP1.2 %>% drop_na(TLE_cm.day)
##Sample Size per Set
Growth_TP1.2 %>%
dplyr::group_by(Set) %>%
dplyr::summarize(SampleSize = length(Set))
##Check for Outliers
ggplot(Growth_TP1.2, aes(x=Set, y=TLE_cm.day)) +
geom_boxplot(alpha=0.5, shape=2, outlier.shape = NA)+
geom_jitter(shape=16, position=position_jitter(0.1))+
theme(axis.text.x = element_text(angle = 90))
```
Potential outliers have been re-measured and therefore will be retained. n=10 per Site, Genotype, Origin group
### Compare Growth Rate
```{r}
#Check normality
hist(Growth_TP1.2$TLE_cm.day)
shapiro.test(Growth_TP1.2$TLE_cm.day)
#Not normal
hist(log(Growth_TP1.2$TLE_cm.day+1))
shapiro.test(log(Growth_TP1.2$TLE_cm.day+1))
##Still not normal
##Compare generalized linear mixed effects models
TLE_TP1.2.glmr.gaus<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP1.2, family=gaussian(link="identity"))
TLE_TP1.2.glmr.gaus.l<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP1.2, family=gaussian(link="log"))
TLE_TP1.2.glmr.gaus.i<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP1.2, family=gaussian(link="inverse"))
TLE_TP1.2.glmr.gam.l<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP1.2, family=Gamma(link="log"))
TLE_TP1.2.glmr.gam.i<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP1.2, family=Gamma(link="inverse"))
TLE_TP1.2.glmr.inv<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP1.2, family=inverse.gaussian(link="1/mu^2"))
TLE_TP1.2.glmr.inv.l<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP1.2, family=inverse.gaussian(link="log"))
TLE_TP1.2.glmr.inv.i<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP1.2, family=inverse.gaussian(link="inverse"))
AIC(TLE_TP1.2.glmr.gaus, TLE_TP1.2.glmr.gaus.l, TLE_TP1.2.glmr.gaus.i, TLE_TP1.2.glmr.gam.l, TLE_TP1.2.glmr.gam.i, TLE_TP1.2.glmr.inv, TLE_TP1.2.glmr.inv.l, TLE_TP1.2.glmr.inv.i)
```
Gamma distribution with log-link has the lowest AIC.
```{r}
##Check residuals
TLE_TP1.2.glmr.gam.l_res <- simulateResiduals(fittedModel = TLE_TP1.2.glmr.gam.l, plot = F)
plot(TLE_TP1.2.glmr.gam.l_res)
```
Compare residuals across models
```{r}
##Check residuals
TLE_TP1.2.glmr.gaus.l_res <- simulateResiduals(fittedModel = TLE_TP1.2.glmr.gaus.l, plot = F)
plot(TLE_TP1.2.glmr.gaus.l_res)
```
Compare with log+1 transformed lmer model
#### LMER Model
```{r}
##Model with log +1 transformation
#Function of Site and Origin, with Genotype as a Random effect
#Interaction between Site and Origin
TLE_TP1.2.lme<-lmer(log(TLE_cm.day+1)~Origin*Site+(1|Genotype), data=Growth_TP1.2)
##Check residuals
TLE_TP1.2.lme_res <- simulateResiduals(fittedModel = TLE_TP1.2.lme, plot = F)
plot(TLE_TP1.2.lme_res)
```
Better residuals with the log+1 transformed lmer model.
```{r}
##Model results
summary(TLE_TP1.2.lme)
eta_squared(TLE_TP1.2.lme)
##Save model results
TLE_TP1.2.res<-data.frame(summary(TLE_TP1.2.lme)$coefficients[-1,])
TLE_TP1.2.res$Predictor<-c("Origin", "Site", "Origin x Site")
TLE_TP1.2.res$EtaSq<-c(eta_squared(TLE_TP1.2.lme)$Eta2)
TLE_TP1.2.res$Response<-rep("Growth", nrow(TLE_TP1.2.res))
TLE_TP1.2.res$Timepoint<-rep("TP1_2", nrow(TLE_TP1.2.res))
```
#### Pairwise
```{r}
##Pairwise Comparisons of Interest
#Native vs Transplant within a Site
TLE.pair_TP1.2<-emmeans(TLE_TP1.2.lme, pairwise~Origin | Site)
TLE.pair_TP1.2
#Calculate standardized effect sizes for pairwise comparisons
TLE.pair.es_TP1.2<-data.frame(eff_size(TLE.pair_TP1.2, sigma=sigma(TLE_TP1.2.lme), edf=df.residual(TLE_TP1.2.lme)))
TLE.pair.es_TP1.2
TLE.pair.es_TP1.2<-TLE.pair.es_TP1.2 %>% dplyr::rename(contrast.se = contrast, SE.es = SE, df.es = df)
##Save Results
TLE.pair_TP1.2.res<-merge(data.frame(TLE.pair_TP1.2$contrasts), TLE.pair.es_TP1.2[,-c(1)])
TLE.pair_TP1.2.res$Response<-rep("Growth", nrow(TLE.pair_TP1.2.res))
TLE.pair_TP1.2.res$TimeP<-rep("TP1_2", nrow(TLE.pair_TP1.2.res))
##Add Significance levels
TLE.pair_TP1.2.res$Sig<-ifelse(TLE.pair_TP1.2.res$p.value<0.001, "***",
ifelse(TLE.pair_TP1.2.res$p.value<0.01, "**",
ifelse(TLE.pair_TP1.2.res$p.value<0.05, "*",
ifelse(TLE.pair_TP1.2.res$p.value<0.1, "-", NA))))
TLE.pair_TP1.2.res
```
#### Plot Growth TP 1 to 2
```{r Plot Growth Rate TP1 to 2}
##Summary statistics by Site and Origin
TP1.2_Growth.sum<-summarySE(Growth_TP1.2, measurevar="TLE_cm.day", groupvars=c("Site", "Origin", "Site.Orig"), na.rm=TRUE)
##Plot Average Growth Rate across Treatments
TP1.2_Growth.plot<-ggplot(TP1.2_Growth.sum, aes(x=Site, y=TLE_cm.day, colour=Site.Orig)) +
scale_colour_manual(values=Orig.colors.o)+
geom_errorbar(aes(ymin=TLE_cm.day-se, ymax=TLE_cm.day+se), width=cap.sz, linewidth=bar.sz, position=position_dodge(width=0.5)) +
geom_point(size=point.sz, position=position_dodge(width=0.5))+
theme_classic()+
theme(axis.title.x = element_text(size = axis.title.sz), axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"), axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz), legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"))+
labs(x="Site and Origin", y=expression(paste('Growth Rate (cm day'^-1*")")), colour="Origin")+
ylim(0, 0.25)+
annotate("text", x=2, y=0.24, label="*", size=sig.sz, fontface="bold")+
geom_bracket(xmin=1, xmax=2, y.position=0.01, label.size=levels.sz, label="**", inherit.aes = FALSE); TP1.2_Growth.plot
```
### Percent Difference in Growth Rates
```{r}
##Summary statistics by Genotype, Origin, and Site
TP1.2_Growth.sum<-summarySE(Growth_TP1.2, measurevar="TLE_cm.day", groupvars=c("Genotype", "Origin", "Site"), na.rm=TRUE)
##Calculate Percent Difference between Native and Transplant by Genotype
TP1.2_Growth.dif<-TP1.2_Growth.sum[which(TP1.2_Growth.sum$Origin=="Native"), c(1,3,5)]
TP1.2_Growth.dif<-TP1.2_Growth.dif %>% dplyr::rename(TLE_N = TLE_cm.day)
TP1.2_Growth.dif$TLE_T<-TP1.2_Growth.sum$TLE_cm.day[which(TP1.2_Growth.sum$Origin=="Transplant")]
##SS
TP1.2_Growth.dif_SS<-subset(TP1.2_Growth.dif, Site=="SS")
TP1.2_Growth.dif_SS$Perc.Inc<-((TP1.2_Growth.dif_SS$TLE_N-TP1.2_Growth.dif_SS$TLE_T)/TP1.2_Growth.dif_SS$TLE_T)*100
TP1.2_Growth.dif_SS
##Mean and Standard Error
mean(TP1.2_Growth.dif_SS$Perc.Inc)
std.error(TP1.2_Growth.dif_SS$Perc.Inc)
##KL
TP1.2_Growth.dif_KL<-subset(TP1.2_Growth.dif, Site=="KL")
TP1.2_Growth.dif_KL$Perc.Inc<-((TP1.2_Growth.dif_KL$TLE_N-TP1.2_Growth.dif_KL$TLE_T)/TP1.2_Growth.dif_KL$TLE_T)*100
TP1.2_Growth.dif_KL
##Mean and Standard Error
mean(TP1.2_Growth.dif_KL$Perc.Inc)
std.error(TP1.2_Growth.dif_KL$Perc.Inc)
```
### Growth Rate TP3 to TP4
#### Calculate Days
```{r}
##Subset Dates for TP 3 and TP 4 Growth
Growth.Dates_TP3.4<-subset(Dates, Task=="Growth" & TimeP=="TP3" |
Task=="Growth" & TimeP=="TP4" )
##Convert to Wide format
Growth.Dates_TP3.4<-Growth.Dates_TP3.4 %>% pivot_wider(names_from = TimeP, values_from = Date)
##Calculate Number of Days
#TP 3 to TP4
Growth.Dates_TP3.4$TP3.4_days<-time_length(Growth.Dates_TP3.4$TP4-Growth.Dates_TP3.4$TP3, unit="days")
```
#### Calculate Total Linear Extension
```{r}
##Merge Length Data with Growth Dates
#Merges by Site column
#Adds TP3.4_days column
Growth_TP3.4<-merge(Length, Growth.Dates_TP3.4[,c(-2)], all.x=TRUE)
##Calculate Linear Extension (cm)
Growth_TP3.4$Ext_cm<-Growth_TP3.4$TL.TP4_cm-Growth_TP3.4$TL.TP3_cm
##Calculate Growth_TP3.4 Rate (cm/day)
Growth_TP3.4$TLE_cm.day<-Growth_TP3.4$Ext_cm/Growth_TP3.4$TP3.4_days
```
#### Data QC
```{r}
##Remove Corals not Measured in T1 to T2
Growth_TP3.4<-Growth_TP3.4 %>% drop_na(TLE_cm.day)
##Sample Size per Set
Growth_TP3.4 %>%
dplyr::group_by(Set) %>%
dplyr::summarize(SampleSize = length(Set))
##Check for Outliers
ggplot(Growth_TP3.4, aes(x=Set, y=TLE_cm.day)) +
geom_boxplot(alpha=0.5, shape=2, outlier.shape = NA)+
geom_jitter(shape=16, position=position_jitter(0.1))+
theme(axis.text.x = element_text(angle = 90))
```
### Compare Growth Rate
```{r}
#Check normality
hist(Growth_TP3.4$TLE_cm.day)
shapiro.test(Growth_TP3.4$TLE_cm.day)
#Not normal
hist(log(Growth_TP3.4$TLE_cm.day+1))
shapiro.test(log(Growth_TP3.4$TLE_cm.day+1))
##Still not normal
##Compare generalized linear mixed effects models
TLE_TP3.4.glmr.gaus<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP3.4, family=gaussian(link="identity"))
TLE_TP3.4.glmr.gaus.l<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP3.4, family=gaussian(link="log"))
TLE_TP3.4.glmr.gaus.i<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP3.4, family=gaussian(link="inverse"))
TLE_TP3.4.glmr.gam.l<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP3.4, family=Gamma(link="log"))
TLE_TP3.4.glmr.gam.i<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP3.4, family=Gamma(link="inverse"))
TLE_TP3.4.glmr.inv<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP3.4, family=inverse.gaussian(link="1/mu^2"))
TLE_TP3.4.glmr.inv.l<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP3.4, family=inverse.gaussian(link="log"))
TLE_TP3.4.glmr.inv.i<-glmer(TLE_cm.day~Origin*Site+(1|Genotype), data=Growth_TP3.4, family=inverse.gaussian(link="inverse"))
AIC(TLE_TP3.4.glmr.gaus, TLE_TP3.4.glmr.gaus.l, TLE_TP3.4.glmr.gaus.i, TLE_TP3.4.glmr.gam.l, TLE_TP3.4.glmr.gam.i, TLE_TP3.4.glmr.inv, TLE_TP3.4.glmr.inv.l, TLE_TP3.4.glmr.inv.i)
```
Gamma distribution with log-link has the lowest AIC.
```{r}
##Check residuals
TLE_TP3.4.glmr.gam.l_res <- simulateResiduals(fittedModel = TLE_TP3.4.glmr.gam.l, plot = F)
plot(TLE_TP3.4.glmr.gam.l_res)
```
Compare residuals across models
```{r}
##Check residuals
TLE_TP3.4.glmr.gaus.l_res <- simulateResiduals(fittedModel = TLE_TP3.4.glmr.gaus.l, plot = F)
plot(TLE_TP3.4.glmr.gaus.l_res)
```
Compare with log+1 transformed lmer model
#### LMER Model
```{r}
##Model with log +1 transformation
#Function of Site and Origin, with Genotype as a Random effect
#Interaction between Site and Origin
TLE_TP3.4.lme<-lmer(log(TLE_cm.day+1)~Origin*Site+(1|Genotype), data=Growth_TP3.4)
##Check residuals
TLE_TP3.4.lme_res <- simulateResiduals(fittedModel = TLE_TP3.4.lme, plot = F)
plot(TLE_TP3.4.lme_res)
```
Better residuals with the log+1 transformed lmer model.
```{r}
##Model results
summary(TLE_TP3.4.lme)
eta_squared(TLE_TP3.4.lme)
##Save model results
TLE_TP3.4.res<-data.frame(summary(TLE_TP3.4.lme)$coefficients[-1,])
TLE_TP3.4.res$Predictor<-c("Origin", "Site", "Origin x Site")
TLE_TP3.4.res$EtaSq<-c(eta_squared(TLE_TP3.4.lme)$Eta2)
TLE_TP3.4.res$Response<-rep("Growth", nrow(TLE_TP3.4.res))
TLE_TP3.4.res$Timepoint<-rep("TP3_4", nrow(TLE_TP3.4.res))
```
#### Pairwise
```{r}
##Pairwise Comparisons of Interest
#Native vs Transplant within a Site
TLE.pair_TP3.4<-emmeans(TLE_TP3.4.lme, pairwise~Origin | Site)
TLE.pair_TP3.4
#Calculate standardized effect sizes for pairwise comparisons
TLE.pair.es_TP3.4<-data.frame(eff_size(TLE.pair_TP3.4, sigma=sigma(TLE_TP3.4.lme), edf=df.residual(TLE_TP3.4.lme)))
TLE.pair.es_TP3.4
TLE.pair.es_TP3.4<-TLE.pair.es_TP3.4 %>% dplyr::rename(contrast.se = contrast, SE.es = SE, df.es = df)
##Save Results
TLE.pair_TP3.4.res<-merge(data.frame(TLE.pair_TP3.4$contrasts), TLE.pair.es_TP3.4[,-c(1)])
TLE.pair_TP3.4.res$Response<-rep("Growth", nrow(TLE.pair_TP3.4.res))
TLE.pair_TP3.4.res$TimeP<-rep("TP3_4", nrow(TLE.pair_TP3.4.res))
##Add Significance levels
TLE.pair_TP3.4.res$Sig<-ifelse(TLE.pair_TP3.4.res$p.value<0.001, "***",
ifelse(TLE.pair_TP3.4.res$p.value<0.01, "**",
ifelse(TLE.pair_TP3.4.res$p.value<0.05, "*",
ifelse(TLE.pair_TP3.4.res$p.value<0.1, "-", NA))))
TLE.pair_TP3.4.res
```
#### Plot Growth TP 3 to 4
```{r Plot Growth Rate TP3 to 4}
##Summary statistics by Site and Origin
TP3.4_Growth.sum<-summarySE(Growth_TP3.4, measurevar="TLE_cm.day", groupvars=c("Site", "Origin", "Site.Orig"), na.rm=TRUE)
##Plot Average Growth Rate across Treatments
TP3.4_Growth.plot<-ggplot(TP3.4_Growth.sum, aes(x=Site, y=TLE_cm.day, colour=Site.Orig)) +
scale_colour_manual(values=Orig.colors.o)+
geom_errorbar(aes(ymin=TLE_cm.day-se, ymax=TLE_cm.day+se), width=cap.sz, linewidth=bar.sz, position=position_dodge(width=0.5)) +
geom_point(size=point.sz, position=position_dodge(width=0.5))+
theme_classic()+
theme(axis.title.x = element_text(size = axis.title.sz), axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"), axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz), legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"))+
labs(x="Site and Origin", y=expression(paste('Growth Rate (cm day'^-1*")")), colour="Origin")+
ylim(0, 0.25)+
annotate("text", x=1, y=0.22, label="*", size=sig.sz, fontface="bold")+
annotate("text", x=2, y=0.18, label="**", size=sig.sz, fontface="bold")+
geom_bracket(xmin=1, xmax=2, y.position=0.01, label.size=levels.sz, label="***", inherit.aes = FALSE); TP3.4_Growth.plot
```
### Percent Difference in Growth Rates
```{r}
##Summary statistics by Genotype, Origin, and Site
TP3.4_Growth.sum<-summarySE(Growth_TP3.4, measurevar="TLE_cm.day", groupvars=c("Genotype", "Origin", "Site"), na.rm=TRUE)
##Calculate Percent Difference between Native and Transplant by Genotype
TP3.4_Growth.dif<-TP3.4_Growth.sum[which(TP3.4_Growth.sum$Origin=="Native"), c(1,3,5)]
TP3.4_Growth.dif<-TP3.4_Growth.dif %>% dplyr::rename(TLE_N = TLE_cm.day)
TP3.4_Growth.dif$TLE_T<-TP3.4_Growth.sum$TLE_cm.day[which(TP3.4_Growth.sum$Origin=="Transplant")]
##SS
TP3.4_Growth.dif_SS<-subset(TP3.4_Growth.dif, Site=="SS")
TP3.4_Growth.dif_SS$Perc.Inc<-((TP3.4_Growth.dif_SS$TLE_T-TP3.4_Growth.dif_SS$TLE_N)/TP3.4_Growth.dif_SS$TLE_N)*100
TP3.4_Growth.dif_SS
##Mean and Standard Error
mean(TP3.4_Growth.dif_SS$Perc.Inc)
std.error(TP3.4_Growth.dif_SS$Perc.Inc)
##KL
TP3.4_Growth.dif_KL<-subset(TP3.4_Growth.dif, Site=="KL")
TP3.4_Growth.dif_KL$Perc.Inc<-((TP3.4_Growth.dif_KL$TLE_N-TP3.4_Growth.dif_KL$TLE_T)/TP3.4_Growth.dif_KL$TLE_T)*100
TP3.4_Growth.dif_KL
##Mean and Standard Error
mean(TP3.4_Growth.dif_KL$Perc.Inc)
std.error(TP3.4_Growth.dif_KL$Perc.Inc)
```
# Write Out Growth Data
```{r}
##Growth Data dataframe
GrowthData<-Growth_TP1.2
##Specify Timepoints
GrowthData<-GrowthData %>% dplyr::rename(TP1.2_Ext_cm = Ext_cm, TP1.2_TLE_cm.day = TLE_cm.day)
##Merge with Timepoints 3 to 4
GrowthData<-merge(GrowthData, Growth_TP3.4, all=TRUE)
##Specify Timepoints
GrowthData<-GrowthData %>% dplyr::rename(TP3.4_Ext_cm = Ext_cm, TP3.4_TLE_cm.day = TLE_cm.day)
##Growth Data
write.csv(GrowthData, "Outputs/GrowthData.csv", row.names=FALSE)
```
# Thermal Tolerance
### Percent Retention
#### Subset Thermal Assay Data by Treatment
```{r}
##Control
Therm_C<-subset(Thermal, Treat=="C")
##Heated
Therm_H<-subset(Thermal, Treat=="H")
```
#### Calculate Percent Retention
Calculating retention as proportion remaining relative to corresponding control levels (0-1) for each site and genotype at each timepoint.
```{r}
##Calculate averages for Control Treatment for each Site, Genotype, and Timepoint
Therm_C<-na.omit(Therm_C)
names(Therm_C)
Therm_C.a<-aggregate(Therm_C[,c(13:15)], list(Therm_C$Site, Therm_C$Genotype, Therm_C$TimeP, Therm_C$Origin), mean, na.action = na.omit)
names(Therm_C.a)[1:4]<-c("Site", "Genotype", "TimeP", "Origin")
names(Therm_C.a)[5:7]<-paste(names(Therm_C.a)[5:7], "C", sep="_")
##Merge Control Averages with Heated Samples
#Merges by Site, Genotype, and Timepoint
Therm_H<-merge(Therm_H, Therm_C.a, all.x=TRUE )
##Calculate Proportion Retained for each Bleaching Metric relative to Control
Therm_H$Chl.prop<-round((Therm_H$Chl_ug.cm2/Therm_H$Chl_ug.cm2_C), 4)
Therm_H$Sym.prop<-round((Therm_H$Sym10.6_cm2/Therm_H$Sym10.6_cm2_C), 4)
Therm_H$PAM.prop<-round((Therm_H$Fv_Fm/Therm_H$Fv_Fm_C), 4)
##Set values >1 to 1
Therm_H$Chl.prop[which(Therm_H$Chl.prop>1)]<-1.0000
Therm_H$Sym.prop[which(Therm_H$Sym.prop>1)]<-1.0000
Therm_H$PAM.prop[which(Therm_H$PAM.prop>1)]<-1.0000
```
# Initial Heat Assay
```{r}
##Subset Initial Timepoint
Thermal_IN<-subset(Thermal, TimeP=="IN")
Thermal_IN$Site.Treat<-paste(Thermal_IN$Site, Thermal_IN$Treat, sep=".")
Thermal_IN$Site.Treat<-factor(Thermal_IN$Site.Treat, levels=c("KL.C", "KL.H", "SS.C", "SS.H"))
Therm_IN<-subset(Therm_H, TimeP=="IN")
```
### Heated vs Control
#### Symbionts
```{r}
#Check normality
hist(Thermal_IN$Sym10.6_cm2)
shapiro.test(Thermal_IN$Sym10.6_cm2)
#Not normal
hist(log(Thermal_IN$Sym10.6_cm2+1))
shapiro.test(log(Thermal_IN$Sym10.6_cm2+1))
#Normal
##Model
#Function of Site and Treatment, with Genotype as a Random effect
Sym.lme_IN<-lmer(log(Sym10.6_cm2+1)~Site*Treatment+(1|Genotype), data=Thermal_IN)
##Check residuals
Sym.lme_res_IN <- simulateResiduals(fittedModel = Sym.lme_IN, plot = F)
plot(Sym.lme_res_IN)
##Model results
summary(Sym.lme_IN)
eta_squared(Sym.lme_IN)
emmeans(Sym.lme_IN, pairwise ~ Site | Treatment)
emmeans(Sym.lme_IN, pairwise ~ Treatment | Site)
##Save model results
Sym_IN.res<-data.frame(summary(Sym.lme_IN)$coefficients[-1,])
##Add pairwise
names(Sym_IN.res)<-names(data.frame(emmeans(Sym.lme_IN, pairwise ~ Site | Treatment)$contrasts))[-c(1:2)]
Sym_IN.res<-rbind(Sym_IN.res,
data.frame(rbind(emmeans(Sym.lme_IN, pairwise ~ Site | Treatment)$contrasts[1], emmeans(Sym.lme_IN, pairwise ~ Site | Treatment)$contrasts[2], emmeans(Sym.lme_IN, pairwise ~ Treatment | Site)$contrasts[1], emmeans(Sym.lme_IN, pairwise ~ Treatment | Site)$contrasts[2]))[,-c(1:3)])
##Metadata
Sym_IN.res$Predictor<-c("Site", "Treatment", "Site x Treatment", "Control Site", "Heated Site", "KL Treatment", "SS Treatment")
Sym_IN.res$Response<-rep("Symbionts", nrow(Sym_IN.res))
Sym_IN.res$EtaSq<-c(eta_squared(Sym.lme_IN)$Eta2, rep(NA, 4))
```
```{r Plot Symbionts Initial}
##Summary statistics by Site
IN_Sym.sum<-summarySE(Thermal_IN, measurevar="Sym10.6_cm2", groupvars=c("Site", "Treatment", "Site.Treat"), na.rm=TRUE)
##Plot Average Symbionts across Treatments
IN_Sym.plot<-ggplot(IN_Sym.sum, aes(x=Site.Treat, y=Sym10.6_cm2, colour=Site)) +
scale_colour_manual(values=Site.colors.o)+
geom_errorbar(aes(ymin=Sym10.6_cm2-se, ymax=Sym10.6_cm2+se), width=cap.sz, linewidth=bar.sz, position=position_dodge(width=0.5)) +
geom_point(aes(shape=Treatment), size=point.sz, position=position_dodge(width=0.5))+
scale_shape_manual(values=c(1,16))+
theme_classic()+
theme(axis.title.x = element_text(size = axis.title.sz), axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"), axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz), legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"))+
labs(x="Site and Treatment", y=expression(paste('Symbiont Density ('*10^6,'cells cm'^-2*")")), colour="Site")+
ylim(0, 1)+
annotate("text", x=.6, y=1, hjust=0, label="Site **", size=sig.sz, fontface="bold")+
annotate("text", x=.6, y=.94, hjust=0, label="Treatment **", size=sig.sz, fontface="bold"); IN_Sym.plot
```
#### Chlorophyll
```{r}
#Check normality
hist(Thermal_IN$Chl_ug.cm2)
shapiro.test(Thermal_IN$Chl_ug.cm2)
#Not normal
hist(log(Thermal_IN$Chl_ug.cm2+1))
shapiro.test(log(Thermal_IN$Chl_ug.cm2+1))
#Still not normal but less skewed
##Model
#Function of Site and Treatment, with Genotype as a Random effect
Chl.lme_IN<-lmer(log(Chl_ug.cm2+1)~Site*Treatment+(1|Genotype), data=Thermal_IN)
##Check residuals
Chl.lme_res_IN <- simulateResiduals(fittedModel = Chl.lme_IN, plot = F)
plot(Chl.lme_res_IN)
##Model results
summary(Chl.lme_IN)
eta_squared(Chl.lme_IN)
emmeans(Chl.lme_IN, pairwise ~ Site | Treatment)
emmeans(Chl.lme_IN, pairwise ~ Treatment | Site)
##Save model results
Chl_IN.res<-data.frame(summary(Chl.lme_IN)$coefficients[-1,])
##Add pairwise
names(Chl_IN.res)<-names(data.frame(emmeans(Chl.lme_IN, pairwise ~ Site | Treatment)$contrasts))[-c(1:2)]
Chl_IN.res<-rbind(Chl_IN.res,
data.frame(rbind(emmeans(Chl.lme_IN, pairwise ~ Site | Treatment)$contrasts[1], emmeans(Chl.lme_IN, pairwise ~ Site | Treatment)$contrasts[2], emmeans(Chl.lme_IN, pairwise ~ Treatment | Site)$contrasts[1], emmeans(Chl.lme_IN, pairwise ~ Treatment | Site)$contrasts[2]))[,-c(1:3)])
##Metadata
Chl_IN.res$Predictor<-c("Site", "Treatment", "Site x Treatment", "Control Site", "Heated Site", "KL Treatment", "SS Treatment")
Chl_IN.res$Response<-rep("Chlorophyll", nrow(Chl_IN.res))
Chl_IN.res$EtaSq<-c(eta_squared(Chl.lme_IN)$Eta2, rep(NA, 4))
```
```{r Plot Chlorophyll Initial}
##Summary statistics by Site
IN_Chl.sum<-summarySE(Thermal_IN, measurevar="Chl_ug.cm2", groupvars=c("Site", "Treatment", "Site.Treat"), na.rm=TRUE)
##Plot Average Chlorophyll across Treatments
IN_Chl.plot<-ggplot(IN_Chl.sum, aes(x=Site.Treat, y=Chl_ug.cm2, colour=Site)) +
scale_colour_manual(values=Site.colors.o)+
geom_errorbar(aes(ymin=Chl_ug.cm2-se, ymax=Chl_ug.cm2+se), width=cap.sz, linewidth=bar.sz, position=position_dodge(width=0.5)) +
geom_point(aes(shape=Treatment), size=point.sz, position=position_dodge(width=0.5))+
scale_shape_manual(values=c(1,16))+
theme_classic()+
theme(axis.title.x = element_text(size = axis.title.sz), axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"), axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz), legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"))+
labs(x="Site and Treatment", y=expression(paste('Total Chlorophyll (\u03BCg cm'^-2*")")), colour="Site")+
ylim(0, 1.25)+
annotate("text", x=.6, y=1.2, hjust=0, label="Site ***", size=sig.sz, fontface="bold")+
annotate("text", x=.6, y=1.12, hjust=0, label="Treatment ***", size=sig.sz, fontface="bold")+
annotate("text", x=.6, y=1.04, hjust=0, label="Site x Treatment **", size=sig.sz, fontface="bold"); IN_Chl.plot
```
#### FvFm
```{r}
#Check normality
hist(Thermal_IN$Fv_Fm)
shapiro.test(Thermal_IN$Fv_Fm)
#Not normal
hist(Thermal_IN$Fv_Fm^2)
shapiro.test(Thermal_IN$Fv_Fm^2)
#Still not normal but less skewed
##Model
#Function of Site and Treatment, with Genotype as a Random effect
PAM.lme_IN<-lmer(Fv_Fm^2~Site*Treatment+(1|Genotype), data=Thermal_IN)
##Check residuals
PAM.lme_res_IN <- simulateResiduals(fittedModel = PAM.lme_IN, plot = F)
plot(PAM.lme_res_IN)
##Model results
summary(PAM.lme_IN)
eta_squared(PAM.lme_IN)
emmeans(PAM.lme_IN, pairwise ~ Site | Treatment)
emmeans(PAM.lme_IN, pairwise ~ Treatment | Site)
##Save model results
PAM_IN.res<-data.frame(summary(PAM.lme_IN)$coefficients[-1,])
##Add pairwise
names(PAM_IN.res)<-names(data.frame(emmeans(PAM.lme_IN, pairwise ~ Site | Treatment)$contrasts))[-c(1:2)]
PAM_IN.res<-rbind(PAM_IN.res,
data.frame(rbind(emmeans(PAM.lme_IN, pairwise ~ Site | Treatment)$contrasts[1], emmeans(PAM.lme_IN, pairwise ~ Site | Treatment)$contrasts[2], emmeans(PAM.lme_IN, pairwise ~ Treatment | Site)$contrasts[1], emmeans(PAM.lme_IN, pairwise ~ Treatment | Site)$contrasts[2]))[,-c(1:3)])
##Metadata
PAM_IN.res$Predictor<-c("Site", "Treatment", "Site x Treatment", "Control Site", "Heated Site", "KL Treatment", "SS Treatment")
PAM_IN.res$Response<-rep("FvFm", nrow(PAM_IN.res))
PAM_IN.res$EtaSq<-c(eta_squared(PAM.lme_IN)$Eta2, rep(NA, 4))
```
Not normal, but model residuals are OK.
```{r Plot FvFm Initial}
##Summary statistics by Site
IN_PAM.sum<-summarySE(Thermal_IN, measurevar="Fv_Fm", groupvars=c("Site", "Treatment", "Site.Treat"), na.rm=TRUE)
##Plot Average FvFm across Treatments
IN_PAM.plot<-ggplot(IN_PAM.sum, aes(x=Site.Treat, y=Fv_Fm, colour=Site)) +
scale_colour_manual(values=Site.colors.o)+
geom_errorbar(aes(ymin=Fv_Fm-se, ymax=Fv_Fm+se), width=cap.sz, linewidth=bar.sz, position=position_dodge(width=0.5)) +
geom_point(aes(shape=Treatment), size=point.sz, position=position_dodge(width=0.5))+
scale_shape_manual(values=c(1,16))+
theme_classic()+
theme(axis.title.x = element_text(size = axis.title.sz), axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"), axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz), legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"))+
labs(x="Site and Treatment", y="Photochemical Efficiency (Fv/Fm)", colour="Site")+
ylim(0.5, 0.655)+
annotate("text", x=.6, y=.655, hjust=0, label="Site *", size=sig.sz, fontface="bold")+
annotate("text", x=.6, y=.645, hjust=0, label="Treatment ***", size=sig.sz, fontface="bold"); IN_PAM.plot
```
### Retention by Site
#### Symbionts
```{r}
#Check normality
hist(Therm_IN$Sym.prop)
shapiro.test(Therm_IN$Sym.prop)
#Normal
##Model
#Function of Site, with Genotype as a Random effect
Tol_Sym.lme_IN<-lmer(Sym.prop~Site+(1|Genotype), data=Therm_IN)
##Check residuals
Tol_Sym.lme_res_IN <- simulateResiduals(fittedModel = Tol_Sym.lme_IN, plot = F)
plot(Tol_Sym.lme_res_IN)
##Model results
summary(Tol_Sym.lme_IN)
eta_squared(Tol_Sym.lme_IN)
##Save model results
Tol_Sym_IN.res<-data.frame(summary(Tol_Sym.lme_IN)$coefficients)
names(Tol_Sym_IN.res)<-names(Sym_IN.res)[1:5]
Tol_Sym_IN.res$Predictor<-rep("Site", nrow(Tol_Sym_IN.res))
Tol_Sym_IN.res$Response<-rep("Symbiont Retention", nrow(Tol_Sym_IN.res))
Tol_Sym_IN.res$EtaSq<-c(eta_squared(Tol_Sym.lme_IN)$Eta2)
##Combine results
Sym_IN.res<-rbind(Sym_IN.res, Tol_Sym_IN.res[2,])
```
```{r Plot Symbiont Retention Initial}
##Summary statistics by Site
IN_TolSym.sum<-summarySE(Therm_IN, measurevar="Sym.prop", groupvars=c("Site"), na.rm=TRUE)
##Plot Average Symbiont Retention across Treatments
IN_TolSym.plot<-ggplot(IN_TolSym.sum, aes(x=Site, y=Sym.prop, colour=Site)) +
scale_colour_manual(values=Site.colors.o)+
geom_errorbar(aes(ymin=Sym.prop-se, ymax=Sym.prop+se), width=cap.sz, linewidth=bar.sz, position=position_dodge(width=0.5)) +
geom_point(size=point.sz, position=position_dodge(width=0.5))+
theme_classic()+
theme(axis.title.x = element_text(size = axis.title.sz), axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"), axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz), legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"))+
labs(x="Site", y="Symbiont Retention", colour="Site")+
ylim(0, 1)+
annotate("text", x=1.5, y=0.75, label="-", size=sig.sz, fontface="bold"); IN_TolSym.plot
```
#### Chlorophyll
```{r}
#Check normality
hist(Therm_IN$Chl.prop)
shapiro.test(Therm_IN$Chl.prop)
#Normal
##Model
#Function of Site, with Genotype as a Random effect
Tol_Chl.lme_IN<-lmer(Chl.prop~Site+(1|Genotype), data=Therm_IN)
##Check residuals
Tol_Chl.lme_res_IN <- simulateResiduals(fittedModel = Tol_Chl.lme_IN, plot = F)
plot(Tol_Chl.lme_res_IN)
##Model results
summary(Tol_Chl.lme_IN)
eta_squared(Tol_Chl.lme_IN)
##Save model results
Tol_Chl_IN.res<-data.frame(summary(Tol_Chl.lme_IN)$coefficients)
names(Tol_Chl_IN.res)<-names(Chl_IN.res)[1:5]
Tol_Chl_IN.res$Predictor<-rep("Site", nrow(Tol_Chl_IN.res))
Tol_Chl_IN.res$Response<-rep("Chlorophyll Retention", nrow(Tol_Chl_IN.res))
Tol_Chl_IN.res$EtaSq<-c(eta_squared(Tol_Chl.lme_IN)$Eta2)
##Combine results
Chl_IN.res<-rbind(Chl_IN.res, Tol_Chl_IN.res[2,])
```
```{r Plot Chlorophyll Retention Initial}
##Summary statistics by Site and Origin
IN_TolChl.sum<-summarySE(Therm_IN, measurevar="Chl.prop", groupvars=c("Site"), na.rm=TRUE)
##Plot Average Chlorophyll Retention across Treatments
IN_TolChl.plot<-ggplot(IN_TolChl.sum, aes(x=Site, y=Chl.prop, colour=Site)) +
scale_colour_manual(values=Site.colors.o)+
geom_errorbar(aes(ymin=Chl.prop-se, ymax=Chl.prop+se), width=cap.sz, linewidth=bar.sz, position=position_dodge(width=0.5)) +
geom_point(size=point.sz, position=position_dodge(width=0.5))+
theme_classic()+
theme(axis.title.x = element_text(size = axis.title.sz), axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"), axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz), legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"))+
labs(x="Site", y="Chlorophyll Retention", colour="Site")+
ylim(0, 0.35); IN_TolChl.plot
```
#### FvFm
```{r}
#Check normality
hist(Therm_IN$PAM.prop)
shapiro.test(Therm_IN$PAM.prop)
#Not normal
hist(Therm_IN$PAM.prop^2)
shapiro.test(Therm_IN$PAM.prop^2)
##Still not normal
##Model
#Function of Site, with Genotype as a Random effect
Tol_PAM.lme_IN<-lmer(PAM.prop~Site+(1|Genotype), data=Therm_IN)
##Check residuals
Tol_PAM.lme_res_IN <- simulateResiduals(fittedModel = Tol_PAM.lme_IN, plot = F)
plot(Tol_PAM.lme_res_IN)
##Model results
summary(Tol_PAM.lme_IN)
eta_squared(Tol_PAM.lme_IN)
##Save model results
Tol_PAM_IN.res<-data.frame(summary(Tol_PAM.lme_IN)$coefficients)
names(Tol_PAM_IN.res)<-names(PAM_IN.res)[1:5]
Tol_PAM_IN.res$Predictor<-rep("Site", nrow(Tol_PAM_IN.res))
Tol_PAM_IN.res$Response<-rep("FvFm Retention", nrow(Tol_PAM_IN.res))
Tol_PAM_IN.res$EtaSq<-c(eta_squared(Tol_PAM.lme_IN)$Eta2)
##Combine results
PAM_IN.res<-rbind(PAM_IN.res, Tol_PAM_IN.res[2,])
```
Not normal, but model residuals are OK.
```{r Plot FvFm Retention Initial}
##Summary statistics by Site and Origin
IN_TolPAM.sum<-summarySE(Therm_IN, measurevar="PAM.prop", groupvars=c("Site"), na.rm=TRUE)
##Plot Average FvFm Retention across Treatments
IN_TolPAM.plot<-ggplot(IN_TolPAM.sum, aes(x=Site, y=PAM.prop, colour=Site)) +
scale_colour_manual(values=Site.colors.o)+
geom_errorbar(aes(ymin=PAM.prop-se, ymax=PAM.prop+se), width=cap.sz, linewidth=bar.sz, position=position_dodge(width=0.5)) +
geom_point(size=point.sz, position=position_dodge(width=0.5))+
theme_classic()+
theme(axis.title.x = element_text(size = axis.title.sz), axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"), axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz), legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"))+
labs(x="Site", y="Photochemical Efficiency Retention", colour="Site")+
ylim(0.6, 1)+
annotate("text", x=1.5, y=1, label="*", size=sig.sz, fontface="bold"); IN_TolPAM.plot
```
# Tolerance after Transplant
### TP1
```{r}
##Subset Timepoint 1
Therm_TP1<-subset(Therm_H, TimeP=="TP1")
```
#### Symbionts
```{r}
#Check normality
hist(Therm_TP1$Sym.prop)
shapiro.test(Therm_TP1$Sym.prop)
#Not normal
hist(log(Therm_TP1$Sym.prop+1))
shapiro.test(log(Therm_TP1$Sym.prop+1))
##Still not normal
##Model with no transformation
#Function of Site and Origin, with Genotype as a Random effect
#Interaction between Site and Origin
Tol_Sym.lme_TP1<-lmer(Sym.prop~Origin*Site+(1|Genotype), data=Therm_TP1)
##Check residuals
Tol_Sym.lme_res_TP1 <- simulateResiduals(fittedModel = Tol_Sym.lme_TP1, plot = F)
plot(Tol_Sym.lme_res_TP1)
##Model results
summary(Tol_Sym.lme_TP1)