-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnalysis.Rout
1257 lines (1217 loc) · 55 KB
/
Analysis.Rout
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
R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> # Analyses of variance for DLB and Straw Test results ------------------------
> #
> # This script was written by Sydney E. Everhart and Zhian N. Kamvar.
> #
> # Loading packages (and installing if needed) -----------------------------
> #
> # The checkpoint package is a fantastic package that will ensure reproducible
> # research by scanning your project for packages and then installing them to
> # a temporary library from a specific date. This way you get non-invasive
> # reproducibility (as long as MRAN continues to run).
> #
> # This first if statement is asking whether or not we are inside a binder
> # session. The binder session allows the analysis to be re-run interactively
> # in the cloud. If joyvan is run, the checkpoint package is not needed.
> if (Sys.getenv("USER") != "jovyan") {
+ if (!require("checkpoint")) {
+ install.packages("checkpoint", repos = "https://cran.rstudio.com")
+ library("checkpoint")
+ }
+ dir.create(".checkpoint")
+ checkpoint(snapshotDate = "2018-02-23", checkpointLocation = ".")
+ }
Loading required package: checkpoint
checkpoint: Part of the Reproducible R Toolkit from Microsoft
https://mran.microsoft.com/documents/rro/reproducibility/
Scanning for packages used in this project
- Discovered 14 packages
All detected packages already installed
checkpoint process complete
---
Warning message:
In dir.create(".checkpoint") : '.checkpoint' already exists
> # Some of the output you can expect to see:
> # library("checkpoint")
> #>
> #> # checkpoint: Part of the Reproducible R Toolkit from Microsoft
> #> # https://mran.microsoft.com/documents/rro/reproducibility/
> #
> # checkpoint("2018-02-22")
> #> Can I create directory~/.checkpointfor internal checkpoint use?
> #>
> #> Continue (y/n)? y
> #> Scanning for packages used in this project
> #> - Discovered 10 packages
> #> Installing packages used in this project
> #> - Installing ‘agricolae’
> #> agricolae
> #> - Installing ‘gridExtra’
> #> gridExtra
> #
> # ...
> #
> #> checkpoint process complete
> #> ---
>
>
> # Packages for analysis and graphing --------------------------------------
> library("tidyverse") # data wrangling and rectangling + ggplot2
── Attaching packages ─────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 2.2.1 ✔ purrr 0.2.4
✔ tibble 1.4.1 ✔ dplyr 0.7.4
✔ tidyr 0.8.0 ✔ stringr 1.2.0
✔ readr 1.1.1 ✔ forcats 0.3.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
> library("readxl") # read excel files
> library("plotrix") # std.error() function
> library("cowplot") # multi-panel plotting
Attaching package: ‘cowplot’
The following object is masked from ‘package:ggplot2’:
ggsave
> library("agricolae") # LSD test
> library("lmerTest") # random effects ANOVA
Loading required package: Matrix
Attaching package: ‘Matrix’
The following object is masked from ‘package:tidyr’:
expand
Loading required package: lme4
Attaching package: ‘lmerTest’
The following object is masked from ‘package:lme4’:
lmer
The following object is masked from ‘package:stats’:
step
> library("lubridate") # for converting stupid datetime values from excel
Attaching package: ‘lubridate’
The following object is masked from ‘package:base’:
date
>
> # Packages of convenience -------------------------------------------------
> library("here") # to burn setwd() to the ground
here() starts at /Users/zhian/Documents/Everhart/SscPhenoProj
Attaching package: ‘here’
The following object is masked from ‘package:lubridate’:
here
> library("sessioninfo") # to know where we stand
>
> dir.create(here("clean_data"))
Warning message:
In dir.create(here("clean_data")) :
'/Users/zhian/Documents/Everhart/SscPhenoProj/clean_data' already exists
> dir.create(here("figures"))
Warning message:
In dir.create(here("figures")) :
'/Users/zhian/Documents/Everhart/SscPhenoProj/figures' already exists
>
> # Reading raw data from Excel file ----------------------------------------
> #
> # To read in the excel data, we have to ignore four possible missing values.
> # Additionally, we are enforcing column types in these data so isolate and
> # cultivar numbers are represented as character data instead of numbers.
> #
> # Moreover, because of floating point conversion issues, all number are rounded
> # to three decimal places as this is how they are represented in the
> # spreadsheet.
> excel_nas <- c("", "NA", ".", "#VALUE!")
> data_path <- here("Brazilian agressiveness_raw_data-final2.xlsx")
> ssc_summary <- read_excel(data_path, sheet = "Summary", na = excel_nas, col_names = FALSE)
> colnames(ssc_summary) <- c("sheetid", "projdesc")
> ssc_summary
# A tibble: 9 x 2
sheetid projdesc
<chr> <chr>
1 A 70 isolates vs Dassel - soybean
2 B Straw test_32 isolates_dry bean_G122
3 C 29 isolates vs IAC_DLB
4 D Straw test_28_isolates_IAC_Alv_Brazil
5 E Soybean cultivars
6 F First exp_rep_ DLB_dry bean cultivars_2B and 2D
7 G Second exp_re_DLB_dry bean cultivars_2B
8 H First exp_rep_strawtest_dry bean cultivars_2B and 2D
9 I Second exp_rep_ strawtest_dry bean cultivars_2D
> #
> # Because all the 97X isolates have the 97 part removed, I'm creating a little
> # function to add it in so that the data can be combined later on.
> fix_isolate_name <- . %>%
+ mutate(Isolate = case_when(
+ grepl("^[0-9][A-Z]$", Isolate) ~ paste0("97", Isolate),
+ TRUE ~ Isolate
+ ))
> # Evaluation of isolates --------------------------------------------------
> #
> # A 70 isolates vs Dassel - soybean ## Partially resistant
> # B Straw test_32 isolates_dry bean_G122 ## Partially resistant
> # C 29 isolates vs IAC_DLB
> # D Straw test_28_isolates_IAC_Alv_Brazil
>
> aproj <- read_excel(data_path, sheet = "A", na = excel_nas,
+ col_types = c("text", "text", "text", "text", "text", "numeric")) %>%
+ dplyr::mutate_if(is.numeric, round, 3) %>%
+ fix_isolate_name %>%
+ readr::write_csv(path = here("clean_data", "A_DLB_SoyBean_Dassel.csv"))
>
> # The G122 project is contained in two different sheets that need to be joined
> # together. The first step is to read in the csv data. The first column will
> # be renamed to X1 automatically. The first colum is the full isolate names.
> # This is necessary to confirm that Block is in the correct order.
> bproj_raw <- read_csv(here("Mensure and score in different days_straw test.csv"),
+ col_types = cols(
+ X1 = col_character(),
+ Block = col_character(),
+ `3 dai` = col_double(),
+ `6 dai` = col_double(),
+ `8 dai` = col_double(),
+ AUDPC = col_double(),
+ `After first node` = col_double()
+ ),
+ na = excel_nas)
Warning message:
Missing column names filled in: 'X1' [1]
> # The next step is to read in the excel sheet B and filter it.
> bproj <- read_excel(data_path, sheet = "B",na = excel_nas, range = "A1:F385",
+ col_types = c("text", "text", "numeric", "numeric",
+ "numeric", "numeric")) %>%
+ fix_isolate_name %>%
+ dplyr::mutate_if(is.numeric, round, 3) %>%
+ dplyr::group_by(Isolate) %>%
+ dplyr::mutate(Block = as.character(seq(n()))) %>%
+ dplyr::ungroup() %>%
+ dplyr::inner_join(bproj_raw,
+ by = c("Isolate" = "X1",
+ "8 dai (cm)" = "8 dai",
+ "AUDPC",
+ "After first node",
+ "Block")) %>%
+ dplyr::select(Isolate_number, Isolate, Block,
+ `3 dai`, `6 dai`, `8 dai (cm)`,
+ everything()) %>%
+ readr::write_csv(path = here("clean_data", "B_ST_DryBean_G122.csv"))
>
> stopifnot(nrow(bproj) == nrow(bproj_raw))
>
> cproj <- read_excel(data_path, sheet = "C", na = excel_nas,
+ col_types = c("text", "text", "text", "text", "text",
+ "numeric", "numeric", "numeric", "numeric",
+ "numeric", "numeric")) %>%
+ dplyr::mutate_if(is.numeric, round, 3) %>%
+ fix_isolate_name %>%
+ readr::write_csv(path = here("clean_data", "C_DLB_DryBean_IAC-Alvorada.csv"))
>
> dproj <- read_excel(data_path, sheet = "D", na = excel_nas,
+ col_types = c("text", "text", "numeric", "numeric")) %>%
+ dplyr::mutate_if(is.numeric, round, 3) %>%
+ fix_isolate_name %>%
+ readr::write_csv(path = here("clean_data", "D_ST_DryBean_IAC-Alvorada.csv"))
>
>
> # Evaluation of cultivars -------------------------------------------------
> # E Soybean cultivars
> # F First exp_rep_ DLB_dry bean cultivars_2B and 2D
> # G Second exp_re_DLB_dry bean cultivars_2B
> # H First exp_rep_strawtest_dry bean cultivars_2B and 2D
> # I Second exp_rep_ strawtest_dry bean cultivars_2D
>
> eproj <- read_excel(data_path, sheet = "E", na = excel_nas,
+ col_types = c("text", "text", "text","text", "numeric")) %>%
+ dplyr::mutate_if(is.numeric, round, 3) %>%
+ readr::write_csv(path = here("clean_data", "E_DLB_Soybean_Cultivars.csv"))
>
> fproj <- read_excel(data_path, sheet = "F", na = excel_nas, range = "A1:N277",
+ col_types = c("text", "text", "text", "text", "numeric",
+ "numeric", "numeric", "numeric", "numeric",
+ "numeric", "numeric", "numeric", "numeric",
+ "numeric")) %>%
+ dplyr::mutate_if(is.numeric, round, 3) %>%
+ readr::write_csv(path = here("clean_data", "F_DLB_DryBean_Cultivars-1.csv"))
>
> gproj <- read_excel(data_path, sheet = "G", na = excel_nas, range = "A1:I277",
+ col_types = c("text", "text", "text", "numeric", "numeric",
+ "numeric", "numeric", "numeric", "numeric")) %>%
+ dplyr::mutate_if(is.numeric, round, 3) %>%
+ readr::write_csv(path = here("clean_data", "G_DLB_DryBean_Cultivars-2.csv"))
>
> hproj <- read_excel(data_path, sheet = "H",na = excel_nas, range = "A1:E323",
+ col_types = c("text", "text", "text", "text", "numeric")) %>%
+ dplyr::mutate_if(is.numeric, round, 3) %>%
+ readr::write_csv(path = here("clean_data", "H_ST_DryBean_Cultivars-1.csv"))
>
>
> iproj <- read_excel(data_path, sheet = "I",na = excel_nas, range = "A1:D286",
+ col_types = c("text", "text", "text", "numeric")) %>%
+ dplyr::mutate_if(is.numeric, round, 3) %>%
+ dplyr::mutate(Cultivar = case_when(
+ Cultivar == "IPR139" ~ "IPR 139",
+ TRUE ~ Cultivar
+ )) %>%
+ readr::write_csv(path = here("clean_data", "I_ST_DryBean_Cultivars-2.csv"))
>
>
> # isolate origin information ----------------------------------------------
> # Downloading the file from the open science framework.
> the_download <- try(download.file("https://osf.io/2yfre/download", here("MasterIsolateList.xlsx")))
trying URL 'https://osf.io/2yfre/download'
Content type 'application/octet-stream' length 49473 bytes (48 KB)
==================================================
downloaded 48 KB
> if (!inherits(the_download, "try-error")){
+ # reading in the excel sheet has its own problems since the date column contains
+ # part dates and part text and they get screwed up no matter what you do. The
+ # way I've dealt with this: import as dates and then convert what didn't parse
+ # into the number of days since 1899-12-30
+ metadata <- read_excel(here("MasterIsolateList.xlsx"), col_types = "text", na = c("NA", "")) %>%
+ mutate(date = as.Date(parse_date_time(`JRS-Collection Date`, c("mdy", "y")))) %>%
+ mutate(date = case_when(
+ is.na(date) ~ as.Date("1899-12-30") + days(as.integer(`JRS-Collection Date`)),
+ TRUE ~ date
+ )) %>%
+ select(-`JRS-Collection Date`) %>%
+ readr::write_csv(here("clean_data", "MasterIsolateList.csv"))
+ # This table provides information on how to find specific isolates in the JR
+ # Steadman collection. Here, we will challenge it against the A-D projects and
+ # see which isolates do not match:
+ anti_join(aproj, metadata, by = c("Isolate" = "AP-GenoID")) %>% count(Isolate) %>% print()
+ anti_join(bproj, metadata, by = c("Isolate" = "AP-GenoID")) %>% count(Isolate) %>% print()
+ anti_join(cproj, metadata, by = c("Isolate" = "AP-GenoID")) %>% count(Isolate) %>% print()
+ anti_join(dproj, metadata, by = c("Isolate" = "AP-GenoID")) %>% count(Isolate) %>% print()
+ }
# A tibble: 3 x 2
Isolate n
<chr> <int>
1 1* 30
2 139 30
3 33 30
# A tibble: 0 x 2
# ... with 2 variables: Isolate <chr>, n <int>
# A tibble: 2 x 2
Isolate n
<chr> <int>
1 972B 30
2 972D 30
# A tibble: 2 x 2
Isolate n
<chr> <int>
1 972B 11
2 972D 11
Warning messages:
1: 11 failed to parse.
2: In period(day = x) : NAs introduced by coercion
>
> # Analysis of aggressiveness (variation by isolate) -----------------------
> #
> # In this part, we will summarize values for each replicate and then use these
> # to create a strip chart.
> #
> ### 70 isolates vs. Dassel soybean in detached leaf assay
> asum <- aproj %>%
+ group_by(Isolate, Collection) %>%
+ summarise(
+ n = n(),
+ mean = mean(Area, na.rm = TRUE),
+ min = min(Area, na.rm = TRUE),
+ max = max(Area, na.rm = TRUE),
+ sd = sd(Area, na.rm = TRUE),
+ se = plotrix::std.error(Area, na.rm = TRUE)
+ )
> bsum <- bproj %>%
+ group_by(Isolate) %>%
+ summarise(
+ n = n(),
+ mean = mean(Score, na.rm = TRUE),
+ min = min(Score, na.rm = TRUE),
+ max = max(Score, na.rm = TRUE),
+ sd = sd(Score, na.rm = TRUE),
+ se = plotrix::std.error(Score, na.rm = TRUE)
+ )
> csum <- cproj %>%
+ group_by(Isolate, Collection) %>%
+ summarise(
+ n = n(),
+ mean = mean(`48 horas`, na.rm = TRUE),
+ min = min(`48 horas`, na.rm = TRUE),
+ max = max(`48 horas`, na.rm = TRUE),
+ sd = sd(`48 horas`, na.rm = TRUE),
+ se = plotrix::std.error(`48 horas`, na.rm = TRUE)
+ )
> dsum <- dproj %>%
+ group_by(Isolate) %>%
+ summarise(
+ n = n(),
+ mean = mean(Score, na.rm = TRUE),
+ min = min(Score, na.rm = TRUE),
+ max = max(Score, na.rm = TRUE),
+ sd = sd(Score, na.rm = TRUE),
+ se = plotrix::std.error(Score, na.rm = TRUE)
+ )
>
> # We want to create a single plot that contains both the results from the
> # detached leaf bioassay AND the straw test per isolate (sheets A-D).
>
>
> dlb <- bind_rows(a = asum, c = csum, .id = "proj") %>%
+ mutate(proj = case_when(
+ proj == "a" & Collection == "first" ~ "Dassel (21 dae)",
+ proj == "a" & Collection == "second" ~ "Dassel (28 dae)",
+ proj == "a" & Collection == "third" ~ "Dassel (35 dae)",
+ proj == "c" & Collection == "first" ~ "IAC-Alvorada (21 dae)",
+ proj == "c" & Collection == "second" ~ "IAC-Alvorada (28 dae)",
+ proj == "c" & Collection == "third" ~ "IAC-Alvorada (35 dae)"
+ ))
> st <- bind_rows(G122 = bsum, `IAC-Alvorada` = dsum, .id = "proj")
>
> sydney_theme <- theme_bw(base_size = 16, base_family = "Helvetica") +
+ theme(axis.text = element_text(color = "black")) +
+ theme(axis.title.x = element_blank()) +
+ theme(axis.text.x = element_text(hjust = 1, vjust = 1, angle = 45, color = "black")) +
+ theme(panel.border = element_rect(size = 1))
>
> set.seed(2018-02-27)
> p2 <- dlb %>%
+ ggplot(mapping=aes(x = proj, y = mean)) +
+ geom_jitter(width = .1, height = 0, shape = 21, color = "black",
+ fill = "white", size = 3.5, alpha = 2.5/4, stroke = 1) +
+ stat_summary(fun.y = mean, geom = "point", shape = 95, size = 17, color = "black") +
+ labs(y = expression(paste("Detached leaf bioassay ", (cm^2) ))) +
+ sydney_theme
>
> p2
Warning messages:
1: Removed 3 rows containing non-finite values (stat_summary).
2: Removed 3 rows containing missing values (geom_point).
> p3 <- st %>%
+ ggplot(mapping = aes(x = proj, y = mean)) +
+ geom_jitter(width = .1, height = 0, shape = 21, color = "black",
+ fill = "white", size = 3.5, alpha = 2.5/4, stroke = 1) +
+ stat_summary(fun.y = mean, geom = "point", shape = 95, size = 17, color = "black") +
+ scale_y_continuous(position = "right", limits = c(1, 9), breaks = c(1, 3, 5, 7, 9)) +
+ labs(y = "Straw test rating") +
+ sydney_theme
>
> aggressive_plot <- cowplot::plot_grid(p2, p3, labels = "AUTO", align = "h",
+ rel_widths = c(2.75, 1),
+ label_size = 16,
+ label_fontfamily = "Helvetica",
+ label_x = c(A = 0.1650, B = 0.075),
+ label_y = c(A = 0.975, B = 0.975))
Warning messages:
1: Removed 3 rows containing non-finite values (stat_summary).
2: Removed 3 rows containing missing values (geom_point).
> aggressive_plot
> cowplot::ggsave(filename = here("figures", "DAB-ST-stripplot.pdf"),
+ plot = aggressive_plot,
+ width = 178,
+ height = 178*(0.621),
+ units = "mm")
> cowplot::ggsave(filename = here("figures", "DAB-ST-stripplot.png"),
+ plot = aggressive_plot,
+ dpi = 600,
+ width = 178,
+ height = 178*(0.621),
+ units = "mm")
> cowplot::ggsave(filename = here("figures", "DAB-ST-stripplot.tiff"),
+ dpi = 900,
+ plot = aggressive_plot,
+ width = 178,
+ height = 178*(0.621),
+ units = "mm")
>
> # LSD Test and ANOVA ------------------------------------------------------
> #
> # We are using a random effects model due to the presence of blocks and leaf
> # age. This is implemented in the lmerTest package, which wraps lme4
> #
> # By default, R treats the first sample as the control and creates the ANOVA
> # model trying to find differences from the control. In our case, we want to
> # use orthoganal contrasts:
> op <- options(contrasts = c("contr.helmert", "contr.poly"))
>
> #' Custom Least Significant Difference
> #'
> #' Because LSD.test from agricolae only uses lm and aov models, I have to do
> #' some wrangling to get it to work for lmerTest objects. This helper function
> #' will do that for me.
> #'
> #' @param response a vector of response variables used to build the model
> #' @param trt a vector with the treatment variable to be assessed
> #' @param model a model returned from lmer
> #' @param ... arguments to be passed to LSD.test()
> #' @param plot an argument of whether or not to plot the results (default: TRUE)
> #'
> #' @return
> #'
> #' an object of class "group" from agricolae
> #'
> myLSD <- function(response, trt, model, ..., plot = TRUE){
+ DFE <- df.residual(model)
+ MSE <- deviance(model, REML = FALSE)/DFE
+ res <- LSD.test(y = response, trt = trt, DFerror = DFE, MSerror = MSE, ...)
+ plot(res, variation = "SE")
+ res
+ }
>
> # Test DLB by Isolate -----------------------------------------------------
> #
> # We want to assess whether or not there is a difference between isolates in
> # our assay. Since there are different leaf ages, we also want to include that
> # in the model to confirm that there is no difference due to this factor.
> #
> # Here we are analyzing the data sets for Dassel and IAC-Alvorada. Because we
> # want to test if there are differences between isolates themselves, but want to
> # account for the effects of Collection and section, we will code these as
> # random effects by specifying (1 | Collection) + (1 | Section), which accounts
> # for both of these before assessing Isolate.
>
> # Dassel by Isolate -------------------------------------------------------
> Dassel_model <- lmer(Area ~ Isolate + (1 | Collection) + (1 | Section), data = aproj)
> anova(Dassel_model)
Analysis of Variance Table of type III with Satterthwaite
approximation for degrees of freedom
Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
Isolate 10566 165.09 64 47.882 10.884 9.77e-15 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> Dassel_LSD <- myLSD(aproj$Area, aproj$Isolate, Dassel_model, p.adj = "bonferroni")
>
> # From this, we can see that Isolate is significantly different. However, we
> # noticed earlier that there was a stark contrast between the collection times.
> # Here we can add collection time as a fixed effect in our model and see if it
> # is significant.
>
> Dassel_model2 <- lmer(Area ~ Isolate + Collection + (1 | Section), data = aproj)
> anova(Dassel_model2)
Analysis of Variance Table of type III with Satterthwaite
approximation for degrees of freedom
Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
Isolate 10565.7 165.1 64 47.89 10.884 9.659e-15 ***
Collection 6433.1 3216.5 2 2031.04 212.069 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> Dassel_LSD2 <- myLSD(aproj$Area, aproj$Isolate, Dassel_model2, p.adj = "bonferroni")
>
> # Indeed it is significant, so we will now analyze each collection time
> # separately.
>
> aproj %>%
+ group_by(Collection) %>%
+ summarize(model = list(broom::tidy(anova(lmer(Area ~ Isolate + (1 | Section)))))) %>%
+ unnest()
# A tibble: 3 x 8
Collection term sumsq meansq NumDF DenDF statistic p.value
<chr> <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
1 first Isolate 5129 80.1 64 0 7.34 NaN
2 second Isolate 6367 99.5 64 123 10.3 0
3 third Isolate 7270 114 64 12.2 10.4 0.0000385
Warning messages:
1: In pf(F.stat, qr(Lc)$rank, nu.F) : NaNs produced
2: In tidy.anova(anova(lmer(Area ~ Isolate + (1 | Section)))) :
The following column names in ANOVA output were not recognized or transformed: NumDF, DenDF
3: In tidy.anova(anova(lmer(Area ~ Isolate + (1 | Section)))) :
The following column names in ANOVA output were not recognized or transformed: NumDF, DenDF
4: In tidy.anova(anova(lmer(Area ~ Isolate + (1 | Section)))) :
The following column names in ANOVA output were not recognized or transformed: NumDF, DenDF
>
> # Everything is significant while separating these out, so we can conclude that,
> # while the experiments differed, they only differed in magnitude, but not
> # pattern. We can see the magnitude of how the experiments changed by looking
> # at the collection response, specifically.
>
> myLSD(aproj$Area, aproj$Collection, Dassel_model2, p.adj = "bonferroni")
$statistics
MSerror Df Mean CV t.value MSD
5.722104 2031 9.309454 25.6953 2.395965 0.3063545
$parameters
test p.ajusted name.t ntr alpha
Fisher-LSD bonferroni trt 3 0.05
$means
response std r LCL UCL Min Max Q25 Q50
first 11.442549 4.307224 700 11.265238 11.619860 0.002 30.476 8.51950 11.6565
second 9.330329 5.055385 700 9.153018 9.507640 0.000 25.697 5.58525 9.5875
third 7.155486 5.004951 700 6.978175 7.332797 0.000 22.755 2.76675 6.5155
Q75
first 14.52775
second 13.06325
third 10.83000
$comparison
NULL
$groups
response groups
first 11.442549 a
second 9.330329 b
third 7.155486 c
attr(,"class")
[1] "group"
>
> asum %>%
+ group_by(Collection) %>%
+ summarize(mean = mean(mean))
# A tibble: 3 x 2
Collection mean
<chr> <dbl>
1 first 11.3
2 second 9.12
3 third 7.13
>
>
> # IAC-Alvorada by Isolate -------------------------------------------------
> # Here, we are performing the same analysis with the IAC-Alvorada data. We don't
> # expect Collection to be significant in this model.
> IAC_model <- lmer(`48 horas` ~ Isolate + (1 | Collection) + (1 | Block), data = cproj)
> anova(IAC_model)
Analysis of Variance Table of type III with Satterthwaite
approximation for degrees of freedom
Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
Isolate 14188 525.48 27 712.21 20.468 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> IAC_LSD <- myLSD(cproj$`48 horas`, cproj$Isolate, IAC_model, p.adj = "bonferroni")
>
> # Again, because we saw the difference in Dassel if we considered leaf age, we
> # will set that as a fixed effect and test it here.
> IAC_model2 <- lmer(`48 horas` ~ Isolate + Collection + (1 | Block), data = cproj)
> anova(IAC_model2)
Analysis of Variance Table of type III with Satterthwaite
approximation for degrees of freedom
Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
Isolate 14200.3 525.94 27 711.88 20.4855 < 2.2e-16 ***
Collection 299.8 149.90 2 776.31 5.8386 0.003042 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> IAC_LSD2 <- myLSD(cproj$`48 horas`, cproj$Isolate, IAC_model2, p.adj = "bonferroni")
>
> # Again, the collection time appears to be slightly significant, so we can check
> # to see if this affected the outcome by separating the collections
>
> cproj %>%
+ group_by(Collection) %>%
+ summarize(model = list(broom::tidy(anova(lmer(`48 horas` ~ Isolate + (1 | Block)))))) %>%
+ unnest()
# A tibble: 3 x 8
Collection term sumsq meansq NumDF DenDF statistic p.value
<chr> <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
1 first Isolate 8490 327 26 226 23.1 0
2 second Isolate 4171 160 26 250 13.0 0
3 third Isolate 9646 371 26 253 17.3 0
Warning messages:
1: In tidy.anova(anova(lmer(`48 horas` ~ Isolate + (1 | Block)))) :
The following column names in ANOVA output were not recognized or transformed: NumDF, DenDF
2: In tidy.anova(anova(lmer(`48 horas` ~ Isolate + (1 | Block)))) :
The following column names in ANOVA output were not recognized or transformed: NumDF, DenDF
3: In tidy.anova(anova(lmer(`48 horas` ~ Isolate + (1 | Block)))) :
The following column names in ANOVA output were not recognized or transformed: NumDF, DenDF
>
> # Okay, we can see that everything still appears significant after considering
> # collection separately.
> IAC_LSD2 <- myLSD(cproj$`48 horas`, cproj$Collection, IAC_model2, p.adj = "bonferroni")
>
> # It appears that the third collection time is different in magnitude from the
> # first two, but only at p = 0.003
> csum %>%
+ group_by(Collection) %>%
+ summarize(mean = mean(mean, na.rm = TRUE))
# A tibble: 3 x 2
Collection mean
<chr> <dbl>
1 first 13.2
2 second 13.7
3 third 14.5
>
> # Straw Test: Isolates
> #
> # Straw tests are not performed on varying tissue age, so we need only compare
> # by isolate here. We are treating each replicate as a random effect
> #
> #
> # G122 by Isolate ---------------------------------------------------------
> G122_model <- lmer(Score ~ Isolate + (1 | Block), data = bproj)
> anova(G122_model)
Analysis of Variance Table of type III with Satterthwaite
approximation for degrees of freedom
Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
Isolate 112.69 3.6353 31 340.07 5.3378 6.661e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> G122_LSD <- myLSD(bproj$Score, bproj$Isolate, G122_model, p.adj = "bonferroni")
> # Isolate is significant
>
> # IAC-Alvorada by Isolate: Straw Test -------------------------------------
> IAC_ST_model <- lmer(Score ~ Isolate + (1 | Rep), data = dproj)
> anova(IAC_ST_model)
Analysis of Variance Table of type III with Satterthwaite
approximation for degrees of freedom
Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
Isolate 341.1 12.633 27 280 11.458 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> ISC_ST_LSD <- myLSD(dproj$Score, dproj$Isolate, IAC_ST_model, p.adj = "bonferroni")
> # Isolate is significant, however, this is largely driven by one
> # under-performing isolate (972D).
>
> dproj2 <- filter(dproj, Isolate != "972D")
> IAC_ST_model2 <- lmer(Score ~ Isolate + (1 | Rep), data = dproj2)
> anova(IAC_ST_model2)
Analysis of Variance Table of type III with Satterthwaite
approximation for degrees of freedom
Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
Isolate 111.76 4.2986 26 270 3.8664 7.694e-09 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> ISC_ST_LSD2 <- myLSD(dproj2$Score, dproj2$Isolate, IAC_ST_model2, p.adj = "bonferroni")
> # Isolate is significant, however, this is largely driven by one
> # under-performing isolate (2D).
>
> # Summary table across isolates -------------------------------------------
> #
> # It would be nice to find out if there are any isolates that are consistently
> # outperforming all other isolates. Here, I will create a table that aggregates
> dir.create(here("tables"))
Warning message:
In dir.create(here("tables")) :
'/Users/zhian/Documents/Everhart/SscPhenoProj/tables' already exists
> # the isolate means per experiment.
> isolate_data <- bind_rows(`Dassel DLB` = asum,
+ `IAC-Alvorada DLB` = csum,
+ `G122 Straw Test` = bsum,
+ `IAC-Alvorada Straw Test` = dsum,
+ .id = "Experiment")
> isolate_data %>%
+ filter(grepl("Straw", Experiment)) %>%
+ group_by(Experiment) %>%
+ mutate(class = case_when(
+ mean >= 7 ~ "Aggressive (7-9)",
+ mean >= 4 ~ "Intermediate (4-6)",
+ TRUE ~ "Non-Aggressive (1-3)"
+ )) %>%
+ mutate(n = n()) %>%
+ count(class, n) %>%
+ mutate(n = 100 * (nn/n)) %>%
+ rename(N = nn, Class = class, `%` = n) %>%
+ select(Experiment, Class, N, `%`) %>%
+ readr::write_csv("tables/straw-test-classifications.csv")
> isolate_summary <- isolate_data %>%
+ group_by(Experiment, Collection) %>%
+ summarize(Min = round(min(min), 3),
+ Mean = round(mean(mean, na.rm = TRUE), 3),
+ Max = round(max(max), 3),
+ `Top 10` = list(
+ data_frame(
+ Isolate = head(Isolate[order(mean, decreasing = TRUE)], 10),
+ `Isolate Mean` = head(sort(mean, decreasing = TRUE), 10),
+ rank = 1:10
+ )
+ )) %>%
+ arrange(grepl("Straw", Experiment))
>
> isolate_summary_print <- isolate_summary %>%
+ rowwise() %>%
+ mutate(`Top 10` = paste(`Top 10`$Isolate, collapse = ", ")) %>%
+ readr::write_csv(here("tables/isolate_summary.csv"))
>
> # Because this isolate table may be difficult to parse, A better solution would
> # be to arrange these isolates by the number of times an isolate is in the top
> # 10 of any experiment and is assessed over at least three of the four
> # experiments.
>
> experiment_order <-c(
+ "Dassel DLB_first" = "Dassel DLB (21 dae)",
+ "Dassel DLB_second" = "Dassel DLB (28 dae)",
+ "Dassel DLB_third" = "Dassel DLB (35 dae)",
+ "IAC-Alvorada DLB_first" = "IAC-Alvorada DLB (21 dae)",
+ "IAC-Alvorada DLB_second" = "IAC-Alvorada DLB (28 dae)",
+ "IAC-Alvorada DLB_third" = "IAC-Alvorada DLB (35 dae)",
+ "G122 Straw Test_NA" = "G122 Straw Test",
+ "IAC-Alvorada Straw Test_NA" = "IAC-Alvorada Straw Test"
+ )
> isolate_data_arranged <- isolate_data %>%
+ ungroup() %>%
+ filter(is.finite(mean)) %>%
+ unite(col = EC, Experiment, Collection, remove = FALSE) %>%
+ group_by(EC) %>%
+ mutate(rank = rank(mean, ties.method = "last", na.last = TRUE)) %>%
+ arrange(-rank) %>%
+ mutate(rank = seq(n())) %>%
+ ungroup() %>%
+ arrange(grepl("Straw", EC)) %>%
+ mutate(EC = fct_inorder(EC)) %>%
+ group_by(Isolate) %>%
+ mutate(top = case_when(rank < 11 ~ TRUE, TRUE ~ FALSE)) %>%
+ mutate(sumtop = sum(top)) %>%
+ mutate(perctop = sumtop/n()) %>%
+ mutate(sum = sum(mean, na.rm = TRUE)) %>%
+ filter(length(unique(Experiment)) >= 3) %>%
+ ungroup() %>%
+ # filter(sumtop > 0) %>%
+ arrange(-sumtop) %>%
+ mutate(Isolate = fct_inorder(Isolate)) %>%
+ mutate(EC = fct_relevel(EC, names(experiment_order))) %>%
+ mutate(EC = `levels<-`(EC, experiment_order))
> isolate_data_arranged
# A tibble: 106 x 15
EC Experiment Isolate Collection n mean min max sd se
<fct> <chr> <fct> <chr> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Dassel D… Dassel DLB 976B third 10 14.1 10.6 18.5 2.22 0.703
2 Dassel D… Dassel DLB 976B second 10 13.0 9.74 19.0 2.68 0.847
3 Dassel D… Dassel DLB 976B first 10 13.5 10.2 18.4 2.67 0.843
4 IAC-Alvo… IAC-Alvora… 976B third 10 21.3 14.7 26.2 3.55 1.12
5 IAC-Alvo… IAC-Alvora… 976B second 10 15.3 11.0 18.9 2.57 0.813
6 IAC-Alvo… IAC-Alvora… 976B first 10 13.5 8.12 21.0 3.72 1.18
7 G122 Str… G122 Straw… 976B <NA> 12 5.42 4.00 6.00 0.669 0.193
8 IAC-Alvo… IAC-Alvora… 976B <NA> 11 8.55 7.00 9.00 0.820 0.247
9 Dassel D… Dassel DLB 974C second 10 15.9 12.3 23.3 3.55 1.12
10 Dassel D… Dassel DLB 974C first 10 15.5 11.6 21.7 3.22 1.02
# ... with 96 more rows, and 5 more variables: rank <int>, top <lgl>, sumtop
# <int>, perctop <dbl>, sum <dbl>
>
> # Here, I'm creating a summary table that summarizes what the data shows. This
> # will arrange the isolates by the number of times they were found in the top 10
> # of any experiment, give the percentage out of the number of total experiments
> # (including collections), the number of experiments conducted, and those
> # experiments that they were found to be in the top 10.
> isolate_data_arranged %>%
+ group_by(Isolate) %>%
+ summarize(`In the Top 10` = unique(sumtop),
+ `%` = unique(perctop),
+ `N Experiments` = length(unique(Experiment)),
+ Experiments = paste(EC[top], collapse = ", ")) %>%
+ mutate(Experiments = gsub("_", " ", Experiments)) %>%
+ mutate(Experiments = gsub(" NA", "", Experiments)) %>%
+ readr::write_csv("tables/isolates_in_top_ten.csv") %>%
+ print()
# A tibble: 16 x 5
Isolate `In the Top 10` `%` `N Experiments` Experiments
<fct> <int> <dbl> <int> <chr>
1 976B 5 0.625 4 Dassel DLB (35 dae), Dassel D…
2 974C 4 0.571 3 Dassel DLB (28 dae), Dassel D…
3 973D 3 0.375 4 Dassel DLB (35 dae), IAC-Alvo…
4 975C 3 0.375 4 IAC-Alvorada DLB (21 dae), IA…
5 975E 3 0.375 4 IAC-Alvorada DLB (35 dae), G1…
6 977C 3 0.429 3 IAC-Alvorada DLB (21 dae), IA…
7 977B 2 0.250 4 Dassel DLB (35 dae), IAC-Alvo…
8 977A 2 0.286 3 IAC-Alvorada DLB (28 dae), IA…
9 978A 2 0.286 3 IAC-Alvorada DLB (21 dae), IA…
10 975D 2 0.400 3 IAC-Alvorada DLB (35 dae), IA…
11 973C 2 0.400 3 G122 Straw Test, IAC-Alvorada…
12 977E 1 0.143 3 IAC-Alvorada DLB (35 dae)
13 976C 1 0.200 3 IAC-Alvorada DLB (21 dae)
14 974B 0 0 4 ""
15 973B 0 0 3 ""
16 974D 0 0 3 ""
>
> # This barplot summarizes the above table by using transparency to denote the
> # top 10.
> pal <- c(
+ "Dassel DLB (21 dae)" = "#B2E0D2",
+ "Dassel DLB (28 dae)" = "#8CD1BB",
+ "Dassel DLB (35 dae)" = "#66C2A5",
+ "IAC-Alvorada DLB (21 dae)" = "#FDC6B0",
+ "IAC-Alvorada DLB (28 dae)" = "#FCA989",
+ "IAC-Alvorada DLB (35 dae)" = "#FC8D62",
+ "G122 Straw Test" = "#8DA0CB",
+ "IAC-Alvorada Straw Test" = "#E78AC3"
+ )
>
> explot <- ggplot(isolate_data_arranged, aes(x = Isolate, y = mean)) +
+ geom_col(aes(fill = EC, color = top)) +
+ scale_fill_manual(values = pal) +
+ scale_color_manual(values = c("FALSE" = "#FFFFFF69", "TRUE" = "black"), guide = "none") +
+ labs(list(
+ title = "Isolates ranked in at least three experiments",
+ fill = "Experiment (Replicate)",
+ caption = "Bars with borders = ranked in the top 10",
+ y = "cumulative mean"
+ )) +
+ sydney_theme +
+ theme(aspect.ratio = 0.62)
> explot
> ggsave(plot = explot,
+ filename = "figures/isolate-rank.pdf",
+ width = 9,
+ height = 5)
> ggsave(plot = explot,
+ filename = "figures/isolate-rank.png",
+ dpi = 600,
+ width = 9,
+ height = 5)
> ggsave(plot = explot,
+ filename = "figures/isolate-rank.tiff",
+ dpi = 900,
+ width = 9,
+ height = 5)
>
>
> # Comparing isolates between DLB assays -----------------------------------
> #
> # The DLB assays were performed on a Brazilian and non-Brazilian cultivar.
> # The question is: how do isolates shared between the tests compare?
> #
> # Step 1: gather the isolates shared between projects
> isos <- inner_join(select(aproj, Isolate), select(cproj, Isolate)) %>%
+ count(Isolate) %>%
+ pull(Isolate)
Joining, by = "Isolate"
> cat(isos, sep = ", ")
973D, 974B, 974C, 975C, 975E, 976B, 977A, 977B, 977C, 977E, 978A>
> # Step 2: Tabulate the number of experiments each isolate was ranked in the
> # top ten.
> isolate_summary %>%
+ unnest() %>%
+ filter(Isolate %in% isos, grepl("DLB", Experiment)) %>%
+ select(-matches("M")) %>%
+ spread(Isolate, rank, fill = 0) %>%
+ summarize_if(is.numeric, ~sum(. > 0)) %>%
+ gather(Isolate, Count, -Experiment) %>%
+ spread(Experiment, Count) %>%
+ arrange(`Dassel DLB` + `IAC-Alvorada DLB`) %>%
+ readr::write_csv(here("tables/DLB-comparison.csv")) %>%
+ print()
Adding missing grouping variables: `Experiment`
# A tibble: 10 x 3
Isolate `Dassel DLB` `IAC-Alvorada DLB`
<chr> <int> <int>
1 975E 0 1
2 977B 1 0
3 977E 0 1
4 973D 1 1
5 975C 0 2
6 977A 0 2
7 977C 0 2
8 978A 0 2
9 976B 2 1
10 974C 3 1
>
>
> # Cultivar tests ----------------------------------------------------------
> # =========================================================================
> #
> # Here we have three experiments that have to do with assessing if there is a
> # difference in resistance between cultivars.
> #
> # - eproj - Detached Leaf Bioassay on 11 soybean cultivars with two
> # experimental replications at 34 dae and 60 dae
> # - fproj & gproj Detached Leaf Bioassay on 23 Dry Bean cultivars. The first
> # sheet represents testing of two isolates.
> # - hproj - Straw test on 23 Dry Bean cultivars to determine isolates for the
> # experiment.
> # - irpoj - Straw test on 19 Dry Bean cultivars.
> #
>
> # Soybean Variety Detached Leaf Bioassay ---------------------------------
> #
> # We can do a similar thing that we did in the assessments above. We will test
> # for differences between cultivars and use Experimental replicates and the
> # replicate as the random effects
> soy_model <- lmer(Area ~ Name + (1 | Exp_rep) + (1 | Rep), data = eproj) # Hola, model! Soy Zhian.
> anova(soy_model)
Analysis of Variance Table of type III with Satterthwaite
approximation for degrees of freedom
Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
Name 34.876 3.4876 10 199 2.4164 0.009834 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> soy_LSD <- myLSD(eproj$Area, eproj$Name, soy_model, p.adj = "bonferroni")
>
> # Notice, however that there appears to be an effect based on experimental
> # replicate
> ggplot(eproj, aes(x = Name, y = Area, fill = Exp_rep)) +
+ geom_boxplot() +
+ sydney_theme
> # The question then becomes, is it significant if we include it as a fixed
> # effect in our model?
> soy_model2 <- lmer(Area ~ Name + Exp_rep + (1 | Rep), data = eproj)
> anova(soy_model2)
Analysis of Variance Table of type III with Satterthwaite
approximation for degrees of freedom
Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
Name 34.876 3.488 10 199 2.416 0.009834 **
Exp_rep 135.080 135.080 1 199 93.591 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> # Yes, it is significant
> soy_LSD2 <- myLSD(eproj$Area, eproj$Exp_rep, soy_model2, p.adj = "bonferroni")
>
> # What do the different experiments look like if we analyze them separately?
> eproj %>%
+ group_by(Exp_rep) %>%
+ summarize(model = list(lmer(Area ~ Name + (1 | Rep)) %>% anova() %>% broom::tidy())) %>%
+ unnest()
# A tibble: 2 x 8
Exp_rep term sumsq meansq NumDF DenDF statistic p.value
<chr> <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
1 1 Name 24.5 2.45 10 90.0 1.63 0.110
2 2 Name 27.0 2.70 10 90.0 2.25 0.0217
Warning messages:
1: In tidy.anova(.) :
The following column names in ANOVA output were not recognized or transformed: NumDF, DenDF
2: In tidy.anova(.) :
The following column names in ANOVA output were not recognized or transformed: NumDF, DenDF
> # This is interesting. If we analyze these separately, then the results are not
> # significant at p < 0.0001 or even p < 0.01. However, this could be due to
> # overdispersion of the data.
>
> # Dry Bean Cultivar Detached Leaf Bioassay --------------------------------
> #
> # This one is a bit tricky since there are two experimental replicates with