-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITS_R_statistical_analyses.Rmd
2337 lines (1762 loc) · 93.1 KB
/
ITS_R_statistical_analyses.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: "Statistical analyses for *The mycobiota of faeces from the critically endangered k\u101k\u101p\u14d and associated nest litter*"
author: "A.G. West"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Load packages into session, and print package version.
```{r results='hide'}
library(ggplot2); packageVersion("ggplot2")
library(phyloseq); packageVersion("phyloseq")
library(gridExtra); packageVersion("gridExtra")
library(ggsignif); packageVersion("ggsignif")
library(ggrepel); packageVersion("ggrepel")
library(ggsci); packageVersion("ggsci")
library(hrbrthemes); packageVersion("hrbrthemes")
library(tidyverse); packageVersion("tidyverse")
library(viridis); packageVersion("viridis")
library(dplyr); packageVersion("dplyr")
library(extrafont); packageVersion("extrafont")
library(data.table); packageVersion("data.table")
library(Manu); packageVersion("Manu")
set.seed(100)
```
#Import data
```{r}
ASV_table <- fread("ITS_ASV_table.txt")
ASV_table <- data.frame(ASV_table, row.names = 1)
OTU <- otu_table(ASV_table, taxa_are_rows = F) #create a phyloseq OTU object
sum(rowSums(OTU))
mean(rowSums(OTU))
sd(rowSums(OTU))
```
```{r}
taxa <- read.table("ITS_taxa_table.txt")
taxa$Family[is.na(taxa$Family)]="Unclassified"
taxa$Genus[is.na(taxa$Genus)]="Unclassified"
taxa$Species[is.na(taxa$Species)]="unclassified"
taxa$Taxonomy <- paste(taxa$Genus, taxa$Species, sep=" ")
taxmatrix <- as.matrix(taxa) #make sure its a matrix
TAX <- tax_table(taxmatrix) # create a phyloseq TAXA table
```
```{r}
map <- read.table("ITS_map.txt",header = TRUE, sep = '\t')
rownames(map) <- map$SAMPLEID
map <- sample_data(map)
setdiff(rownames(OTU), rownames(map))
rownames(map) == rownames(OTU)
map <- map[rownames(OTU),]
identical(rownames(OTU), rownames(map))
```
#Phyloseq
Create a phyloseq object for downstream analyses:
```{r}
ps <- phyloseq(TAX, map,
OTU)
ps
ps = subset_samples(ps, SAMPLEID != "FHHNA-07-3" & SAMPLEID != "FHNA-07-3D" & SAMPLEID != "FB3A-20-2D" & SAMPLEID != "FHI2A-21-2")
ps
psF = subset_samples(ps, Type != "Litter")
psF
psN = subset_samples(ps, Type != "Faecal")
psN
```
##Filtering with phyloseq
####Taxonomic filtering
Use to filter out non-target taxa e.g. mitochondria etc.
```{r}
# Show available ranks in the dataset
rank_names(ps)
ps_tax_table <- as.data.frame(tax_table(ps))
sum(is.na(ps_tax_table$Phylum)) #85 counts of 2137 taxa = 3.97% >> 2044346 reads spanning 2137 fungi taxa
str(ps_tax_table$Phylum)
sapply(ps_tax_table, n_distinct)
levels(factor(ps_tax_table$Kingdom))
plyr::count(ps_tax_table$Kingdom)
```
```{r}
ps_tax_table[is.na(ps_tax_table)]="Unclassified"
asv_table_ps<-as.data.frame(t(otu_table(ps)))
asv_table_wTax_ps <- cbind(asv_table_ps, ps_tax_table)
Phyla.sum.ps<-aggregate(asv_table_wTax_ps[,1:177], list(asv_table_wTax_ps$Phylum),sum)
row.names(Phyla.sum.ps)<- Phyla.sum.ps$Group.1
Phyla.sum.ps$Group.1 <- NULL
sum(rowSums(Phyla.sum.ps))
rowSums(Phyla.sum.ps != 0) #number of samples each phylum occurs in
P_rowsum.ps <- rowSums(Phyla.sum.ps)
P_rowsum.ps #number of reads per phylum
dir.create("MS_FINAL")
dir.create("MS_FINAL/tables")
write.csv(P_rowsum.ps, "MS_FINAL/tables/fungi_P_rowsum_ps.csv")
genus.sum.ps<-aggregate(asv_table_wTax_ps[,1:177], list(asv_table_wTax_ps$Genus),sum)
row.names(genus.sum.ps)<- genus.sum.ps$Group.1
genus.sum.ps$Group.1 <- NULL
sum(rowSums(genus.sum.ps))
G_rowsum.ps <- rowSums(genus.sum.ps)
write.csv(G_rowsum.ps, "MS_FINAL/tables/G_rowsum_ps.csv")
write.csv(genus.sum.ps, "MS_FINAL/tables/genus_sums_ps.csv")
```
```{r}
psF0 <- subset_taxa(psF, !is.na(Phylum) & !Phylum %in% c("", "uncharacterized"))
phyla2Filter = c("<NA>")
psF1 = subset_taxa(psF0, !Phylum %in% phyla2Filter)
psN0 <- subset_taxa(psN, !is.na(Phylum) & !Phylum %in% c("", "uncharacterized"))
phyla2Filter = c("<NA>")
psN1 = subset_taxa(psN0, !Phylum %in% phyla2Filter)
```
####Filter low-abundance ASVs
```{r}
# Transform to relative abundance
minTotRelAbun = 1e-5
x = taxa_sums(psF1)
keepTaxa = (x / sum(x)) > minTotRelAbun
psF2 = prune_taxa(keepTaxa, psF1)
psF2
NtaxaF <- tax_table(psF2)
x = taxa_sums(psN1)
keepTaxa = (x / sum(x)) > minTotRelAbun
psN2 = prune_taxa(keepTaxa, psN1)
psN2
NtaxaN <- tax_table(psN2)
```
#SRS
```{r}
library(SRS)
##Samples should be arranged columnwise
###Faecal###
srs.otuF = data.frame(t(otu_table(psF2)))
#SRS.shiny.app(srs.otuF)
SRS_outputF <- SRS(srs.otuF, Cmin = 500) #14 samples discarded
SRS_outputF.df = data.frame(t(SRS_outputF))
colnames(SRS_outputF.df) = row.names(srs.otuF)
SRS_outputF.df = SRS_outputF.df[,order(colSums(SRS_outputF.df),decreasing = T)]
NtaxaF.df = as.data.frame(NtaxaF)
to.remove <- setdiff(rownames(NtaxaF.df), colnames(SRS_outputF.df))
NtaxaF.df = NtaxaF.df[!row.names(NtaxaF.df) %in% to.remove,]
setdiff(rownames(NtaxaF.df), colnames(SRS_outputF.df))
identical(rownames(NtaxaF.df), colnames(SRS_outputF.df))
NtaxaF.df = NtaxaF.df[colnames(SRS_outputF.df),]
identical(rownames(NtaxaF.df), colnames(SRS_outputF.df))
NtaxaF.df$ASV_ID <- paste("ASV_", 1:nrow(NtaxaF.df), sep="")
NtaxaF.df$concat = paste(NtaxaF.df$ASV_ID, NtaxaF.df$Taxonomy, sep = "_")
rownames(NtaxaF.df) = NtaxaF.df$concat
colnames(SRS_outputF.df) = rownames(NtaxaF.df)
NtaxaF.df$ASV_ID = NULL
NtaxaF.df$concat = NULL
NtaxaF.df = as.matrix(NtaxaF.df)
rownames(SRS_outputF.df) <- gsub(x = rownames(SRS_outputF.df), pattern = "\\.", replacement = "-")
###Nest###
srs.otuN = data.frame(t(otu_table(psN2)))
#SRS.shiny.app(srs.otuN)
SRS_outputN <- SRS(srs.otuN, Cmin = 1600) #4 samples discarded
SRS_outputN.df = data.frame(t(SRS_outputN))
colnames(SRS_outputN.df) = row.names(srs.otuN)
SRS_outputN.df = SRS_outputN.df[,order(colSums(SRS_outputN.df),decreasing = T)]
NtaxaN.df = as.data.frame(NtaxaN)
to.remove <- setdiff(rownames(NtaxaN.df), colnames(SRS_outputN.df))
NtaxaN.df = NtaxaN.df[!row.names(NtaxaN.df) %in% to.remove,]
setdiff(rownames(NtaxaN.df), colnames(SRS_outputN.df))
identical(rownames(NtaxaN.df), colnames(SRS_outputN.df))
NtaxaN.df = NtaxaN.df[colnames(SRS_outputN.df),]
identical(rownames(NtaxaN.df), colnames(SRS_outputN.df))
NtaxaN.df$ASV_ID <- paste("ASV_", 1:nrow(NtaxaN.df), sep="")
NtaxaN.df$concat = paste(NtaxaN.df$ASV_ID, NtaxaN.df$Taxonomy, sep = "_")
rownames(NtaxaN.df) = NtaxaN.df$concat
colnames(SRS_outputN.df) = rownames(NtaxaN.df)
NtaxaN.df$ASV_ID = NULL
NtaxaN.df$concat = NULL
NtaxaN.df = as.matrix(NtaxaN.df)
rownames(SRS_outputN.df) <- gsub(x = rownames(SRS_outputN.df), pattern = "\\.", replacement = "-")
```
```{r}
write.csv(SRS_outputF.df, "MS_FINAL/tables/fungi_SRS_asv_table_F.csv")
write.csv(SRS_outputN.df, "MS_FINAL/tables/fungi_SRS_asv_table_N.csv")
```
```{r}
###Faecal###
map.ps2.F <- data.frame(sample_data(psF2))
f.to.delete <- setdiff(rownames(map.ps2.F), rownames(SRS_outputF.df))
map.ps2.F = map.ps2.F[!row.names(map.ps2.F) %in% f.to.delete,]
map.ps2.F$Date <- as.Date(map.ps2.F$Date, format = "%d/%m/%Y")
map.ps2.F.sort <- dplyr::arrange(map.ps2.F, Name, Date)
SRS_outputF.df.sort <- SRS_outputF.df[map.ps2.F.sort$SAMPLEID,]
psF_SRS = phyloseq(otu_table(SRS_outputF.df.sort, taxa_are_rows = F),
sample_data(map.ps2.F.sort),
tax_table(NtaxaF.df))
psF_SRS
psF_SRS_otu = data.frame(otu_table(psF_SRS))
avg_ASV_F <- data.frame(rowSums(psF_SRS_otu != 0))
prev_ASV_F <- data.frame(colSums(psF_SRS_otu != 0))
sample_data(psF_SRS)$Age <- factor(sample_data(psF_SRS)$Age,
level = c("<14 days","15-28 days","29-42 days","43-56 days","57-70 days","71-120 days","200+ days"),
label = c("<14 days","15 - 28 days","29 - 42 days","43 - 56 days","57 - 70 days","71 - 120 days","200+ days"))
###Nest###
map.ps2.N <- data.frame(sample_data(psN2))
n.to.delete <- setdiff(rownames(map.ps2.N), rownames(SRS_outputN.df))
map.ps2.N = map.ps2.N[!row.names(map.ps2.N) %in% n.to.delete,]
map.ps2.N$Date <- as.Date(map.ps2.N$Date, format = "%d/%m/%Y")
map.ps2.N.sort <- dplyr::arrange(map.ps2.N, Name, Date)
SRS_outputN.df.sort <- SRS_outputN.df[map.ps2.N.sort$SAMPLEID,]
psN_SRS = phyloseq(otu_table(SRS_outputN.df.sort, taxa_are_rows = F),
sample_data(map.ps2.N.sort),
tax_table(NtaxaN.df))
psN_SRS
psN_SRS_otu = data.frame(otu_table(psN_SRS))
avg_ASV_N <- data.frame(rowSums(psN_SRS_otu != 0))
prev_ASV_N <- data.frame(colSums(psN_SRS_otu != 0))
sample_data(psN_SRS)$Name <- factor(sample_data(psN_SRS)$Name,
levels = c("Alice_Nest","Aranga_Nest","Cyndy_Nest","Esperance_Nest",
"Hoki_Nest","Huhana_Nest","Ihi_Nest","Kuihi_Nest","Marama_Nest",
"Margaretmaree_Nest","Nora_Nest","Pounamu_Nest","Rakiura_Nest","Sue_Nest",
"Wehepo_Nest"),
labels = c("Alice","Aranga","Cyndy","Esperance","Hoki","Huhana","Ihi","Kuihi",
"Marama","Margaret-Maree","Nora","Pounamu","Rakiura","Sue","Weheruatanga-o-te-po"))
sample_data(psN_SRS)$Age <- factor(sample_data(psN_SRS)$Age,
levels = c("<14 days","15-28 days","29-42 days","43-56 days","57-70 days","71-120 days"),
labels = c("<14 days","15 - 28 days","29 - 42 days","43 - 56 days","57 - 90 days","57 - 90 days"))
```
#Data summaries
```{r}
map.f <- data.frame(sample_data(psF_SRS))
map.n <- data.frame(sample_data(psN_SRS))
pool = c("Pool")
map.f.np = map.f[!(map.f$Group %in% pool),]
summary_data <- map.f %>%
group_by(Group, Name) %>%
dplyr::summarise(Count = n())
summary_data
map.f %>% count(Group)
map.f.np %>% count(Name)
map.f %>% count(Age)
map.f %>% count(Aspergillosis)
map.f %>% count(Nest)
map.f %>% count(Nest_type)
map.f %>% count(NestFaeces)
map.f %>% count(Island)
map.f %>% count(Movement)
map.n %>% count(Age)
map.n %>% count(Aspergillosis)
map.n %>% count(Nest)
map.n %>% count(Nest_type)
map.n %>% count(NestFaeces)
map.n %>% count(Island)
map.n %>% count(Movement)
```
```{r}
SRS_asv_tableF<-as.data.frame(t(otu_table(psF_SRS)))
SRS_taxo_tableF<-as.data.frame(tax_table(psF_SRS))
SRS_asv_table_wTaxF <- cbind(SRS_asv_tableF, SRS_taxo_tableF)
SRS_asv_tableN<-as.data.frame(t(otu_table(psN_SRS)))
SRS_taxo_tableN<-as.data.frame(tax_table(psN_SRS))
SRS_asv_table_wTaxN <- cbind(SRS_asv_tableN, SRS_taxo_tableN)
```
```{r}
#Phylum
Phyla.sumF<-aggregate(SRS_asv_table_wTaxF[,1:108], list(SRS_asv_table_wTaxF$Phylum),sum)
row.names(Phyla.sumF)<- Phyla.sumF$Group.1
Phyla.sumF$Group.1 <- NULL
P_rowsumF <- rowSums(Phyla.sumF)
write.csv(Phyla.sumF, "MS_FINAL/tables/fungi_Phyla_sumF_per_sample_NC_kakapo.csv")
write.csv(P_rowsumF, "MS_FINAL/tables/fungi_P_rowsumF_NC_kakapo_fungi.csv")
Phyla.sumN<-aggregate(SRS_asv_table_wTaxN[,1:51], list(SRS_asv_table_wTaxN$Phylum),sum)
row.names(Phyla.sumN)<- Phyla.sumN$Group.1
Phyla.sumN$Group.1 <- NULL
P_rowsumN <- rowSums(Phyla.sumN)
write.csv(Phyla.sumN, "MS_FINAL/tables/fungi_Phyla_sumN_per_sample_NC_kakapo.csv")
write.csv(P_rowsumN, "MS_FINAL/tables/fungi_P_rowsumN_NC_kakapo.csv")
sum(rowSums(Phyla.sumF)) #54000
rowSums(Phyla.sumF != 0)
sum(rowSums(Phyla.sumN)) #81600
rowSums(Phyla.sumN != 0)
```
```{r}
Class.sumF <- aggregate(SRS_asv_table_wTaxF[,1:108], list(SRS_asv_table_wTaxF$Class),sum)
row.names(Class.sumF)<- Class.sumF$Group.1
Class.sumF$Group.1 <- NULL
C_rowsumF <- rowSums(Class.sumF)
write.csv(C_rowsumF, "MS_FINAL/tables/fungi_class_rowsumF_NC_kakapo.csv")
write.csv(Class.sumF, "MS_FINAL/tables/fungi_Class_sumF_per_sample_NC_kakapo.csv")
Class.sumN <- aggregate(SRS_asv_table_wTaxN[,1:51], list(SRS_asv_table_wTaxN$Class),sum)
row.names(Class.sumN)<- Class.sumN$Group.1
Class.sumN$Group.1 <- NULL
C_rowsumN <- rowSums(Class.sumN)
write.csv(C_rowsumN, "MS_FINAL/tables/fungi_class_rowsumN_NC_kakapo.csv")
write.csv(Class.sumN, "MS_FINAL/tables/fungi_class_sumN_per_sample_NC_kakapo.csv")
```
```{r}
Genus.sumF <- aggregate(SRS_asv_table_wTaxF[,1:108], list(SRS_asv_table_wTaxF$Genus),sum)
row.names(Genus.sumF)<- Genus.sumF$Group.1
Genus.sumF$Group.1 <- NULL
G_rowsumF <- rowSums(Genus.sumF)
write.csv(G_rowsumF, "MS_FINAL/tables/fungi_genus_rowsumF_NC_kakapo.csv")
write.csv(Genus.sumF, "MS_FINAL/tables/fungi_Genus_sumF_per_sample_NC_kakapo.csv")
Genus.sumN <- aggregate(SRS_asv_table_wTaxN[,1:51], list(SRS_asv_table_wTaxN$Genus),sum)
row.names(Genus.sumN)<- Genus.sumN$Group.1
Genus.sumN$Group.1 <- NULL
G_rowsumN <- rowSums(Genus.sumN)
write.csv(G_rowsumN, "MS_FINAL/tables/fungi_genus_rowsumN_NC_kakapo.csv")
write.csv(Genus.sumN, "MS_FINAL/tables/fungi_Genus_sumN_per_sample_NC_kakapo.csv")
```
```{r}
taxa.sumF <- aggregate(SRS_asv_table_wTaxF[,1:108], list(SRS_asv_table_wTaxF$Taxonomy),sum)
row.names(taxa.sumF)<- taxa.sumF$Group.1
taxa.sumF$Group.1 <- NULL
t_rowsumF <- rowSums(taxa.sumF)
write.csv(t_rowsumF, "MS_FINAL/tables/fungi_taxa_rowsumF_NC_kakapo.csv")
write.csv(taxa.sumF, "MS_FINAL/tables/fungi_taxa_sumF_per_sample_NC_kakapo.csv")
taxa.sumN <- aggregate(SRS_asv_table_wTaxN[,1:51], list(SRS_asv_table_wTaxN$Taxonomy),sum)
row.names(taxa.sumN)<- taxa.sumN$Group.1
taxa.sumN$Group.1 <- NULL
t_rowsumN <- rowSums(taxa.sumN)
write.csv(t_rowsumN, "MS_FINAL/tables/fungi_taxa_rowsumN_NC_kakapo.csv")
write.csv(taxa.sumN, "MS_FINAL/tables/fungi_taxa_sumN_per_sample_NC_kakapo.csv")
```
#PERMANOVA
###Poo removal
```{r}
###Faecal###
permanova.dis.F <- distance(psF_SRS, "bray")
adonis2(permanova.dis.F ~ NestFaeces, map.f,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.f$Name)))
beta.pooR <- vegan::betadisper(permanova.dis.F, map.f$NestFaeces)
beta.pooR
vegan::permutest(beta.pooR,permutations = how(nperm = 9999))
###Nest###
permanova.dis.N <- phyloseq::distance(psN_SRS, "bray")
adonis2(permanova.dis.N ~ NestFaeces, map.n,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.n$Name)))
beta.pooR.N <- vegan::betadisper(permanova.dis.N, map.n$NestFaeces)
beta.pooR.N
vegan::permutest(beta.pooR.N)
```
###Faecal
```{r}
source('pairwiseAdonis3.R')
###FAECAL###
#Aspergillosis
vegan::adonis2(permanova.dis.F ~ Aspergillosis, map.f,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.f$Name)))
beta.asp <- vegan::betadisper(permanova.dis.F, map.f$Aspergillosis)
beta.asp
vegan::permutest(beta.asp, permutations = how(nperm = 9999))
#Movement
vegan::adonis2(permanova.dis.F ~ Movement, map.f,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.f$Name)))
beta.m <- vegan::betadisper(permanova.dis.F, map.f$Movement)
beta.m
vegan::permutest(beta.m, permutations = how(nperm = 9999))
#Island
psF_sub_is <- subset_samples(psF_SRS, Island != "Hand rearing")
disF.sub.is <- distance(psF_sub_is, "bray")
mapF.sub.is <- data.frame(sample_data(psF_sub_is))
vegan::adonis2(disF.sub.is ~ Island, mapF.sub.is,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=mapF.sub.is$Name)))
beta.l <- vegan::betadisper(disF.sub.is, mapF.sub.is$Island)
beta.l
vegan::permutest(beta.l, permutations = how(nperm = 9999))
#Age
vegan::adonis2(permanova.dis.F ~ Days, map.f,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.f$Name)))
vegan::adonis2(permanova.dis.F ~ Age, map.f,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.f$Name)))
pairwise.adonis3(permanova.dis.F ~ Age, data = map.f, p.adjust.m = 'BH', strata = "Name", nperm = 9999, within_type = "series")
beta.age <- vegan::betadisper(permanova.dis.F, map.f$Age)
beta.age
vegan::permutest(beta.age)
beta.age.df <- data.frame(beta.age$distances)
beta.age.df$Group = beta.age$group
dunn.test::dunn.test(beta.age.df$beta.age.distances, beta.age.df$Group, method = "bh")
#Nest type
##No sub-adult samples (and no hand-rearing samples)
psF_sub_NT <- subset_samples(psF_SRS, Nest_type != "Sub-adult samples" | Nest_type != "Hand rearing")
disF.sub.NT <- distance(psF_sub_NT, "bray")
mapF.sub.NT <- data.frame(sample_data(psF_sub_NT))
vegan::adonis2(disF.sub.NT ~ Nest_type, mapF.sub.NT,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=mapF.sub.NT$Name)))
beta.nt <- vegan::betadisper(disF.sub.NT, mapF.sub.NT$Nest_type)
beta.nt
vegan::permutest(beta.nt, permutations = how(nperm = 9999))
#Nest
##No sub-adult samples
vegan::adonis2(disF.sub.NT ~ Nest, mapF.sub.NT,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=mapF.sub.NT$Name)))
beta.n <- vegan::betadisper(disF.sub.NT, mapF.sub.NT$Nest)
beta.n
vegan::permutest(beta.n, permutations = how(nperm = 9999))
#Chick
vegan::adonis2(permanova.dis.F ~ Name, map.f,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.f$Name)))
```
###Litter
```{r}
###NEST###
#Aspergillosis
vegan::adonis2(permanova.dis.N ~ Aspergillosis, map.n,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.n$Name)))
vegan::adonis2(permanova.dis.N ~ Island + Aspergillosis, map.n,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.n$Name)))
beta.asp.L <- vegan::betadisper(permanova.dis.N, map.n$Aspergillosis)
beta.asp.L
vegan::permutest(beta.asp.L, permutations = how(nperm = 9999))
#Movement
vegan::adonis2(permanova.dis.N ~ Movement, map.n,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.n$Name)))
beta.M.L <- vegan::betadisper(permanova.dis.N, map.n$Movement)
beta.M.L
vegan::permutest(beta.M.L)
#Island
vegan::adonis2(permanova.dis.N ~ Island, map.n,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.n$Name)))
beta.I.L <- vegan::betadisper(permanova.dis.N, map.n$Island)
beta.I.L
vegan::permutest(beta.I.L)
#Days since first chick
vegan::adonis2(permanova.dis.N ~ Days, map.n,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.n$Name)))
vegan::adonis2(permanova.dis.N ~ Age, map.n,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.n$Name)))
pairwise.adonis3(permanova.dis.N ~ Age, data = map.n, p.adjust.m = 'BH', strata = "Name", nperm = 999, within_type = "series")
beta.age.L <- vegan::betadisper(permanova.dis.N, map.n$Age)
beta.age.L
vegan::permutest(beta.age.L, permutations = how(nperm = 9999))
#Nest type
vegan::adonis2(permanova.dis.N ~ Nest_type, map.n,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.n$Name)))
beta.NT.L <- vegan::betadisper(permanova.dis.N, map.n$Nest_type)
beta.NT.L
vegan::permutest(beta.NT.L, permutations = how(nperm = 9999))
#Nest
vegan::adonis2(permanova.dis.N ~ Nest, map.n,
permutations = how(nperm = 9999, within=Within(type="series"), plots=Plots(strata=map.n$Name)))
```
```{r}
#Adjust for multiple testing error
f.per.p.adj <- c("0.5","1","1","0.11","0.0004","0.0002","0.12","0.40","1")
l.per.p.adj <- c("1","1","1","1","0.002","0.002","1","0.04")
p.adjust(f.per.p.adj, method = "BH")
p.adjust(l.per.p.adj, method = "BH")
f.beta.p.adj <- c("0.33","0.11","0.003","0.72","0.00001","0.002")
l.beta.p.adj <- c("0.81","0.39","0.66","0.01","0.21","0.06")
p.adjust(f.beta.p.adj, method = "BH")
p.adjust(l.beta.p.adj, method = "BH")
```
##Bray-Curtis boxplots
```{r}
boxplot_theme <- theme_ipsum() + theme(plot.title = element_text(size = 28),
plot.subtitle = element_text(size = 26),
axis.text.x = element_blank(),
axis.title.x = element_text(size=26),
axis.ticks.x = element_blank(),
axis.text.y=element_text(size=20),
axis.title.y=element_text(size=26),
axis.line.x=element_line(color="black",size=1.0,linetype=1),
axis.line.y=element_line(color="black",size=1.0,linetype=1),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
legend.box.background = element_rect(),
legend.box.margin = margin(5, 5, 5, 5),
legend.position="bottom",
legend.title = element_text(face = "bold", size = 28),
legend.text = element_text(size = 26))
```
```{r fig.height= 10, fig.width=12}
library(reshape2); packageVersion("reshape2")
otu_split.F <- data.frame(otu_table(psF_SRS))
rownames(otu_split.F) <- map.f$Full
otu_split.F1.BC <- split(otu_split.F, map.f$NestFaeces)
dist.list.f.bc<- c()
for (i in 1:length(otu_split.F1.BC)) {
dist.list.f.bc[[i]] <- as.matrix(vegdist(otu_split.F1.BC[[i]], method = "bray"))
}
names(dist.list.f.bc) = names(otu_split.F1.BC)
df.f.bc <- reshape2::melt(dist.list.f.bc)
names(df.f.bc) <- c("Sample1", "Sample2", "BCdistance","Faecal_experiment")
df.f.bc$match = df.f.bc$Sample1 == df.f.bc$Sample2
df.f.bc.2 = df.f.bc[-which(df.f.bc$match == "TRUE"),]
faecal.bc.boxplot <- ggplot(df.f.bc.2,aes(x = Faecal_experiment, y = BCdistance)) +
geom_jitter(position = position_jitter(0.3), aes(color = Faecal_experiment), alpha = 0.75) +
geom_boxplot(size=1.0, fill='transparent') +
boxplot_theme +
guides(colour = guide_legend(override.aes = list(size=6))) +
labs(x = "Faecal experiment", y = "Bray-Curtis dissimilarity") +
ggtitle("Faecal samples", subtitle = "PERMANOVA p = 0.8") +
scale_color_manual(name = "Bray-Curtis distances",values= get_pal("Kakapo"))
faecal.bc.boxplot
faecal.bc.boxplot.nojitter <- ggplot(df.f.bc.2,aes(x = Faecal_experiment, y = BCdistance)) +
geom_boxplot(size=1.0, aes(fill = Faecal_experiment)) +
boxplot_theme +
labs(x = "Faecal experiment", y = "Bray-Curtis dissimilarity") +
ggtitle("Faecal samples", subtitle = "PERMANOVA p = 0.8") +
scale_fill_manual(name = "Bray-Curtis distances",values= get_pal("Kakapo"))
faecal.bc.boxplot.nojitter
dir.create("MS_FINAL/boxplots/")
ggsave("MS_FINAL/boxplots/fungi_bc_faecal_pooR_nojitter.png", faecal.bc.boxplot.nojitter, height = 10, width = 12, dpi = 400, bg = "white")
```
```{r fig.height= 10, fig.width=12}
otu_split.N <- data.frame(otu_table(psN_SRS))
rownames(otu_split.N) <- map.n$Full
otu_split.N1.BC <- split(otu_split.N, map.n$NestFaeces)
dist.list.n.bc<- c()
for (i in 1:length(otu_split.N1.BC)) {
dist.list.n.bc[[i]] <- as.matrix(vegdist(otu_split.N1.BC[[i]], method = "bray"))
}
names(dist.list.n.bc) = names(otu_split.N1.BC)
df.n.bc <- reshape2::melt(dist.list.n.bc)
names(df.n.bc) <- c("Sample1", "Sample2", "BCdistance","Faecal_experiment")
df.n.bc$match = df.n.bc$Sample1 == df.n.bc$Sample2
df.n.bc.2 = df.n.bc[-which(df.n.bc$match == "TRUE"),]
litter.bc.boxplot <- ggplot(df.n.bc.2,aes(x = Faecal_experiment, y = BCdistance)) +
geom_jitter(position = position_jitter(0.3), aes(color = Faecal_experiment), alpha = 0.75) +
geom_boxplot(size=1.0, fill='transparent') +
boxplot_theme +
guides(colour = guide_legend(override.aes = list(size=6))) +
labs(x = "Faecal experiment", y = "Bray-Curtis dissimilarity distances") +
ggtitle("Litter samples", subtitle = "PERMANOVA p = 1") +
scale_color_manual(name = "Faecal removal",values= get_pal("Kakapo"))
litter.bc.boxplot
litter.bc.boxplot.nojitter <- ggplot(df.n.bc.2,aes(x = Faecal_experiment, y = BCdistance)) +
geom_boxplot(size=1.0, aes(fill = Faecal_experiment)) +
boxplot_theme +
labs(x = "Faecal experiment", y = "Bray-Curtis dissimilarity") +
ggtitle("Litter samples", subtitle = "PERMANOVA p = 1") +
scale_fill_manual(name = "Bray-Curtis distances",values= get_pal("Kakapo"))
litter.bc.boxplot.nojitter
ggsave("MS_FINAL/boxplots/fungi_bc_litter_pooR_nojitter.png", litter.bc.boxplot.nojitter, height = 10, width = 12, dpi = 400, bg = "white")
```
```{r fig.height= 9, fig.width=20}
library(ggpubr)
bc.boxplots.combined = ggarrange(faecal.bc.boxplot.nojitter, litter.bc.boxplot.nojitter, labels = c("a","b"), font.label = list(size = 30),
ncol=2, nrow=1, common.legend = T, legend = "bottom")
bc.boxplots.combined
ggsave("MS_FINAL/boxplots/fungi_bc_boxplots_combined_nojitter.png", bc.boxplots.combined, width = 20, height = 9, dpi = 400, bg = "white")
```
#Taxa plots
```{r}
taxaplot_theme <- theme_ipsum() + theme(plot.title = element_text(size = 35),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.text.y=element_text(size=25),
axis.title.y=element_text(size=35),
axis.title.x = element_text(size=35),
strip.text.x = element_text(size = 28),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
legend.box.background = element_rect(),
legend.box.margin = margin(5, 5, 5, 5),
legend.position="bottom",
legend.title = element_text(face = "bold", size = 35),
legend.text = element_text(size = 30))
```
```{r fig.cap = "K\u101k\u101p\u14d phylum others taxonomic plot", fig.height = 8, fig.width = 12, dpi=300}
psF_RA <- transform_sample_counts(psF_SRS, function(x) x/sum(x))
psN_RA <- transform_sample_counts(psN_SRS, function(x) x/sum(x))
```
##Faecal
```{r}
library(plyr); packageVersion("plyr")
glom_f <- tax_glom(psF_RA, taxrank = 'Taxonomy')
df_f <- psmelt(glom_f)
df_f$Taxonomy <- as.character(df_f$Taxonomy)
means_f <- ddply(df_f, ~Taxonomy, function(x) c(mean=mean(x$Abundance)))
remainder_f <- means_f[means_f$mean <= 0.003,]$Taxonomy
df_f[df_f$Taxonomy %in% remainder_f,]$Taxonomy <- 'Other species <0.3%'
print(levels(factor(df_f$Taxonomy)))
```
```{r fig.height = 20, fig.width = 40, dpi=300}
###Faecal taxa plots###
taxa.colours.f <- c("#882E72","#D6C1DE","#54809D","#4EB265","#CAE0AB","#77b6b1","#33605d","#F7EE55","#F9ECA0","#F6C141","#FF99AB","#FF0F39","#767676")
faecal_taxa_plotbar <- ggplot(data=df_f, aes(x=Sample_Name, y=Abundance,
fill = factor(Taxonomy,
c("Apiotrichum unclassified","Blastobotrys parvus",
"Blastobotrys unclassified","Candida albicans","Candida palmioleophila",
"Debaryomyces hansenii","Kazachstania telluris","Metschnikowia unclassified",
"Mycena flos-nivium","Spencermartinsiella unclassified","Thelebolus globosus",
"Vishniacozyma victoriae", "Other species <0.3%")))) +
geom_bar(aes(), stat="identity", position="fill", width = 1) +
guides(fill=guide_legend(title="Species", nrow = 4)) + taxaplot_theme +
theme(axis.title.y = element_blank(), axis.text.y = element_blank()) +
labs(x="K\u101k\u101p\u14d faecal samples") +
facet_grid(.~Age, scales = "free_x", space='free') +
scale_fill_manual(values = taxa.colours.f)
faecal_taxa_plotbar
faecal_taxa_plotbar_age <- ggplot(data=df_f,
aes(x=Age, y=Abundance,
fill = factor(Taxonomy,
c("Apiotrichum unclassified","Blastobotrys parvus",
"Blastobotrys unclassified","Candida albicans","Candida palmioleophila",
"Debaryomyces hansenii","Kazachstania telluris","Metschnikowia unclassified",
"Mycena flos-nivium","Spencermartinsiella unclassified","Thelebolus globosus",
"Vishniacozyma victoriae", "Other species <0.3%")))) +
geom_bar(aes(), stat="identity", position="fill", width = 1.5) +
guides(fill=guide_legend(title="Species", nrow = 4)) + taxaplot_theme +
theme(strip.text.x = element_blank()) +
ggtitle("Faecal samples by k\u101k\u101p\u14d chick age") +
labs(y="Relative sequence abundance ", x = "Age groups") +
facet_grid(.~Age, scales = "free_x", space='free') +
scale_fill_manual(values = taxa.colours.f)
faecal_taxa_plotbar_age
```
##Litter
```{r}
glom_nest.T <- tax_glom(psN_RA, taxrank = 'Taxonomy')
df_nest.T <- psmelt(glom_nest.T)
df_nest.T$Taxonomy <- as.character(df_nest.T$Taxonomy)
means_nest.T <- ddply(df_nest.T, ~Taxonomy, function(x) c(mean=mean(x$Abundance)))
remainder_nest.T <- means_nest.T[means_nest.T$mean <= 0.003,]$Taxonomy
df_nest.T[df_nest.T$Taxonomy %in% remainder_nest.T,]$Taxonomy <- 'Other species <0.3%'
print(levels(factor(df_nest.T$Taxonomy)))
```
```{r fig.cap = "K\u101k\u101p\u14d species others taxonomic plot", fig.height = 16, fig.width = 40, dpi=300}
###Litter taxa plots###
nest.taxa.col <- c("#402060","#882E72","#D6C1DE","#54809D","#CAE0AB","#85CA95","#77b6b1","#008b8b","#33605d","#F9ECA0",
"#f3a833","#de5d3a","#9a4d76","#fa6e79","#ffa2ac","#ffd1d5","#6dead6","#36c5f4","#3388de","#e2dfdf","#767676")
taxa_plot_nest <- ggplot(data=df_nest.T,
aes(x=Sample_Name, y=Abundance,
fill = factor(Taxonomy,
c("Apiotrichum laibachii","Apiotrichum unclassified","Blastobotrys parvus",
"Blastobotrys unclassified","Candida palmioleophila",
"Cutaneotrichosporon dermatis","Debaryomyces hansenii","Geomyces auratus",
"Kazachstania telluris","Leohumicola unclassified","Mortierella parvispora",
"Mortierella unclassified","Oidiodendron unclassified","Penicillium spinulosum",
"Priceomyces haplophilus","Pseudogymnoascus unclassified","Sistotrema coronilla",
"Sugiyamaella unclassified","Trechispora unclassified","Umbelopsis isabellina",
"Other species <0.3%")))) +
geom_bar(aes(), stat="identity", position="fill", width = 1) +
guides(fill=guide_legend(title="Species", nrow = 7)) + taxaplot_theme +
theme(axis.title.y = element_blank(),axis.text.y = element_blank()) +
labs(x = "Nest litter samples") +
facet_grid(.~Age, scales = "free_x", space='free') +
scale_fill_manual(values = nest.taxa.col)
taxa_plot_nest
taxa_plot_nest_age <- ggplot(data=df_nest.T,
aes(x=Age, y=Abundance,
fill = factor(Taxonomy,
c("Apiotrichum laibachii","Apiotrichum unclassified","Blastobotrys parvus",
"Blastobotrys unclassified","Candida palmioleophila",
"Cutaneotrichosporon dermatis","Debaryomyces hansenii","Geomyces auratus",
"Kazachstania telluris","Leohumicola unclassified","Mortierella parvispora",
"Mortierella unclassified","Oidiodendron unclassified","Penicillium spinulosum",
"Priceomyces haplophilus","Pseudogymnoascus unclassified","Sistotrema coronilla",
"Sugiyamaella unclassified","Trechispora unclassified","Umbelopsis isabellina",
"Other species <0.3%")))) +
geom_bar(aes(), stat="identity", position="fill", width = 1.5) +
guides(fill=guide_legend(title="Species", nrow = 5)) + taxaplot_theme +
ggtitle("Litter samples by days since first chick") +
theme(axis.title.y=element_text(size=30), strip.text.x = element_blank()) +
labs(y="Relative sequence abundance ", x = "Temporal groups") +
facet_wrap(~Age, scales = "free_x", nrow=1) +
scale_fill_manual(values = nest.taxa.col)
taxa_plot_nest_age
```
```{r fig.height = 30, fig.width = 42, dpi=300}
taxa.f = ggarrange(faecal_taxa_plotbar_age, faecal_taxa_plotbar,
ncol=2, nrow=1, common.legend = T, legend = "bottom", widths = c(0.25,1))
taxa.f
taxa.n = ggarrange(taxa_plot_nest_age, taxa_plot_nest,
ncol=2, nrow=1, common.legend = T, legend = "bottom", widths = c(0.27,1))
taxa.n
taxa.combined = ggarrange(taxa.f, NULL, taxa.n, nrow = 3, labels = c("a","b"), font.label = list(size = 30), heights = c(1, 0.02, 1))
taxa.combined
dir.create("MS_FINAL/taxa_plots")
ggsave("MS_FINAL/taxa_plots/fungi_barplot_taxa_age_combined.png", taxa.combined, height = 30, width = 40, dpi=400, bg = "white")
```
#Alpha Diversity
##Faecal
```{r}
rich_psF <- estimate_richness(psF_SRS, measures = c("Observed","InvSimpson"))
richF <- list(rich_psF, sample_data(psF_SRS)$NestFaeces, sample_data(psF_SRS)$Aspergillosis, sample_data(psF_SRS)$Movement, sample_data(psF_SRS)$Island, sample_data(psF_SRS)$Age, sample_data(psF_SRS)$Days, sample_data(psF_SRS)$Name, sample_data(psF_SRS)$Nest, sample_data(psF_SRS)$Nest_type, sample_data(psF_SRS)$Sample_Name)
names(richF) <- c("alpha_diversity", "NestFaeces", "Aspergillosis", "Movement", "Island", "Age", "Days", "Chick", "Nest", "Nest_type","Sample_Name")
shapiro.test(richF$alpha_diversity$Observed)
shapiro.test(richF$alpha_diversity$InvSimpson)
rich_dfF <- as.data.frame(richF)
names(rich_dfF)[names(rich_dfF) == "alpha_diversity.Observed"] <- "Observed"
names(rich_dfF)[names(rich_dfF) == "alpha_diversity.InvSimpson"] <- "InvSimpson"
# Faecal removal
kruskal.test(richF$alpha_diversity$Observed, richF$NestFaeces)
kruskal.test(richF$alpha_diversity$InvSimpson, richF$NestFaeces)
# Aspergillosis
kruskal.test(richF$alpha_diversity$Observed, richF$Aspergillosis)
kruskal.test(richF$alpha_diversity$InvSimpson, richF$Aspergillosis)
# Movement
kruskal.test(richF$alpha_diversity$Observed, richF$Movement)
kruskal.test(richF$alpha_diversity$InvSimpson, richF$Movement)
# Island
richF.norear <- rich_dfF[-which(rich_dfF$Island == "Hand rearing"),]
kruskal.test(richF.norear$Observed, richF.norear$Island)
kruskal.test(richF.norear$InvSimpson, richF.norear$Island)
# Age
kruskal.test(richF$alpha_diversity$Observed, richF$Age)
kruskal.test(richF$alpha_diversity$InvSimpson, richF$Age)
kruskal.test(richF$alpha_diversity$Observed, richF$Days)
kruskal.test(richF$alpha_diversity$InvSimpson, richF$Days)
# Chick
kruskal.test(richF$alpha_diversity$Observed, richF$Chick)
kruskal.test(richF$alpha_diversity$InvSimpson, richF$Chick)
#Nest type (without hand rearing samples)
richF.nt <- rich_dfF[-which(rich_dfF$Nest_type == "Hand rearing"| rich_dfF$Nest_type == "Sub-adult samples"),]
shapiro.test(richF.nt$alpha_diversity$Observed)
shapiro.test(richF.nt$alpha_diversity$InvSimpson)
kruskal.test(richF.nt$alpha_diversity$Observed, richF.nt$Nest_type)
kruskal.test(richF.nt$alpha_diversity$InvSimpson, richF.nt$Nest_type)
#Nest
kruskal.test(richF.nt$alpha_diversity$Observed, richF.nt$Nest)
kruskal.test(richF.nt$alpha_diversity$InvSimpson, richF.nt$Nest)
```
```{r}
faecal.obs.p.adj <- c("0.34","0.04","0.10","0.003","0.02","0.47","0.21","0.009","0.03")
faecal.invsimp..p.adj <- c("0.9","0.28","0.94","0.05","0.01","0.47","0.02","0.07","0.52")
p.adjust(faecal.obs.p.adj, method = "BH")
p.adjust(faecal.invsimp..p.adj, method="BH")
```
###LMMs
```{r}
library(lme4); packageVersion("lme4")
richF.glmm <- rich_dfF
richF.glmm.mv <- richF.glmm[-which(richF.glmm$Nest_type == "Sub-adult samples"),]
#Observed richness
###Faecal experiment
obs_model_fe_null <- glmer(Observed ~ (1|Chick) + (1|Island:Nest) + (1|Days), data = richF.glmm, family = poisson(link=log))
obs_model_fe <- glmer(Observed ~ NestFaeces + (1|Chick) + (1|Island:Nest) + (1|Days), data = richF.glmm, family = poisson(link=log))
summary(obs_model_fe)
anova(obs_model_fe, obs_model_fe_null)
confint(obs_model_fe)
###Island
obs_model_lc_null <- glmer(Observed ~ (1|Chick) + (1|Nest) + (1|Days), data = richF.norear, family = poisson(link=log))
obs_model_lc <- glmer(Observed ~ Island + (1|Chick) + (1|Nest) + (1|Days), data = richF.norear, family = poisson(link=log))
summary(obs_model_lc)
anova(obs_model_lc,obs_model_lc_null)
confint(obs_model_lc)
obs_model_lc_null_hr <- glmer(Observed ~ (1|Chick) + (1|Nest) + (1|Days), data = richF.glmm, family = poisson(link=log))
obs_model_lc_hr <- glmer(Observed ~ Island + (1|Chick) + (1|Nest) + (1|Days), data = richF.glmm, family = poisson(link=log))
summary(obs_model_lc_hr)
anova(obs_model_lc_hr,obs_model_lc_null_hr)
confint(obs_model_lc_hr)
###Movement
obs_model_mv_null <- glmer(Observed ~ (1|Chick) + (1|Island:Nest) + (1|Days), data = richF.nt, family = poisson(link=log))
obs_model_mv <- glmer(Observed ~ Movement + (1|Chick) + (1|Island:Nest) + (1|Days), data = richF.nt, family = poisson(link=log))
summary(obs_model_mv)
anova(obs_model_mv, obs_model_mv_null)
confint(obs_model_mv)
###Aspergillosis
obs_model_asp_null <- glmer(Observed ~ (1|Chick) + (1|Island:Nest) + (1|Days), data = richF.glmm, family = poisson(link=log))
obs_model_asp <- glmer(Observed ~ Aspergillosis + (1|Chick) + (1|Island:Nest) + (1|Days), data = richF.glmm, family = poisson(link=log))
summary(obs_model_asp)
anova(obs_model_asp, obs_model_asp_null)
confint(obs_model_asp)
###Days
obs_model_days_null <- glmer(Observed ~ (1|Chick) + (1|Island:Nest), data = richF.glmm, family = poisson(link=log))
obs_model_days <- glmer(Observed ~ Days + (1|Chick) + (1|Island:Nest), data = richF.glmm, family = poisson(link=log))
summary(obs_model_days)
anova(obs_model_days, obs_model_days_null)
confint(obs_model_days)
###Age
obs_model_age_null <- glmer(Observed ~ (1|Chick) + (1|Island:Nest), data = richF.glmm, family = poisson(link=log))
obs_model_age <- glmer(Observed ~ Age + (1|Chick) + (1|Island:Nest), data = richF.glmm, family = poisson(link=log))
summary(obs_model_age)
anova(obs_model_age, obs_model_age_null)
confint(obs_model_age)
###Nest type
obs_model_nt <- glmer(Observed ~ Nest_type + (1|Chick) + (1|Island:Nest) + (1|Days), data = richF.nt, family = poisson(link=log))
obs_model_nt_null <- glmer(Observed ~ (1|Chick) + (1|Island:Nest) + (1|Days), data = richF.nt, family = poisson(link=log))
summary(obs_model_nt)
anova(obs_model_nt, obs_model_nt_null)
confint(obs_model_nt)
###Nest