-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRebuttal.Rmd
2925 lines (2294 loc) · 103 KB
/
Rebuttal.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: "Effects of microplastics on Daphnia-associated microbiomes in situ and in vitro: REBBUTAL"
output: html_notebook
---
```{r}
library(ggplot2)
library(ggpubr)
library(dplyr)
library(pcaMethods)
library(plotly)
library(vegan)
```
Reviewer1:
In the in situ sampling, the db-RDA seems to indicate that the concentration of microplastics is not a significant factor influencing the bacterial microbiome composition, but that the observed differences between urban and natural ponds are rather explained by other factors (e.g. temperature and chlorophyll). It therefore seems that because of these covarying factors leading to confounding effects, it is not possible to conclude on the effect of microplastics on bacterial microbiome composition. If the authors perform a PCA on these environmental variables (excluding microplastic concentrations), I guess urban and natural ponds will be clearly separated, independently of the plastic effect (which will be indicative of many confounding variables).
Action:
The reviewer wants me to perform a PCA on these environmental variables with exclusion of MP. This is to see if there is a clear distinction of the sites based on the collected variables alone.
```{r}
library(ggplot2)
library(dplyr)
library(gridExtra)
library(ggpubr)
env_data=read.csv('/Users/u0145079/Library/CloudStorage/OneDrive-KULeuven/Desktop/Doctorate/Publication/Review/Rebbutal/0_REBBUTAL/10_Scripts/files/tables/Supplementary table 3- Sampled pond envirionmental parameters.csv')
# Group-wise median imputation for missing values
pca_data_groupwise_imputed <- env_data %>%
group_by(Type) %>%
mutate(across(where(is.numeric), ~ ifelse(is.na(.), median(., na.rm = TRUE), .))) %>%
ungroup() %>%
select(-Location, -Type, -Sample.ID) %>%
scale()
# Perform PCA on the scaled data
pca_result <- prcomp(pca_data_groupwise_imputed, scale. = FALSE)
# Extract the PCA scores and add the "Type" and "Location" variables for coloring and labeling
pca_scores <- as.data.frame(pca_result$x)
pca_scores$Type <- env_data$Type # Use original env_data as the rows are aligned
pca_scores$Location <- env_data$Location
# Define a buffer to extend the plot limits
x_buffer <- diff(range(pca_scores$PC1)) * 0.1
y_buffer <- diff(range(pca_scores$PC2)) * 0.1
# Define colors
colors <- ifelse(pca_scores$Type == "Urban", "red", "blue")
location_abbreviations <- c(
"Kluizen" = "KL",
"De Gavers" = "DG",
"Evangelie Boom " = "EB",
"Reserve next to Kulak" = "RK",
"MVR" = "MVR",
"Meer van Rotselaar" = "MVR",
"Blauwwe Poort" = "BP",
"Citadell Park" = "CP",
"De Bourgoyen" = "DB",
"Donk-Oudenaarde" = "DO",
"St. Donatus P. " = "DP",
"LRV" = "LRV"
)
# Add the abbreviated location names as a new column
pca_scores$Location_Abbreviation <- location_abbreviations[pca_scores$Location]
# Plot with extended limits
plot(pca_scores$PC1, pca_scores$PC2,
col = colors,
pch = 19, # Point style
xlab = "PC1",
ylab = "PC2",
main = "",
xlim = range(pca_scores$PC1) + c(-x_buffer, x_buffer),
ylim = range(pca_scores$PC2) + c(-y_buffer, y_buffer))
# Add a legend
legend("bottomleft", legend = c("Urban", "Natural"), col = c("red", "blue"), pch = 19)
# Add the "Pond" or "Location" labels to each point
text(pca_scores$PC1, pca_scores$PC2, labels = pca_scores$Location_Abbreviation, pos = 4, cex = 0.7)
####Bar-chart
# Define the environmental variables of interest
env_vars <- c("FINAL.mg.C.L", "Dissolved.oxygen..DO.", "Temperature...C.", "pH", "Conductivity", "Chlorophyll")
# Filter out rows with incomplete information in env_vars
env_data_filtered <- env_data %>%
select(-Sample.ID) %>%
na.omit()
library(reshape2)
env_long <- reshape2::melt(env_data_filtered, id.vars = c("Location", "Type"))
# Create the bar plot with custom colors for Type
ggplot(env_long, aes(x = Location, y = value, fill = Type)) +
geom_bar(stat = "identity", position = "dodge") +
facet_wrap(~ variable, scales = "free_y") + # Separate facets for each variable
scale_fill_manual(values = c("Urban" = "red", "Natural" = "blue")) + # Custom colors for Type
labs(x = "Pond", y = "Value", title = "") +
theme_pubr() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
#Statistical test
pca_data_scaled <- scale(pca_data) #normalize original data to remove effect of different scales
# Calculate the Euclidean distance matrix (you can use other distance metrics as well)
distance_matrix <- dist(pca_data_scaled, method = "euclidean")
betadisp_result <- betadisper(distance_matrix, env_data$Type[complete.cases(env_data[, -which(names(env_data) %in% c("Location", "Type", "Sample.ID"))])])
# View the betadisp results
summary(betadisp_result)
# Perform an ANOVA to test for significant differences in dispersion
anova_betadisp <- anova(betadisp_result)
print(anova_betadisp) #0.01375*
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 10.635 10.6350 6.4129 0.01375 *
Residuals 65 107.795 1.6584
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# Perform PERMANOVA (adonis function in vegan package)
permanova_result <- adonis2(distance_matrix ~ env_data$Type[complete.cases(env_data[, -which(names(env_data) %in% c("Location", "Type", "Sample.ID"))])], method = "euclidean")
# Print the result
print(permanova_result) #0.001
```
L162: Performing rarefactions is very criticized in the field of microbial ecology, especially when rarefying to the depth of the samples with the fewest reads. I would recommend sensitivity analyses there, by replicating all the analyses using different depths for rarefactions (e.g. 2,000 and 3,000).
Action: Perform rarefractions using different depths and compare the results with the method used in the paper.
```{r}
library(phyloseq)
library(dplyr)
library(ggplot2)
library(vegan)
library(ggpubr)
```
1. Field sampling campaign:
```{r}
ps_original=readRDS("/Users/u0145079/Library/CloudStorage/OneDrive-KULeuven/Desktop/PlasticDaphnia/Publication/Review/Rebbutal/Scripts/files/objects/ps_original") #Raw dataset un-normalised
#Check the read number distribution of the samples
sort(sample_sums(ps_original), decreasing=FALSE) #4664-36892
```
Subsample to depth of the lowest sample (like in the original manuscript):
```{r}
ps_original=rarefy_even_depth(ps_original, sample.size=min(sample_sums(ps_original)), rngseed=1, replace=FALSE) #4664
bray <- vegdist(data.frame(t(otu_table(ps_original))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
#permanova:
permanova = adonis2(bray ~ data.frame(sample_data(ps_original))$Type)
print(permanova) #0.001 ***
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_original))$Type)
Df SumOfSqs R2 F Pr(>F)
Model 1 7.117 0.12233 20.071 0.001 ***
Residual 144 51.062 0.87767
Total 145 58.179 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_original))$Type,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.1767
#Richness- Figure 3B
library(BiocManager)
library(microbiome)
library(knitr)
#install.packages("patchwork")
library(patchwork)
tab <-microbiome::alpha(ps_original, index = "all")
meta <- data.frame(sample_data(ps_original)) #Accessing my sample information from the ps object containing rarefied data
tab$Type = meta$Type
#Chao1
print(t.test(chao1~Type, data=tab)) # t = 8.9475, df = 137.71, p-value = 2.186e-15
#Shannon
print(t.test(diversity_shannon~Type, data=tab)) # t = 7.3497, df = 143.93, p-value = 1.37e-11
#Pielou
print(t.test(evenness_pielou~Type, data=tab)) # t = 3.9496, df = 138.56, p-value = 0.0001241
#PCoA: Bacterioplankton- Figure 3C
ps_original_bac=subset_samples(ps_original, sample_data(ps_original)$Type == "Bacterioplankton")
bray <- vegdist(data.frame(t(otu_table(ps_original_bac))), method="bray")
#Permanova_test
permanova = adonis2(bray ~ data.frame(sample_data(ps_original_bac))$Category)
print(permanova)
'''
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_original_bac))$Category)
Df SumOfSqs R2 F Pr(>F)
Model 1 1.4962 0.04971 4.2893 0.001 ***
Residual 82 28.6040 0.95029
Total 83 30.1002 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
'''
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_original_bac))$Category,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.174
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.03543 0.035427 3.2859 0.07354 .
Residuals 82 0.88409 0.010782
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
#PCoA: Daphnia- Figure 3D
ps_original_dap=subset_samples(ps_original, sample_data(ps_original)$Type == "Daphnia")
bray <- vegdist(data.frame(t(otu_table(ps_original_dap))), method="bray")
#Permanova_test
permanova = adonis2(bray ~ data.frame(sample_data(ps_original_dap))$Category)
print(permanova)
'''
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_original_dap))$Category)
Df SumOfSqs R2 F Pr(>F)
Model 1 1.8973 0.09051 5.9712 0.001 ***
Residual 60 19.0642 0.90949
Total 61 20.9615 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
'''
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_original_dap))$Category,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.0533 .
'''
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.2363 0.236297 3.8861 0.0533 .
Residuals 60 3.6483 0.060806
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
'''
#Envfit and step-wise RDA
#Bacterioplankton
env_meta <- read.csv("/Users/u0145079/Library/CloudStorage/OneDrive-KULeuven/Desktop/PlasticDaphnia/Publication/Field_data/tables/Env_parameters+MPs.csv", row.names = 1)
bac_env_data = subset(env_meta,rownames(env_meta) %in% sample_names(ps_original_bac))
bray <- vegdist(data.frame(t(otu_table(ps_original_bac))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
envfit_result <- envfit(nMDS, bac_env_data, permutations = 999, na.rm = TRUE) #Remove rows with missing samples
envfit_result
"""
***VECTORS
NMDS1 NMDS2 r2 Pr(>r)
DO 0.26864 -0.96324 0.0688 0.113
Temperature 0.59922 -0.80059 0.0007 0.976
pH -0.05210 -0.99864 0.0331 0.338
Conductivity 0.55023 -0.83501 0.0048 0.850
Redox 0.04699 -0.99890 0.0408 0.272
Chlorophyl 0.34650 0.93805 0.0638 0.121
MPs 0.09620 -0.99536 0.0145 0.634
PE.PP 0.10845 -0.99410 0.0280 0.408
PS -0.17426 0.98470 0.0036 0.895
PET.polyester -0.13017 0.99149 0.0080 0.798
Permutation: free
Number of permutations: 999
18 observations deleted due to missingness
"""
#No significant envfit for bacterioplankton
#Daphnia
dap_env_data = subset(env_meta,rownames(env_meta) %in% sample_names(ps_original_dap))
bray <- vegdist(data.frame(t(otu_table(ps_original_dap))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
envfit_result <- envfit(nMDS, dap_env_data, permutations = 999, na.rm = TRUE) #Remove rows with missing samples
envfit_result
"""
***VECTORS
NMDS1 NMDS2 r2 Pr(>r)
DO 0.04220 0.99911 0.0888 0.089 .
Temperature -0.10277 0.99471 0.1906 0.004 **
pH 0.99929 -0.03773 0.0182 0.640
Conductivity -0.97803 -0.20845 0.0298 0.488
Redox -0.79022 0.61283 0.1657 0.016 *
Chlorophyl 0.84187 -0.53969 0.2421 0.001 ***
MPs 0.46677 -0.88438 0.1714 0.014 *
PE.PP 0.01543 -0.99988 0.0129 0.823
PS 0.56856 -0.82264 0.3091 0.001 ***
PET.polyester 0.54111 -0.84095 0.3193 0.001 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Permutation: free
Number of permutations: 999
10 observations deleted due to missingness
"""
#DB-RDA
scaled_dap_env_data <- as.data.frame(scale(dap_env_data)) #scale metavariables due to different scales
# Calculate correlation matrix
cor_matrix <- cor(scaled_dap_env_data, use = "pairwise.complete.obs")
library(caret)
# Identify highly correlated pairs (absolute correlation > 0.7)
highly_correlated <- findCorrelation(cor_matrix, cutoff = 0.7, verbose = TRUE)
reduced_data <- scaled_dap_env_data[,-highly_correlated]
sample_data(ps_original_dap) = reduced_data
bray = vegdist(data.frame(t(otu_table(ps_original_dap))), method="bray")
dbrda = dbrda(bray ~ ., reduced_data, dist="bray", na.action = na.exclude)
summary(dbrda)
anova(dbrda)
anova(dbrda, by="terms", permu=999) #Load a full metadata for bacteria:
plot(dbrda)
"""
Permutation test for dbrda under reduced model
Terms added sequentially (first to last)
Permutation: free
Number of permutations: 999
Model: dbrda(formula = bray ~ Temperature + pH + Conductivity + Redox + Chlorophyl + PE.PP, data = reduced_data, distance = "bray", na.action = na.exclude)
Df SumOfSqs F Pr(>F)
Temperature 1 0.9544 3.3637 0.004 **
pH 1 0.3661 1.2903 0.195
Conductivity 1 0.3771 1.3290 0.208
Redox 1 0.8795 3.0998 0.003 **
Chlorophyl 1 0.7430 2.6188 0.016 *
PE.PP 1 0.2299 0.8103 0.598
Residual 45 12.7680
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
```
Subsample at depth 3000:
```{r}
ps_3000=rarefy_even_depth(ps_original, sample.size=3000, rngseed=1, replace=FALSE)
bray <- vegdist(data.frame(t(otu_table(ps_3000))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
#permanova:
permanova = adonis2(bray ~ data.frame(sample_data(ps_3000))$Type)
print(permanova) #0.001 ***
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_3000))$Type)
Df SumOfSqs R2 F Pr(>F)
Model 1 7.089 0.12177 19.966 0.001 ***
Residual 144 51.128 0.87823
Total 145 58.217 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_3000))$Type,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.174
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.0433 0.043339 1.8664 0.174
Residuals 144 3.3437 0.023220
"""
#Richness- Figure 3B
library(BiocManager)
library(microbiome)
library(knitr)
#install.packages("patchwork")
library(patchwork)
tab <-microbiome::alpha(ps_3000, index = "all")
meta <- data.frame(sample_data(ps_3000)) #Accessing my sample information from the ps object containing rarefied data
tab$Type = meta$Type
#Chao1
print(t.test(chao1~Type, data=tab)) # t = 8.8971, df = 140.86, p-value = 2.53e-15
#Shannon
print(t.test(diversity_shannon~Type, data=tab)) # t = 7.338, df = 143.83, p-value = 1.463e-11
#Pielou
print(t.test(evenness_pielou~Type, data=tab)) # t = 4.0117, df = 139.56, p-value = 9.786e-05
#PCoA: Bacterioplankton- Figure 3C
ps_3000_bac=subset_samples(ps_3000, sample_data(ps_3000)$Type == "Bacterioplankton")
bray <- vegdist(data.frame(t(otu_table(ps_3000_bac))), method="bray")
#Permanova_test
permanova = adonis2(bray ~ data.frame(sample_data(ps_3000_bac))$Category)
print(permanova)
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_3000_bac))$Category)
Df SumOfSqs R2 F Pr(>F)
Model 1 1.4927 0.04952 4.2723 0.001 ***
Residual 82 28.6504 0.95048
Total 83 30.1432 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_3000_bac))$Category,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.06784
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.03627 0.036268 3.4243 0.06784 .
Residuals 82 0.86848 0.010591
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
#PCoA: Daphnia- Figure 3D
ps_dap=subset_samples(ps_3000, sample_data(ps_3000)$Type == "Daphnia")
bray <- vegdist(data.frame(t(otu_table(ps_3000_dap))), method="bray")
#Permanova_test
permanova = adonis2(bray ~ data.frame(sample_data(ps_3000_dap))$Category)
print(permanova)
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_3000_dap))$Category)
Df SumOfSqs R2 F Pr(>F)
Model 1 1.902 0.09064 5.9803 0.001 ***
Residual 60 19.083 0.90936
Total 61 20.985 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_3000_dap))$Category,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.05069
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.2402 0.240227 3.9763 0.05069 .
Residuals 60 3.6249 0.060414
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
#Envfit and step-wise RDA
#Bacterioplankton
env_meta <- read.csv("/Users/u0145079/Library/CloudStorage/OneDrive-KULeuven/Desktop/PlasticDaphnia/Publication/Field_data/tables/Env_parameters+MPs.csv", row.names = 1)
bac_env_data = subset(env_meta,rownames(env_meta) %in% sample_names(ps_3000_bac))
sam_data_bac = subset(meta,rownames(meta) %in% sample_names(ps_3000_bac))
bray <- vegdist(data.frame(t(otu_table(ps_3000_bac))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
envfit_result <- envfit(nMDS, bac_env_data, permutations = 999, na.rm = TRUE) #Remove rows with missing samples
envfit_result
"""
***VECTORS
NMDS1 NMDS2 r2 Pr(>r)
DO 0.26052 -0.96547 0.0741 0.093 .
Temperature 0.38796 -0.92168 0.0006 0.981
pH -0.56248 -0.82681 0.0291 0.405
Conductivity 0.58483 -0.81115 0.0079 0.786
Redox 0.12573 -0.99206 0.0514 0.187
Chlorophyl 0.49643 0.86807 0.0661 0.105
MPs 0.27999 -0.96000 0.0177 0.584
PE.PP 0.26363 -0.96462 0.0363 0.305
PS -0.18196 0.98331 0.0060 0.829
PET.polyester -0.27525 0.96137 0.0140 0.644
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Permutation: free
Number of permutations: 999
18 observations deleted due to missingness
"""
#No significant envfit for bacterioplankton
#Daphnia
dap_env_data = subset(env_meta,rownames(env_meta) %in% sample_names(ps_dap))
sam_data_bac = subset(meta,rownames(meta) %in% sample_names(ps_dap))
bray <- vegdist(data.frame(t(otu_table(ps_dap))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
envfit_result <- envfit(nMDS, dap_env_data, permutations = 999, na.rm = TRUE) #Remove rows with missing samples
envfit_result
"""
***VECTORS
NMDS1 NMDS2 r2 Pr(>r)
DO 0.04220 0.99911 0.0888 0.089 .
Temperature -0.10277 0.99471 0.1906 0.004 **
pH 0.99929 -0.03773 0.0182 0.640
Conductivity -0.97803 -0.20845 0.0298 0.488
Redox -0.79022 0.61283 0.1657 0.016 *
Chlorophyl 0.84187 -0.53969 0.2421 0.001 ***
MPs 0.46677 -0.88438 0.1714 0.014 *
PE.PP 0.01543 -0.99988 0.0129 0.823
PS 0.56856 -0.82264 0.3091 0.001 ***
PET.polyester 0.54111 -0.84095 0.3193 0.001 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Permutation: free
Number of permutations: 999
10 observations deleted due to missingness
"""
#DB-RDA
scaled_dap_env_data <- as.data.frame(scale(dap_env_data)) #scale metavariables due to different scales
# Calculate correlation matrix
cor_matrix <- cor(scaled_dap_env_data, use = "pairwise.complete.obs")
library(caret)
# Identify highly correlated pairs (absolute correlation > 0.7)
highly_correlated <- findCorrelation(cor_matrix, cutoff = 0.7, verbose = TRUE)
reduced_data <- scaled_dap_env_data[,-highly_correlated]
sample_data(ps_rarified_dap) = reduced_data
bray = vegdist(data.frame(t(otu_table(ps_dap))), method="bray")
dbrda = dbrda(bray ~ ., reduced_data, dist="bray", na.action = na.exclude)
summary(dbrda)
anova(dbrda)
anova(dbrda, by="terms", permu=999) #Load a full metadata for bacteria:
plot(dbrda)
"""
Permutation test for dbrda under reduced model
Terms added sequentially (first to last)
Permutation: free
Number of permutations: 999
Model: dbrda(formula = bray ~ Temperature + pH + Conductivity + Redox + Chlorophyl + PE.PP, data = reduced_data, distance = "bray", na.action = na.exclude)
Df SumOfSqs F Pr(>F)
Temperature 1 0.9544 3.3637 0.004 **
pH 1 0.3661 1.2903 0.195
Conductivity 1 0.3771 1.3290 0.208
Redox 1 0.8795 3.0998 0.003 **
Chlorophyl 1 0.7430 2.6188 0.016 *
PE.PP 1 0.2299 0.8103 0.598
Residual 45 12.7680
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
```
#Subsample at depth 4000
```{r}
ps_4000=rarefy_even_depth(ps_original, sample.size=4000, rngseed=1, replace=FALSE)
bray <- vegdist(data.frame(t(otu_table(ps_4000))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
#permanova:
permanova = adonis2(bray ~ data.frame(sample_data(ps_4000))$Type)
print(permanova) #0.001 ***
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_4000))$Type)
Df SumOfSqs R2 F Pr(>F)
Model 1 7.147 0.12289 20.175 0.001 ***
Residual 144 51.010 0.87711
Total 145 58.157 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_4000))$Type,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.1784
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.0428 0.04277 1.8286 0.1784
Residuals 144 3.3682 0.02339
"""
#Richness- Figure 3B
library(BiocManager)
library(microbiome)
library(knitr)
#install.packages("patchwork")
library(patchwork)
tab <-microbiome::alpha(ps_4000, index = "all")
meta <- data.frame(sample_data(ps_4000)) #Accessing my sample information from the ps object containing rarefied data
tab$Type = meta$Type
#Chao1
print(t.test(chao1~Type, data=tab)) # t = 8.6405, df = 140.11, p-value = 1.139e-14
#Shannon
print(t.test(diversity_shannon~Type, data=tab)) # t = 7.3735, df = 143.93, p-value = 1.203e-11
#Pielou
print(t.test(evenness_pielou~Type, data=tab)) # t = 3.9666, df = 138.8, p-value = 0.0001163
#PCoA: Bacterioplankton- Figure 3C
ps_4000_bac=subset_samples(ps_4000, sample_data(ps_4000)$Type == "Bacterioplankton")
bray <- vegdist(data.frame(t(otu_table(ps_4000_bac))), method="bray")
#Permanova_test
permanova = adonis2(bray ~ data.frame(sample_data(ps_4000_bac))$Category)
print(permanova)
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_4000_bac))$Category)
Df SumOfSqs R2 F Pr(>F)
Model 1 1.4797 0.04923 4.2456 0.001 ***
Residual 82 28.5789 0.95077
Total 83 30.0585 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_4000_bac))$Category,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.06961 .
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.03617 0.036168 3.3801 0.06961 .
Residuals 82 0.87741 0.010700
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
#PCoA: Daphnia- Figure 3D
ps_dap_4000=subset_samples(ps_4000, sample_data(ps_4000)$Type == "Daphnia")
bray <- vegdist(data.frame(t(otu_table(ps_dap_4000))), method="bray")
#Permanova_test
permanova = adonis2(bray ~ data.frame(sample_data(ps_dap_4000))$Category)
print(permanova)
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_dap_4000))$Category)
Df SumOfSqs R2 F Pr(>F)
Model 1 1.8857 0.09 5.9341 0.001 ***
Residual 60 19.0660 0.91
Total 61 20.9517 1.00
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_dap_4000))$Category,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.05069
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.2381 0.238136 3.9265 0.05212 .
Residuals 60 3.6389 0.060649
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
#Envfit and step-wise RDA
#Bacterioplankton
env_meta <- read.csv("/Users/u0145079/Library/CloudStorage/OneDrive-KULeuven/Desktop/PlasticDaphnia/Publication/Field_data/tables/Env_parameters+MPs.csv", row.names = 1)
bac_env_data = subset(env_meta,rownames(env_meta) %in% sample_names(ps_4000_bac))
bray <- vegdist(data.frame(t(otu_table(ps_4000_bac))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
envfit_result <- envfit(nMDS, bac_env_data, permutations = 999, na.rm = TRUE) #Remove rows with missing samples
envfit_result
"""
***VECTORS
NMDS1 NMDS2 r2 Pr(>r)
DO 0.31032 -0.95063 0.0709 0.100
Temperature 0.73785 -0.67496 0.0001 0.996
pH -0.30906 -0.95104 0.0259 0.418
Conductivity 0.58537 -0.81076 0.0095 0.746
Redox 0.10810 -0.99414 0.0456 0.227
Chlorophyl 0.49233 0.87041 0.0632 0.129
MPs 0.26715 -0.96365 0.0163 0.593
PE.PP 0.22871 -0.97349 0.0332 0.355
PS -0.05412 0.99853 0.0056 0.833
PET.polyester -0.16522 0.98626 0.0109 0.714
Permutation: free
Number of permutations: 999
18 observations deleted due to missingness
"""
#No significant envfit for bacterioplankton
#Daphnia
dap_env_data = subset(env_meta,rownames(env_meta) %in% sample_names(ps_dap_4000))
bray <- vegdist(data.frame(t(otu_table(ps_dap_4000))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
envfit_result <- envfit(nMDS, dap_env_data, permutations = 999, na.rm = TRUE) #Remove rows with missing samples
envfit_result
"""
***VECTORS
NMDS1 NMDS2 r2 Pr(>r)
DO 0.04220 0.99911 0.0888 0.089 .
Temperature -0.10277 0.99471 0.1906 0.004 **
pH 0.99929 -0.03773 0.0182 0.640
Conductivity -0.97803 -0.20845 0.0298 0.488
Redox -0.79022 0.61283 0.1657 0.016 *
Chlorophyl 0.84187 -0.53969 0.2421 0.001 ***
MPs 0.46677 -0.88438 0.1714 0.014 *
PE.PP 0.01543 -0.99988 0.0129 0.823
PS 0.56856 -0.82264 0.3091 0.001 ***
PET.polyester 0.54111 -0.84095 0.3193 0.001 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Permutation: free
Number of permutations: 999
10 observations deleted due to missingness
"""
#DB-RDA
scaled_dap_env_data <- as.data.frame(scale(dap_env_data)) #scale metavariables due to different scales
# Calculate correlation matrix
cor_matrix <- cor(scaled_dap_env_data, use = "pairwise.complete.obs")
library(caret)
# Identify highly correlated pairs (absolute correlation > 0.7)
highly_correlated <- findCorrelation(cor_matrix, cutoff = 0.7, verbose = TRUE)
reduced_data <- scaled_dap_env_data[,-highly_correlated]
sample_data(ps_dap_4000) = reduced_data
bray = vegdist(data.frame(t(otu_table(ps_dap_4000))), method="bray")
dbrda = dbrda(bray ~ ., reduced_data, dist="bray", na.action = na.exclude)
summary(dbrda)
anova(dbrda)
anova(dbrda, by="terms", permu=999) #Load a full metadata for bacteria:
plot(dbrda)
"""
Permutation test for dbrda under reduced model
Terms added sequentially (first to last)
Permutation: free
Number of permutations: 999
Model: dbrda(formula = bray ~ Temperature + pH + Conductivity + Redox + Chlorophyl + PE.PP, data = reduced_data, distance = "bray", na.action = na.exclude)
Df SumOfSqs F Pr(>F)
Temperature 1 0.9544 3.3637 0.004 **
pH 1 0.3661 1.2903 0.195
Conductivity 1 0.3771 1.3290 0.208
Redox 1 0.8795 3.0998 0.003 **
Chlorophyl 1 0.7430 2.6188 0.016 *
PE.PP 1 0.2299 0.8103 0.598
Residual 45 12.7680
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
```
```{r}
#Subsample at depth 5000
ps_5000=rarefy_even_depth(ps_original, sample.size=5000, rngseed=1, replace=FALSE) #sample loss: N108
bray <- vegdist(data.frame(t(otu_table(ps_5000))), method="bray")
nMDS <- metaMDS(bray,k=2,distance = 'bray')
#permanova:
permanova = adonis2(bray ~ data.frame(sample_data(ps_5000))$Type)
print(permanova) #0.001 ***
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_5000))$Type)
Df SumOfSqs R2 F Pr(>F)
Model 1 7.265 0.12562 20.544 0.001 ***
Residual 143 50.566 0.87438
Total 144 57.831 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_5000))$Type,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.1999
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.0393 0.039267 1.6587 0.1999
Residuals 143 3.3852 0.023672
"""
#Richness- Figure 3B
library(BiocManager)
library(microbiome)
library(knitr)
#install.packages("patchwork")
library(patchwork)
tab <-microbiome::alpha(ps_5000, index = "all")
meta <- data.frame(sample_data(ps_5000)) #Accessing my sample information from the ps object containing rarefied data
tab$Type = meta$Type
#Chao1
print(t.test(chao1~Type, data=tab)) # t = 8.835, df = 137.79, p-value = 4.145e-15
#Shannon
print(t.test(diversity_shannon~Type, data=tab)) # t = 7.351, df = 143, p-value = 1.39e-11
#Pielou
print(t.test(evenness_pielou~Type, data=tab)) # t = 3.8087, df = 137.37, p-value = 0.0002098
#PCoA: Bacterioplankton- Figure 3C
ps_5000_bac=subset_samples(ps_5000, sample_data(ps_5000)$Type == "Bacterioplankton")
bray <- vegdist(data.frame(t(otu_table(ps_5000_bac))), method="bray")
#Permanova_test
permanova = adonis2(bray ~ data.frame(sample_data(ps_5000_bac))$Category)
print(permanova)
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_5000_bac))$Category)
Df SumOfSqs R2 F Pr(>F)
Model 1 1.4871 0.05024 4.2843 0.001 ***
Residual 81 28.1155 0.94976
Total 82 29.6026 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_5000_bac))$Category,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.08503 .
"""
Analysis of Variance Table
Response: Distances
Df Sum Sq Mean Sq F value Pr(>F)
Groups 1 0.03374 0.033743 3.0401 0.08503 .
Residuals 81 0.89904 0.011099
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
#PCoA: Daphnia- Figure 3D
ps_dap_5000=subset_samples(ps_5000, sample_data(ps_5000)$Type == "Daphnia")
bray <- vegdist(data.frame(t(otu_table(ps_dap_5000))), method="bray")
#Permanova_test
permanova = adonis2(bray ~ data.frame(sample_data(ps_dap_5000))$Category)
print(permanova)
"""
Permutation test for adonis under reduced model
Permutation: free
Number of permutations: 999
adonis2(formula = bray ~ data.frame(sample_data(ps_dap_5000))$Category)
Df SumOfSqs R2 F Pr(>F)
Model 1 1.9006 0.09066 5.9819 0.001 ***
Residual 60 19.0630 0.90934
Total 61 20.9636 1.00000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
"""
# test homogeneity of variance
homog_test_cat <- betadisper(bray, data.frame(sample_data(ps_dap_5000))$Category,bias.adjust=TRUE) #Calculate multivariate dispersions
disp_category=anova(homog_test_cat) #Perform test
print(disp_category) #0.05069
"""
Analysis of Variance Table