/
Data Analysis.Rmd
1722 lines (1475 loc) · 64.7 KB
/
Data Analysis.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: "Data Analysis"
author: "Charis"
output:
pdf_document: default
html_document: default
---
# Materials and Methods
_Within Variables_
Statistical analyses were run within each variable, both independent and dependent, to test if there were significant differences between rootstocks. The distribution of the data was right skewed and justified the use of the Kruskal-Wallis test for all variables except xylem density. Following Kruskall-Wallis tests, Dunn’s test and Pairwise Mann-Whitney tests were run as post-hoc tests. For xylem density, one-way ANOVA was used followed by a post-hoc Tukey’s HSD test.
_Classes_
The imbalance between the number of replicates per sample used for the independent and dependent variables made it impossible to directly compare between the two. Whereas four replicates per rootstock were used for the histological data (independent variables), anywhere from four to 16 replicates per rootstock were used for the DNA concentration (dependent variable). In order to mitigate this issue, the independent variables were sorted into classes to convert them from quantitative variables into qualitative factors. Five classes were established for each independent variable (diameter, density, and surface) and assigned as shown in supplementary table 1.
A three-way ANOVA would have been an ideal test to measure the combined influences of histological classes on DNA concentration, but the data was right skewed and transformations ineffective. As such, separate Kruskal-Wallis tests were run for histological variable DNA concentration combination. These were followed by Dunn’s test and the Pairwise Mann-Whitney test. The “agricolae” package was used to identify Kruskal-Wallis groups as seen in Tables 1-5.
_Correlation_
To investigate potential correlation between histological traits, the Kendall rank correlation test was run and plotted (Figures 3-5) using the “ggpubr” package.
All data analysis was run in R studio version 1.3.959. Essential packages include “ARTool,” “dplyr,” “FSA,” “ggplot2,” “grDevices” and those mentioned above.
# Data Introduction
The _independent variables_ are grapevine xylem histological characteristics:
1. _diameter_ : diameter of xylem vessels (μm)
2. _density_ : density of xylem vessels (nº vessels/mm^2)
3. _surface_ : Proportion of stem surface area covered in xylem
vessels (mm2 xylem/total mm2 surface area)
The _dependent variables_ are :
1. _fungal incidence_ measured as #of infected samples/# total analyzed samples and was calculated for both *Pa. chlamydospora* and *Pm. minimum*, but will not be treated in this analysis.
2. _fungal DNA concentration_ measured as DNA concentration in (pg/uL) samples for each *Pa. chlamydospora* and *Pm. minimum*
Note : from here on *Pa. chlamydospora* and *Pm. minimum* will be referred to as Pch and Pmin for facility.
# Data Prep
The data had to be reorganized everything to fit in the same excel file - "internshipanalysis.xlsx" and used this for all future analysis.
This was necessary as many rootstock names varied for each variable (ie. a rootstock was named "110 RICHTER" in the Pch Incidence file but "RICHTER 110" in the histological data files). Before I could do anything meaningful I had to fix this issue and reorganize the data.
Data import and package installation
```{r data import and packages, warning = FALSE, message = FALSE, results = 'hide'}
# raw data with everything together
library(readxl)
PchPres <- read_excel("internshipanalysis.xlsx", sheet = "Pch incidence")
PminInc <- read_excel("internshipanalysis.xlsx", sheet = "Pmin incidence")
PchConc <- read_excel("internshipanalysis.xlsx", sheet = "Pch conc")
PminConc <- read_excel("internshipanalysis.xlsx", sheet = "Pmin conc")
hist <- read_excel("internshipanalysis.xlsx", sheet = "histological data")
hist.avrgs <- read_excel("internshipanalysis.xlsx", sheet = "hist.avrgs")
charact <- read_excel("internshipanalysis.xlsx", sheet = "rootstock.characteristics")
# Packages
#install.packages("ggpubr")
# install.packages("ggplot2")
# install.packages("dplyr")
# install.packages("grDevices")
# install.packages("ARTool")
# install.packages("agricolae")
# install.packages("FSA")
# install.packages("devtools")
##ggbiplot install (from github so slightly different)
# library(devtools)
# install_github("vqv/ggbiplot")
```
Quick data prep
```{r data prep, warning = FALSE, message = FALSE, results = 'hide'}
#* Pch Conc ####
#PchConc clean up by averages
library(dplyr)
PchMeanConc <- PchConc %>%
group_by(rootstock) %>%
summarise(PchMeanConc = mean(Conc_pg.ul))
PchConc <- dplyr::left_join(PchConc, PchMeanConc, by = "rootstock")
#standard error
standard_error <- function(x) sd(x) / sqrt(length(x))
PchConcError <- PchConc %>%
group_by(rootstock) %>%
summarise(PchConcError = standard_error(Conc_pg.ul))
# join standard error and averages by rootstock
PchConc <- dplyr::left_join(PchConc, PchConcError, by = "rootstock")
PchMeanConc <- dplyr::left_join(PchMeanConc, PchConcError, by = "rootstock")
# remove superfluous columns
PchConc$Code <- NULL
PchConc$Plant <- NULL
PchConc$Sampling <- NULL
PchConc$Conc_ug.ul <- NULL
#* Pmin Conc####
#Pmin Conc clean up by averages
library(dplyr)
PminMeanConc <- PminConc %>%
group_by(rootstock) %>%
summarise(PminMeanConc = mean(Conc_pg.ul))
PminConc <- dplyr::left_join(PminConc, PminMeanConc, by = "rootstock")
#standard error
#std.error function
standard_error <- function(x) sd(x) / sqrt(length(x))
PminConcError <- PminConc %>%
group_by(rootstock) %>%
summarise(PminConcError = standard_error(Conc_pg.ul))
# join standard error and averages by rootstock
PminConc <- dplyr::left_join(PminConc, PminConcError, by = "rootstock")
PminMeanConc <- dplyr::left_join(PminMeanConc, PminConcError, by = "rootstock")
# remove superfluous columns
PminConc$Code <- NULL
PminConc$Plant <- NULL
PminConc$Sampling <- NULL
PminConc$Conc_ug.ul <- NULL
#* Histological####
#organize hist file
hist$`rate diam` <- NULL
hist$`rate dens` <- NULL
hist$`rate surface` <- NULL
hist$`average diameter` <- NULL
hist$`error diameter` <- NULL
hist$`average density` <- NULL
hist$`error density` <- NULL
hist$`average surface` <- NULL
hist$`error surface` <- NULL
hist <- hist %>%
rename(
diameter = 'Diameter (μm)',
density = 'Density (nº vessels/mm2)',
surface = 'Surface vessels/total surface (mm2 xilema/mm2)',
)
library(dplyr)
hist.charact <- dplyr::left_join(hist, charact, by = "rootstock")
```
## Classes
The independent and dependent variables cannot be compared, at least not in their current state. The main issue here is the dependent (DNA concentration and fungal incidence) variable data has a different number of samples/rootstock than the independent (histological) variables. This means that we cannot truly combine all the data into one usable data set without using averages. Averages are potentially useful in preliminary data visualization, but not statistically useful (code for averages lines 89-109). The alternative is to turn the independent variable into a qualitative measure. We will do this by creating "classes" for each independent variable.
These classes are assigned as follows :
- 5 Diameter classes :
<44um, 45-54um, 55-64um, 65-74um, and 75-84 um.
- 5 Density classes :
under 36, 37-46, 47-56, 57-66, 67 and above (nº vessels/mm2)
- 5 Surface classes
.10-.14, .15-.19, .20-24, .24-.30, .31 and above (mm2 xylem/ total mm2)
Classes are summed up in the "hist.groups" sheet and were then inputted into the following sheets of the "internshipanalysis.xlsx" excel file.
-"histwclasses"
-"PchConc"
-"PminConc"
#Data Analysis
## Data Analysis Intro
Steps
1. Data exploration
2. Initial statistical tests
- if the data was parametric ANOVA was used
- if the data was non-parametric, Kruskal-Wallis was used
3. Post hoc tests
- if the data was parametric Tukey's HSD test and student's t-tests were used
- if the data was non-parametric, Dunn and Wilcoxon rank sum tests were used
The data was studied independently for each varaible and then together via the classes.
## Dependent variables - Pch and Pmin DNA Concentration
### Pch DNA Concentration
1. Data exploration. We will evaluate the data for the following:
- A: Outliers and Y distribution
- B: Number of modalites for X
- C: Relation between Y et X
- D: Interactions between Xs
- E: Collinearity between Xs
```{r Pch dist ggplots, warning = FALSE, message = FALSE}
library(ggplot2)
ggplot(PchConc, aes(x=Conc_pg.ul)) +
geom_density(color="darkblue", fill="lightblue") +
labs(x = "Pch DNA concentration", y = "Frequency")
```
```{r Pch conc data exploration, warning = FALSE, message = FALSE}
# Outliers
par(mfrow=c(1,2))
boxplot(PchConc$Conc_pg.ul
,col='red'
,ylab='Conc')
dotchart(PchConc$Conc_pg.ul
,pch=16
, xlab='Conc'
,col='red')
# Distribution of Y vvalues
par(mfrow=c(1,2))
##Histogram
hist(PchConc$Conc_pg.ul
,breaks=8
, xlab='DNA concentration')
## Quantile-Quantile Plot
qqnorm(PchConc$Conc_pg.ul)
qqline(PchConc$Conc_pg.ul)
# B -Number of modalites for X
PchConc$rootstock <- as.factor(PchConc$rootstock)
library(ARTool)
str(PchConc$rootstock)
# C - Relation(s) between Y et X
boxplot(PchConc$Conc_pg.ul~PchConc$rootstock,
varwidth = TRUE,
ylab = "DNA Concenration",
xlab = "Rootstock")
```
2. Data analysis - initial tests
As the data is non-parametric we will likely be unable to use anova, but we will try and check the residuals.
If the residuals are also non-normal we will use a Kruskal-Walllis test and follow with Dunn or Mann-Whiteney (two sample Wilcoxon) post-hoc tests. If the residues are normal we will keep the anova test and follow-up with a Tukey's HSD test.
```{r Pch conc data analysis, warning = FALSE, message = FALSE}
#anova
a2 <- aov(Conc_pg.ul ~ rootstock, data = PchConc)
anova(a2)
#p-value = 1.193e-13 ***, v sig
#normality of residuals check
#distrubution/normality
par(mfrow=c(1,2))
#Histogramme
hist(a2$residuals)
# Q-Q Plot
qqnorm(a2$residuals)
qqline(a2$residuals)
#more normal, but still not that normal
shapiro.test(a2$residuals)
#p-value < 2.2e-16, not normal. Will use Kruskal-Wallis test
PchConc$rootstock <- as.factor(PchConc$rootstock)
#Kruskal.Wallis test
kruskal.test(Conc_pg.ul ~ rootstock, data = PchConc)
#p-value < 2.2e-16, significant
```
3. Post-hoc tests
```{r Pch conc post-hoc, warning = FALSE, message = FALSE}
# #post-hoc test Dunn
# library(FSA)
# dunnTest(Conc_pg.ul ~ rootstock, data = PchConc, method ="bh")
# #post-hoc test Wilcoxon rank sum test
library(ggpubr)
w.g.pchconc<- compare_means(Conc_pg.ul ~ rootstock, PchConc, method="wilcox.test",
ref.group = ".all.")
w.g.pchconc <- subset(w.g.pchconc, p.signif!="ns")
w.g.pchconc <- dplyr::rename(w.g.pchconc, rootstock = "group2")
w.g.pchconc <- left_join(PchMeanConc, w.g.pchconc, by = "rootstock")
colnames(w.g.pchconc)
w.g.pchconc <- w.g.pchconc[, -c(4:6)]
w.g.pchconc <-na.omit(w.g.pchconc)
w.g.pchconc
# library(csv)
# write.csv2(w.g.pchconc, "Pch.wilcox.csv")
```
Dunn test were also run with the above code, but the results are not shown. Wilcox results are shown as they are included in the final ggplots. Only the significant values are listed.
### Pmin DNA concentration
1. Data exploration (same as above)
```{r pmin dist ggplots, warning = FALSE, message = FALSE}
library(ggplot2)
ggplot(PminConc, aes(x=Conc_pg.ul)) +
geom_density(color="darkblue", fill="lightblue") +
labs(x = "Pmin DNA concentration", y = "Frequency")
```
```{r Pmin conc data exploration, warning = FALSE, message = FALSE}
# A - Outliers and Y distribution
# Outliers
par(mfrow=c(1,2))
boxplot(PminConc$Conc_pg.ul
,col='red'
,ylab='Conc')
dotchart(PminConc$Conc_pg.ul
,pch=16
, xlab='Conc'
,col='red')
## Distribution of Y values
par(mfrow=c(1,2))
#Histogram
hist(PminConc$Conc_pg.ul
,breaks=8
, xlab='DNA concentration')
# Quantile-Quantile Plot
qqnorm(PminConc$Conc_pg.ul)
qqline(PminConc$Conc_pg.ul)
# B -Number of modalites for X
PminConc$rootstock <- as.factor(PminConc$rootstock)
library(ARTool)
str(PminConc$rootstock)
# 24 modalities but each one has a different number of samples.
# C - Relation(s) between Y et X
boxplot(PminConc$Conc_pg.ul~PminConc$rootstock,
varwidth = TRUE,
ylab = "DNA Concenration",
xlab = "Rootstock")
```
2. Data analysis - initial tests
As the data is non-parametric we will likely be unable to use anova, but we will try and check the residuals.
If the residuals are also non-normal we will use a Kruskal-Walllis test and follow with Dunn or Mann-Whiteney (two sample Wilcoxon) post-hoc tests. If the residues are normal we will keep the anova test and follow-up with a Tukey's HSD test.
```{r Pmin conc data analysis, warning = FALSE, message = FALSE}
a3 <- aov(Conc_pg.ul ~ rootstock, data = PminConc)
anova(a3)
#p-value < 2.2e-16 ***, v sig
#check normality of residuals
par(mfrow=c(1,2))
#Histogramme
hist(a3$residuals)
# Q-Q Plot
qqnorm(a3$residuals)
qqline(a3$residuals)
#not quite normal
shapiro.test(a3$residuals)
#p-value < 2.2e-16, not normal
PminConc$rootstock <- as.factor(PminConc$rootstock)
kruskal.test(Conc_pg.ul ~ rootstock, data = PminConc)
#p-value = 3.167e-13, significant
```
3. Post-hoc
```{r Pmin conc post-hoc, warning = FALSE, message = FALSE}
#Post-hoc tests
#post-hoc test Dunn
# library(FSA)
# dunnTest(Conc_pg.ul ~ rootstock, data = PminConc, method ="bh")
# #post-hoc test Wilcoxon rank sum test
library(ggpubr)
w.pminconc<- compare_means(Conc_pg.ul ~ rootstock, PminConc, method="wilcox.test",
ref.group = ".all.")
w.pminconc <- subset(w.pminconc, p.signif!="ns")
w.pminconc <- dplyr::rename(w.pminconc, rootstock = "group2")
w.pminconc <- left_join(PminMeanConc, w.pminconc, by = "rootstock")
colnames(w.pminconc)
w.pminconc <- w.pminconc[, -c(4:5)]
w.pminconc <-na.omit(w.pminconc)
w.pminconc
# library(csv)
# write.csv2(w.pminconc, "Pmin.wilcox.csv")
```
Dunn test was run as well but pnly the Wilcoxon results are shown as they will be used in the final ggplots. Only the significant values are listed.
## Independent variables - Histological factors (xylem diameter, density, and surface area)
```{r indep data expl ggplots, warning = FALSE, message = FALSE}
library(ggplot2)
a <- ggplot(hist, aes(x=diameter)) +
geom_density(color="darkblue", fill="lightblue") +
labs(x = "Diameter", y = "Frequency")
b <- ggplot(hist, aes(x=density)) +
geom_density(color="darkblue", fill="lightblue") +
labs(x = "Density", y = "Frequency")
c <- ggplot(hist, aes(x=surface)) +
geom_density(color="darkblue", fill="lightblue") +
labs(x = "Surface", y = "Frequency")
library(ggpubr)
ggarrange(a, b, c, ncol = 2, nrow = 2)
```
### Diameter
1. Data exploration (same as above)
```{r diameter data exploration, warning = FALSE, message = FALSE}
# A - Outliers and Y distribution
# Outliers
par(mfrow=c(1,2))
boxplot(hist$diameter,
col = 'blue')
dotchart(hist$diameter,
col = 'blue')
#Distribution of Y values
par(mfrow=c(1,2))
#Histogram
hist(hist$diameter
,breaks=8
, xlab='diameter')
#Quantile-Quantile Plot
qqnorm(hist$diameter)
qqline(hist$diameter)
# B -Number of modalites for X
summary(hist$rootstock)
# C - Relation(s) between Y et X
boxplot(hist$diameter ~ hist$rootstock,
varwidth = TRUE,
ylab = "Surface",
xlab = "Rootstock")
```
2. Data analysis
As the data is non-parametric we will likely be unable to use anova, but we will try and check the residuals.
If the residuals are also non-normal we will use a Kruskal-Walllis test and follow with Dunn or Mann-Whiteney (two sample Wilcoxon) post-hoc tests.If the residues are normal we will keep the anova test and follow-up with a Tukey's HSD test.
```{r diameter data analysis, warning = FALSE, message = FALSE}
e0 <- aov(diameter ~ rootstock, data = hist)
anova(e0)
#3.106e-09 ***, strongly significant
#normality and distribution of residues
par(mfrow=c(1,2))
#Histogram
hist(e0$residuals)
# Q-Q Plot
qqnorm(e0$residuals)
qqline(e0$residuals)
#decently normal
shapiro.test(e0$residuals)
#p-value = 0.0001813, very close but not normal
hist$rootstock <- as.factor(hist$rootstock)
kruskal.test(diameter ~ rootstock, data = hist)
#p-value = 2.827e-06, significant
```
3. Post-hoc
```{r diamater post hoc, warning = FALSE, message = FALSE}
#Post hoc
#Dunn
# library(FSA)
# dunnTest(diameter ~ rootstock, data = hist, method ="bh")
#Wilcoxon rank sum test
library(ggpubr)
w.diam.r <- compare_means(diameter ~ rootstock, hist, method="wilcox.test",
ref.group = ".all.")
w.diam.r <- subset(w.diam.r, p.signif!="ns")
w.diam.r <- dplyr::rename(w.diam.r, rootstock = "group2")
w.diam.r <- left_join(hist.avrgs, w.diam.r, by = "rootstock")
colnames(w.diam.r)
w.diam.r <- w.diam.r[, -c(4:12)]
w.diam.r <-na.omit(w.diam.r)
w.diam.r
# library(csv)
# write.csv2(w.diam.r, "Diam.r.wilcox.csv")
```
Dunn test was run as well but pnly the Wilcoxon results are shown as they will be used in the final ggplots. Only the significant values are listed.
4. parents
```{r diameter parent data analysis, warning = FALSE, message = FALSE}
x0 <- aov(diameter ~ parents, data = hist.charact)
anova(x0)
#0.004508 **, strongly significant
#normality and distribution of residues
par(mfrow=c(1,2))
#Histogram
hist(x0$residuals)
# Q-Q Plot
qqnorm(x0$residuals)
qqline(x0$residuals)
#looks normal!
shapiro.test(x0$residuals)
#p-value = p-value = 0.001225, not normal
hist.charact$parents <- as.factor(hist.charact$parents)
kruskal.test(diameter ~ parents, data = hist.charact)
#p-value = 0.0004902, significant
# library(FSA)
# dunnTest(diameter ~ parents, data = hist.charact, method ="bh")
#Wilcoxon ranked sum
library(ggpubr)
w.diam.p <- compare_means(diameter ~ parents, hist.charact, method="wilcox.test",
ref.group = ".all.")
w.diam.p <- subset(w.diam.p, p.signif!="ns")
w.diam.p
# library(csv)
# write.csv2(w.diam.p, "Diam.p.wilcox.csv")
```
### Density
1. Data exploration (same as above)
```{r density data exploration, warning = FALSE, message = FALSE}
# A - Outliers and Y distribution
# Outliers
par(mfrow=c(1,2))
boxplot(hist$density,
col = 'blue')
dotchart(hist$diameter,
col = 'blue')
# Distribution of Y vvalues
par(mfrow=c(1,2))
#Histogram
hist(hist$density
,breaks=8
, xlab='density')
#Quantile-Quantile Plot
qqnorm(hist$density)
qqline(hist$density)
# B -Number of modalites for X
summary(hist$rootstock)
# C - Relation(s) between Y et X
boxplot(hist$density ~ hist$rootstock,
varwidth = TRUE,
ylab = "Surface",
xlab = "Rootstock")
```
2. Data analysis
As the data is non-parametric we will likely be unable to use anova, but we will try and check the residuals.
If the residuals are also non-normal we will use a Kruskal-Walllis test and follow with Dunn or Mann-Whiteney (two sample Wilcoxon) post-hoc tests. If the residues are normal we will keep the anova test and follow-up with a Tukey's HSD test.
```{r density data analysis, warning = FALSE, message = FALSE}
e1 <- aov(density ~ rootstock, data = hist)
anova(e1)
#2.572e-13 ***, strongly significant
#normality and distribution of residues
par(mfrow=c(1,2))
#Histogram
hist(e1$residuals)
# Q-Q Plot
qqnorm(e1$residuals)
qqline(e1$residuals)
#looks normal!
shapiro.test(e1$residuals)
#p-value = p-value = 0.06405, very slightly normal!
#so anova test stands and there are signficant differences
```
3. Post-hoc
```{r density post hoc, warning = FALSE, message = FALSE}
#Post hoc
#Tukey's HSD
#TukeyHSD(e1, conf.level=.95)
#Wilcoxon ranked sum
library(ggpubr)
t.dens.r <- compare_means(density ~ rootstock, hist, method="t.test",
ref.group = ".all.")
t.dens.r <- subset(t.dens.r, p.signif!="ns")
t.dens.r <- dplyr::rename(t.dens.r, rootstock = "group2")
t.dens.r <- left_join(hist.avrgs, t.dens.r, by = "rootstock")
colnames(t.dens.r)
t.dens.r <- t.dens.r[, -c(2:4, 7:12)]
t.dens.r <-na.omit(t.dens.r)
t.dens.r
# library(csv)
# write.csv2(t.dens.r, "Dens.r.ttest.csv")
```
Tukey's HSD test was run, but there are far too many results to show in this Rmd file.T-test results are shown as they will be used in the final ggplots. Only the significant values are listed.
4. Parents
```{r density parent data analysis, warning = FALSE, message = FALSE}
x1 <- aov(density ~ parents, data = hist.charact)
anova(x1)
#3.901e-06 ***, strongly significant
#normality and distribution of residues
par(mfrow=c(1,2))
#Histogram
hist(x1$residuals)
# Q-Q Plot
qqnorm(x1$residuals)
qqline(x1$residuals)
#looks normal!
shapiro.test(x1$residuals)
#p-value = p-value = 0.005285, not normal
hist.charact$parents <- as.factor(hist.charact$parents)
kruskal.test(density ~ parents, data = hist.charact)
#p-value = 0.0008763, significant
# library(FSA)
# dunnTest(density ~ parents, data = hist.charact, method ="bh")
#Wilcoxon ranked sum
library(ggpubr)
w.dens.p <- compare_means(density ~ parents, hist.charact, method="wilcox.test",
ref.group = ".all.")
w.dens.p <- subset(w.dens.p, p.signif!="ns")
w.dens.p
# library(csv)
# write.csv2(w.dens.p, "Dens.p.wilcox.csv")
```
### Surface
1. Data exploration (same as above)
```{r surface data exploration, warning = FALSE, message = FALSE}
# A - Outliers and Y distribution
# Outliers
par(mfrow=c(1,2))
boxplot(hist$surface,
col = 'blue')
dotchart(hist$surface,
col = 'blue')
#two outliers
## Distribution of Y vvalues
par(mfrow=c(1,2))
#Histogram
hist(hist$surface
,breaks=8
, xlab='surface')
# Quantile-Quantile Plot
qqnorm(hist$surface)
qqline(hist$surface)
# B -Number of modalites for X
summary(hist$rootstock)
# C - Relation(s) between Y et X
boxplot(hist$surface ~ hist$rootstock,
varwidth = TRUE,
ylab = "Surface",
xlab = "Rootstock")
```
2. Data analysis
As the data is non-parametric we will likely be unable to use anova, but we will try and check the residuals.
If the residuals are also non-normal we will use a Kruskal-Walllis test and follow with Dunn or Mann-Whiteney (two sample Wilcoxon) post-hoc tests. If the residues are normal we will keep the anova test and follow-up with a Tukey's HSD test.
```{r surface data analysis, warning = FALSE, message = FALSE}
e2 <- aov(surface ~ rootstock, data = hist)
anova(e2)
#6.169e-06 ***, strongly significant
#normality and distribution of residues
par(mfrow=c(1,2))
#Histogram
hist(e2$residuals)
# Q-Q Plot
qqnorm(e2$residuals)
qqline(e2$residuals)
#kind of normal
shapiro.test(e2$residuals)
#p-value = 1.152e-13, not normal
hist$rootstock <- as.factor(hist$rootstock)
kruskal.test(surface ~ rootstock, data = hist)
#p-value = 1.308e-07, significant
```
3. Post-hoc
```{r surface post hoc, warning = FALSE, message = FALSE}
#Post hoc
#Dunn
#library(FSA)
#dunnTest(surface ~ rootstock, data = hist, method ="bh")
#Wilcoxon ranked sum
library(ggpubr)
w.surf.r <- compare_means(surface ~ rootstock, hist, method="wilcox.test",
ref.group = ".all.")
w.surf.r <- subset(w.surf.r, p.signif!="ns")
w.surf.r <- dplyr::rename(w.surf.r, rootstock = "group2")
w.surf.r <- left_join(hist.avrgs, w.surf.r, by = "rootstock")
colnames(w.surf.r)
w.surf.r <- w.surf.r[, -c(2:5, 8:12)]
w.surf.r <-na.omit(w.surf.r)
w.surf.r
# library(csv)
# write.csv2(w.surf.r, "Surf.r.wilcox.csv")
```
Dunn test was run as well but pnly the Wilcoxon results are shown as they will be used in the final ggplots. Only the significant values are listed.
4. Parents
```{r surface parent data analysis, warning = FALSE, message = FALSE}
x2 <- aov(surface ~ parents, data = hist.charact)
anova(x2)
#0.007644 **, strongly significant
#normality and distribution of residues
par(mfrow=c(1,2))
#Histogram
hist(x2$residuals)
# Q-Q Plot
qqnorm(x2$residuals)
qqline(x2$residuals)
#looks normal!
shapiro.test(x2$residuals)
#p-value = p-value = 1.095e-13, not normal
hist.charact$parents <- as.factor(hist.charact$parents)
kruskal.test(surface ~ parents, data = hist.charact)
#p-value = 1.875e-06, significant
#post hoc
# library(FSA)
# dunnTest(surface ~ parents, data = hist.charact, method ="bh")
#Wilcoxon ranked sum
library(ggpubr)
w.surf.p <- compare_means(surface ~ parents, hist.charact, method="wilcox.test",
ref.group = ".all.")
w.surf.p <- subset(w.surf.p, p.signif!="ns")
w.surf.p
# library(csv)
# write.csv2(w.surf.p, "Surf.p.wilcox.csv")
```
### PCA
```{r convert to zscores}
library(dplyr)
hist.zscores <- hist.charact %>%
mutate(diameter.zscore = (diameter - mean(diameter))/sd(diameter)) %>%
mutate(density.zscore = (density - mean(density))/sd(density)) %>%
mutate(surface.zscore = (surface - mean(surface))/sd(surface))
```
```{r histological PCA 1}
colnames(hist.zscores)
h.c.pca <- prcomp(hist.zscores[,c(17:19)], center = TRUE,scale. = TRUE)
h.c.pca$center #mean of variables
h.c.pca$scale #standard deviation of vairables
h.c.pca$rotation
summary(h.c.pca)
str(h.c.pca)
```
```{r PCA plot}
library(ggbiplot)
ggbiplot(h.c.pca)
```
Diameter represents 61.0% of variance, density represents 0.32% of variance, and surface represents 0.067% variance. This is likely due to the fact that the surface measurement is not on the same scale as density and diameter.
## Independent v. Dependent
As was already mentioned, the original independent and dependent variables cannot be compared. To combat this the independent variables were converted to qualitative factors (classes).
### Pch Concentration v. Histological Classes
1. Data exploration
```{r pch conc v hist class dist ggplots, warning = FALSE, message = FALSE}
PchConc$diam.class <- as.factor(PchConc$diam.class)
PchConc$dens.class <- as.factor(PchConc$dens.class)
PchConc$surf.class <- as.factor(PchConc$surf.class)
library(ggplot2)
g <- ggplot(PchConc, aes(x = diam.class,y = Conc_pg.ul, color = diam.class)) + geom_boxplot()
Diam.pchplot <- g + geom_jitter(shape = 16, position = position_jitter(0.2)) + theme_classic() +
labs(x = "Diameter Class", y = "Pch DNA Concentration", color = "Diameter Class")
h <- ggplot(PchConc, aes(x = dens.class,y = Conc_pg.ul, color = dens.class)) + geom_boxplot()
Dens.pchplot <- h + geom_jitter(shape = 16, position = position_jitter(0.2)) + theme_classic() +
labs(x = "Density Class", y = "Pch DNA Concentration", color = "Density Class")
i <- ggplot(PchConc, aes(x = surf.class,y = Conc_pg.ul, color = surf.class)) + geom_boxplot()
Surf.pchplot <- i + geom_jitter(shape = 16, position = position_jitter(0.2)) + theme_classic() +
labs(x = "Surface Class", y = "Pch DNA Concentration", color = "Surface Class")
library(ggpubr)
ggarrange(Diam.pchplot, Dens.pchplot, Surf.pchplot, ncol = 2, nrow = 2)
```
```{r pch conc v hist class data exploration, warning = FALSE, message = FALSE}
# Data exploration already run above for y
# X data exploration :
# B -Number of modalites for X
library(ARTool)
str(PchConc)
# as factor
PchConc$diam.class <- as.factor(PchConc$diam.class)
PchConc$dens.class <- as.factor(PchConc$dens.class)
PchConc$surf.class <- as.factor(PchConc$surf.class)
str(PchConc)
# do these factors interact at all?
table(PchConc$diam.class, PchConc$dens.class)
table(PchConc$dens.class, PchConc$surf.class)
table(PchConc$diam.class, PchConc$surf.class)
# C - Relation(s) between Y et X
par(mfrow=c(1,3))
boxplot(PchConc$Conc_pg.ul~PchConc$diam.class,
varwidth = TRUE,
ylab = "DNA Concentration",
xlab = "Diameter Class",
col='lightblue',
main = "")
boxplot(PchConc$Conc_pg.ul~PchConc$dens.class,
varwidth = TRUE,
ylab = "DNA Concentration",
xlab = "Density Class",
col='lightblue',
main = "")
boxplot(PchConc$Conc_pg.ul~PchConc$surf.class,
varwidth = TRUE,
ylab = "DNA Concentration",
xlab = "Surface Class",
col='lightblue',
main = "")
# D - Interactions between Xs
boxplot(PchConc$Conc_pg.ul~PchConc$diam.class*PchConc$dens.class*PchConc$surf.class,
varwidth = TRUE,
ylab = "DNA Concentration",
col='lightblue',
main = "")
```
2. Data analysis
As we have one quantitative dependent variable and three qualitative independent variables, a three-way ANOVA would be the best way to approach this data. Unfortunately though, our data has tended to be very non-parametric (almost following a Poisson distribution), and ANOVA requires normal residuals. We run a three-way ANOVA to see what our residuals might be. Again, we will only keep the ANOVA as our test if our residuals are normal.
```{r 3 way anova pch conc, warning = FALSE, message = FALSE }
# Three way ANOVA
h0 <- lm(Conc_pg.ul ~ diam.class*dens.class*surf.class, data = PchConc)
anova(h0)
#normality of residuals check
#distrubution/normality
par(mfrow=c(1,2))
#Histogram
hist(h0$residuals)
# Q-Q Plot
qqnorm(h0$residuals)
qqline(h0$residuals)
#not at all normal
shapiro.test(h0$residuals)
```
Shapiro test p-value < 2.2e-16, not normal. We cannot run an anova.
To have normal residuals we would have to remove 79 observations (out of 233) and transform with an orderNorm transformation, but this looses too much data. We can try a ranked transformation normally, but even this was not sufficient. The transformation code can be requested, but is not included as it was all unsuccessful. So, we continued with kruskal-wallis and will have to work with one factor at a time. This means we do not know the impact of all three factors together.
- by diameter
```{r kruskal and post hoc pch/diam class, warning = FALSE, message = FALSE, results = 'hide'}
#Kruskal.Wallis test
kruskal.test(Conc_pg.ul ~ diam.class, data = PchConc)
# Kruskal-Wallis rank sum test
#
# data: Conc_pg.ul by diam.class
# Kruskal-Wallis chi-squared = 23.213, df = 4, p-value = 0.0001148
#Post-hoc tests:
#Dunn
PchConc$diam.class <- as.factor(PchConc$diam.class)
# library(FSA)
# dunnTest(Conc_pg.ul ~ diam.class, data = PchConc, method ="bh")
#Wilcoxon ranked sum
library(ggpubr)
w.diam.c <- compare_means(Conc_pg.ul ~ diam.class, PchConc, method="wilcox.test",
ref.group = ".all.")
w.diam.c <- subset(w.diam.c, p.signif!="ns")
w.diam.c
```
- by density
```{r kruskal and post hoc pch/dens class, warning = FALSE, message = FALSE, results = 'hide'}
#Kruskal.Wallis test
kruskal.test(Conc_pg.ul ~ dens.class, data = PchConc)
# Kruskal-Wallis rank sum test
#
# data: Conc_pg.ul by dens.class
# Kruskal-Wallis chi-squared = 13.675, df = 4, p-value = 0.008408
#Post-hoc tests:
#Dunn
PchConc$dens.class <- as.factor(PchConc$dens.class)
# library(FSA)
# dunnTest(Conc_pg.ul ~ dens.class, data = PchConc, method ="bh")
#Wilcoxon ranked sum
library(ggpubr)
w.dens.c <- compare_means(Conc_pg.ul ~ dens.class, PchConc, method="wilcox.test",
ref.group = ".all.")
w.dens.c <- subset(w.dens.c, p.signif!="ns")
w.dens.c
```
- by surface
```{r kruskal and post hoc pch/surf class, warning = FALSE, message = FALSE, results = 'hide'}
kruskal.test(Conc_pg.ul ~ surf.class, data = PchConc)
# Kruskal-Wallis rank sum test
#
# data: Conc_pg.ul by surf.class
# Kruskal-Wallis chi-squared = 22.718, df = 4, p-value = 0.0001442
#Post-hoc tests:
#Dunn
PchConc$surf.class <- as.factor(PchConc$surf.class)
# library(FSA)
# dunnTest(Conc_pg.ul ~ surf.class, data = PchConc, method ="bh")
#Wilcoxon ranked sum
library(ggpubr)
w.surf.c <- compare_means(Conc_pg.ul ~ surf.class, PchConc, method="wilcox.test",
ref.group = ".all.")
w.surf.c <- subset(w.surf.c, p.signif!="ns")
w.surf.c
```
### Pmin Concentration v. Histological Classes
1. Data exploration
```{r pmin conc v hist class dist ggplots, warning = FALSE, message = FALSE}
PminConc$diam.class <- as.factor(PminConc$diam.class)
PminConc$dens.class <- as.factor(PminConc$dens.class)
PminConc$surf.class <- as.factor(PminConc$surf.class)
library(ggplot2)
j <- ggplot(PminConc, aes(x = diam.class,y = Conc_pg.ul, color = diam.class)) + geom_boxplot()
Diam.pminplot <- j + geom_jitter(shape = 16, position = position_jitter(0.2)) + theme_classic() +
labs(x = "Diameter Class", y = "Pmin DNA Concentration", color = "Diameter Class")
k <- ggplot(PminConc, aes(x = dens.class,y = Conc_pg.ul, color = dens.class)) + geom_boxplot()
Dens.pminplot <- k + geom_jitter(shape = 16, position = position_jitter(0.2)) + theme_classic() +
labs(x = "Density Class", y = "Pmin DNA Concentration", color = "Density Class")
l <- ggplot(PminConc, aes(x = surf.class,y = Conc_pg.ul, color = surf.class)) + geom_boxplot()
Surf.pminplot <- l + geom_jitter(shape = 16, position = position_jitter(0.2)) + theme_classic() +
labs(x = "Surface Class", y = "Pmin DNA Concentration", color = "Surface Class")
library(ggpubr)
ggarrange(Diam.pminplot, Dens.pminplot, Surf.pminplot, ncol = 2, nrow = 2)
```
```{r pminconc v hist class data exploration, warning = FALSE, message = FALSE}
# Data exploration already run above for y
# X data exploration :
# B -Number of modalites for X
library(ARTool)
str(PminConc)
# as factor
PminConc$diam.class <- as.factor(PminConc$diam.class)
PminConc$dens.class <- as.factor(PminConc$dens.class)
PminConc$surf.class <- as.factor(PminConc$surf.class)
str(PminConc)
# do these factors interact at all?
table(PminConc$diam.class, PminConc$dens.class)
table(PminConc$dens.class, PminConc$surf.class)
table(PminConc$diam.class, PminConc$surf.class)
# C - Relation(s) between Y et X
boxplot(PminConc$Conc_pg.ul~PminConc$rootstock,
varwidth = TRUE,
ylab = "DNA Concenration",
xlab = "Rootstock")
```
2. Data analysis
Just like above, we have one quantitative dependent variable and three qualitative independent variables, a three-way ANOVA would be the best way to approach this data. Unfortunately though, our data has tended to be very non-parametric (almost following a Poisson distribution), and ANOVA requires normal residuals. We run a three-way ANOVA to see what our residuals might be. Again, we will only keep the ANOVA as our test if our residuals are normal.
```{r 3 way anova pmin conc, warning = FALSE, message = FALSE}
# Three way ANOVA
h1 <- lm(Conc_pg.ul ~ diam.class*dens.class*surf.class, data = PminConc)
anova(h1)
#normality of residuals check
#distribution/normality
par(mfrow=c(1,2))
#Histogram
hist(h1$residuals)
# Q-Q Plot
qqnorm(h1$residuals)
qqline(h1$residuals)
#not at all normal
shapiro.test(h1$residuals)
```
Shapiro test p-value < 2.2e-16, not normal. We cannot run an anova.
Just like Pch it impossible to get to an anova with normal residues without severely manipulating the data.
Code for this is available upon request or in "Transformations.R" file on github.
So we will again continue with kruskal wallis and will have to work with one factor at a time. This means we do not know the impact of all three factors together.
- by diameter
```{r kruskal and post hoc pmin/diam class, warning = FALSE, message = FALSE, results = 'hide'}
kruskal.test(Conc_pg.ul ~ diam.class, data = PminConc)
# Kruskal-Wallis rank sum test
#
# data: Conc_pg.ul by diam.class
# Kruskal-Wallis chi-squared = 21.076, df = 4, p-value = 0.0003059
#Post-hoc tests:
#Dunn
PminConc$diam.class <- as.factor(PminConc$diam.class)
library(FSA)
dunnTest(Conc_pg.ul ~ diam.class, data = PminConc, method ="bh")
#Wilcoxon ranked sum
w.diam.m <- compare_means(Conc_pg.ul ~ diam.class, PminConc, method="wilcox.test",
ref.group = ".all.")
w.diam.m <- subset(w.diam.m, p.signif!="ns")
w.diam.m
```
- by density
```{r kruskal and post hoc pmin/dens class, warning = FALSE, message = FALSE, results = 'hide'}
#Kruskal Wallis