-
Notifications
You must be signed in to change notification settings - Fork 0
/
Field Floral Hemp 2021.R
3090 lines (2599 loc) · 121 KB
/
Field Floral Hemp 2021.R
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 code by Mona Farnisa
######## Field Floral Hemp Data 2021
######## Floral hemp (Cannabis sativa L.) responses to nitrogen fertilization
######## under field conditions in the high desert
#libraries to load
library(tidyverse)
library(broom)
library(lubridate)
library(dplyr)
library(car)
library(lme4)
library(nlme)
library(glmmTMB)
library(ggplot2)
library(ggrepel)
library(dplyr)
library(tidyr)
library(tidyverse)
library(multcompView)
library(emmeans)
library(multcomp)
library(see)
library(performance)
library(plyr)
library(multcompView)
library(emmeans)
library(multcomp)
library(gridExtra)
library(cowplot)
library(merTools)
library(broom)
############## Canopy Cover Field 2021 ###########
read.csv('Canopy Cover.csv')
field.canopy <- read.csv("Canopy Cover.csv", header = T, sep = ",")
#make dates into a date format
field.canopy$date <- as.Date(field.canopy$Date,'%m/%d/%Y')
#create DAT column
field.canopy$dat <- as.factor(difftime(as.POSIXct(field.canopy$date), as.POSIXct('2021-06-14', tz="PT"), units="days"))
#factor variety
field.canopy$variety <- as.factor(field.canopy$Variety)
#factor treatment
field.canopy$treatment <- as.factor(field.canopy$Treatment)
#factor plots
field.canopy$plot <- as.factor(field.canopy$Plot)
#factor rows
field.canopy$row <- as.factor(field.canopy$Row)
# create blocks
field.canopy <- field.canopy %>%
mutate(block = case_when(
row == "1" ~ "1",
row == "2" ~ "1",
row == "3" ~ "2",
row == "4" ~ "2",
row == "5" ~ "3",
row == "6" ~ "3",
row == "7" ~ "4",
row == "8" ~ "4"
))
###cc per plant
field.canopy$ccperplant <- field.canopy$Canopy_m2.per.plant
field.canopy$vartreat <- as.factor(paste(field.canopy$variety, field.canopy$treatment))
###Check to see that all combinations are correct
xtabs(~ variety + date, data = field.canopy)
xtabs(~ treatment + dat, data = field.canopy)
xtabs(~ treatment + variety, data = field.canopy)
xtabs(~ row + variety, data = field.canopy)
xtabs(~ plot + variety, data = field.canopy)
xtabs(~ block + variety, data = field.canopy)
library(plyr)
#per plant
canopycover.stats <- ddply(field.canopy, c("vartreat", "dat", 'treatment', 'variety'),
summarise,
N = length(ccperplant),#We use length instead of count.
mean = mean(ccperplant),
sd = sd(ccperplant),
se = sd / sqrt(N))
canopycover.stats
#write.table(canopycover.stats, file = 'Field CC means.csv', sep = ",", quote = FALSE, row.names = F)
levels(canopycover.stats$variety)[levels(canopycover.stats$variety)=='Tahoe'] <- 'Tahoe Cinco'
# presentation figure canopy cover
ggplot(canopycover.stats, aes(x=dat, y=mean, group = vartreat, color = treatment, linetype = variety)) +
geom_point(size = 4) +
geom_line(size = 1) +
scale_linetype_manual(values=c('solid', "dotted", "dashed"))+
scale_color_manual(values = c("#1B9E77", '#E7298A'))+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, size=1,position=position_dodge(0)) +
theme_classic() +
ylab(bquote('Canopy cover '(m^2~plant^-1))) +
xlab('Days after transplanting') +
labs(color = 'Treatment', linetype = 'Cultivar') + #rename legend title
theme(axis.title.x = element_text(size = 16), axis.text = element_text(size = 16)) +
theme(axis.title.y = element_text(size = 16)) +
theme(axis.title.y = element_text(vjust=0.9)) +
theme(legend.text=element_text(size=16)) +
#theme(legend.title = element_blank()) +
theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 16)) +
scale_y_continuous(expand = c(0,0),limits = c(0, 0.8))+
#geom_text_repel(aes(label=l), size = 7, nudge_x = 0.2)+
theme(legend.position = c(.1, .8)) +
theme(legend.box.background = element_rect(color="black", size=1))
#theme(legend.position = 'none')
###### Model Building ~ canopy cover
c1 <- lmer(ccperplant ~ treatment*variety + (1|block) + (1|dat), data = field.canopy, REML = F)
summary(c1)
# check plots
plot(c1)
par(mfrow=c(1,2))
qqnorm(resid(c1))
qqline(resid(c1))
# residuals
hist(residuals(c1), breaks=10)
c2 <- lmer(ccperplant ~ treatment*variety + (1|plot) + (1|dat), data = field.canopy, REML = F)
summary(c2)
# check plots
plot(c2)
par(mfrow=c(1,2))
qqnorm(resid(c2))
qqline(resid(c2))
# residuals
hist(residuals(c2), breaks=10)
c3 <- lmer(ccperplant ~ treatment*variety + (1|block/plot) + (1|dat), data = field.canopy, REML = F)
summary(c3)
# check plots
plot(c3)
par(mfrow=c(1,2))
qqnorm(resid(c3))
qqline(resid(c3))
# residuals
hist(residuals(c3), breaks=10)
c4 <- lmer(log(ccperplant) ~ treatment*variety + (1|block/plot) + (1|dat), data = field.canopy, REML = F)
summary(c4)
# check plots
plot(c4)
par(mfrow=c(1,2))
qqnorm(resid(c4))
qqline(resid(c4))
# residuals
hist(residuals(c4), breaks=10)
c5 <- lmer(sqrt(ccperplant) ~ treatment*variety + (1|block/plot) + (1|dat), data = field.canopy, REML = F)
summary(c5)
# check plots
plot(c5)
par(mfrow=c(1,2))
qqnorm(resid(c5))
qqline(resid(c5))
# residuals
hist(residuals(c5), breaks=10)
####### calculate slopes
coefficients(c5)
library(merTools)
RMSE.merMod(c1)
RMSE.merMod(c2)
RMSE.merMod(c3)
RMSE.merMod(c4)
RMSE.merMod(c5)
library(see)
library(performance)
### check assumptions
check_model(c5)
Anova(c5)
# estimated marginal means
e1 = emmeans(c5, specs = pairwise ~ treatment|variety, adjust = "none", type = "response") # compare levels of treatment within group
e1
e2 = emmeans(c5, ~ treatment*variety, adjust = "none")
e2
e3 = emmeans(c5, ~ treatment|variety, type = "response", adjust = "none")
e3
# comparisons
# confidence intervals with statistical tests
contrast(e2, method="pairwise",adjust="none", type = "response", infer = T)
pairs(e2, alpha = 0.05, adjust = "none") # contrast stats without CI's
#write.csv(SPAD.contrasts, file = 'SPAD.contrasts.csv', quote = FALSE, row.names = T)
#summary(contrast(e2, method="pairwise",adjust="tukey"), infer=c(TRUE, TRUE)) # same as pairs
pwpp(e2, by = "treatment", adjust = "none")
pairs(e2, adjust = "none")
plot(e2, comparisons = T, adjust = "none", by = "variety") # if red arrows overlap groups are not sig from each other
#cld(e2)
canopycover.lmer.cld <- cld(e2,
alpha = 0.05,
reversed = T, ### reverse the order of letters
Letters = letters, ### Use lower-case letters for .group
#type = "response", ### Report emmeans in orginal scale
adjust = "none", ### no adjustment = LSD for multiple comparisons
method = "paiwise")
canopycover.lmer.cld
# create labels
canopycover.stats <- canopycover.stats %>% mutate(l = case_when(
dat == "108" & vartreat == "Red Bordeaux Control" ~ "c",
dat == "108" & vartreat == "Berry Blossom N+" ~ "a",
dat == "108" & vartreat == "Red Bordeaux N+" ~ "ab",
dat == "108" & vartreat == "Tahoe Control" ~ "d",
dat == "108" & vartreat == "Berry Blossom Control" ~ "c",
dat == "108" & vartreat == "Tahoe N+" ~ "bc"))
######## black & white manuscript figure for canopy cover
cc.line.bw <- ggplot(canopycover.stats, aes(x=dat, y=mean, group = vartreat, shape = vartreat, linetype = vartreat)) +
geom_point(size = 4) +
geom_line(size = 1) +
scale_shape_manual(values=c(15, 0, 17, 2, 18, 9))+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, size=1, position=position_dodge(0)) +
theme_classic() +
ylab(bquote('Canopy cover '(m^2~plant^-1))) +
xlab('Days after transplanting') +
labs(shape = 'Cultivar - Treatment', linetype = 'Cultivar - Treatment') + #rename legend title
theme(axis.title.x = element_text(size = 16), axis.text = element_text(size = 16)) +
theme(axis.title.y = element_text(size = 16)) +
theme(axis.title.y = element_text(vjust=0.9)) +
#ggtitle('Canopy Cover - Field 2021') +
theme(legend.text=element_text(size=16)) +
#theme(legend.title=element_text(size=14)) +
theme(legend.title = element_blank()) +
theme(strip.text = element_text(size = 16)) +
scale_y_continuous(expand = c(0,0),limits = c(0, 0.8))+
geom_text_repel(aes(label=l), size = 7, nudge_x = 0.2) +
#theme(legend.position = c(.2, .8)) +
#theme(legend.box.background = element_rect(color="black", size=1)) +
theme(legend.position = 'none')
cc.line.bw
############# Field Data 2021 Measurements (Plant Height, Stem Diameter) #####
read.csv('Field Data.csv')
measurements <- read.csv('Field Data.csv', header = T, sep = ",")
#make dates into a date format
measurements$date <- as.Date(measurements$Date,'%m/%d/%Y')
#create DAT column
measurements$dat <- as.factor(difftime(as.POSIXct(measurements$date), as.POSIXct('2021-06-14', tz="PT"), units="days"))
#factor variety
measurements$variety <- as.factor(measurements$Variety)
#factor treatment
measurements$treatment <- as.factor(measurements$Treatment)
# factor row
measurements$row <- as.factor(measurements$Row)
measurements$plant.number <- measurements$Plant.Number
# create blocks
measurements <- measurements %>%
mutate(block = case_when(
row == "1" ~ "1",
row == "2" ~ "1",
row == "3" ~ "2",
row == "4" ~ "2",
row == "5" ~ "3",
row == "6" ~ "3",
row == "7" ~ "4",
row == "8" ~ "4"
))
###Check to see that all combinations are correct
xtabs(~ variety + dat, data = measurements)
xtabs(~ treatment + dat, data = measurements)
xtabs(~ Plant.Number + dat, data = measurements)
xtabs(~ treatment + variety, data = measurements)
xtabs(~ block + variety, data = measurements)
measurements1 <- na.omit(measurements)
# remove days 44, 95
measurements1 <- subset(measurements1, dat != 44& dat != 72 & dat != 95 & dat != 109)
#Combined Variety & Treatment
measurements1$vartreat <- as.factor(paste(measurements1$variety, measurements1$treatment))
height.stats <- ddply(measurements1, c("variety", 'treatment',"dat", 'vartreat'),
summarise,
N = length(Height..cm.),#We use length instead of count.
mean = mean(Height..cm.),
sd = sd(Height..cm.),
se = sd / sqrt(N))
height.stats
library(ggplot2)
##Line graphs of mean and s.e.
ggplot(height.stats, aes(x=dat, y=mean, group = vartreat, color = treatment, linetype = variety)) +
geom_point(size = 4) +
geom_line(size = 1) +
scale_linetype_manual(values=c('solid', "dotted", "dashed"))+
scale_color_manual(values = c("#1B9E77", '#E7298A'))+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, size=1,position=position_dodge(0)) +
theme_classic() +
ylab(bquote('Plant height '(cm~plant^-1))) +
xlab('Days after transplanting') +
labs(color = 'Treatment', linetype = 'Cultivar') + #rename legend title
theme(axis.title.x = element_text(size = 16), axis.text = element_text(size = 16)) +
theme(axis.title.y = element_text(size = 16)) +
theme(axis.title.y = element_text(vjust=0.9)) +
theme(legend.text=element_text(size=16)) +
#theme(legend.title = element_blank()) +
theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 16)) +
scale_y_continuous(expand = c(0,0),limits = c(0, 150))+
#geom_text_repel(aes(label=l), size = 7, nudge_x = 0.2)+
theme(legend.position = c(.1, .8)) +
theme(legend.box.background = element_rect(color="black", size=1))+
theme(legend.position = 'none')
###### Model Building ~ Plant Height
h1 <- lmer(Height..cm. ~ treatment*variety + (1|block) + (1|dat), data = measurements1, REML = F)
h3 <- lmer(Height..cm. ~ treatment*variety + (1|block/Plant.Number) + (1|dat), data = measurements1, REML = F)
# model selection
AIC(h1, h2, h3)
h4 <- lmer(log(Height..cm.) ~ treatment*variety + (1|block/Plant.Number) + (1|dat), data = measurements1, REML = F)
h5 <- lmer(sqrt(Height..cm.) ~ treatment*variety + (1|block/Plant.Number) + (1|dat), data = measurements1, REML = F)
h4.1 <- lmer(log(Height..cm.) ~ treatment*variety + (1|block) + (1|dat), data = measurements1, REML = F)
h4.2 <- lmer(log(Height..cm.) ~ treatment*variety + (1|Plant.Number) + (1|dat), data = measurements1, REML = F)
h4.3 <- lmer(log(Height..cm.) ~ treatment+variety + (1|block/Plant.Number) + (1|dat), data = measurements1, REML = F)
library(merTools)
RMSE.merMod(h3)
RMSE.merMod(h4)
RMSE.merMod(h5)
library(see)
library(performance)
### check assumptions
#check_model(h3)
check_model(h4)
#check_model(h5)
Anova(h4)
# estimated marginal means
e1 = emmeans(h4, specs = pairwise ~ treatment|variety, adjust = "none", type = "response") # compare levels of treatment within group
e1
e2 = emmeans(h4, ~ treatment*variety, adjust = "none")
e2
e3 = emmeans(h4, ~ treatment|variety, type = "response", adjust = "none")
e3
# comparisons
# confidence intervals with statistical tests
contrast(e2, method="pairwise",adjust="none", type = "response", infer = T)
SPAD.contrasts <- pairs(e2, alpha = 0.05, adjust = "none") # contrast stats without CI's
#write.csv(SPAD.contrasts, file = 'SPAD.contrasts.csv', quote = FALSE, row.names = T)
#summary(contrast(e2, method="pairwise",adjust="tukey"), infer=c(TRUE, TRUE)) # same as pairs
pwpp(e2, by = "treatment", adjust = "none")
pairs(e2, adjust = "none")
plot(e2, comparisons = T, adjust = "none", by = "variety") # if red arrows overlap groups are not sig from each other
cld(e2,
alpha = 0.05,
reversed = T, ### reverse the order of letters
Letters = letters, ### Use lower-case letters for .group
type = "response", ### Report emmeans in orginal scale
adjust = "none",
method = "pairwise") ### Tukey adjustment for multiple comparisons
# create labels
height.stats <- height.stats %>% mutate(l = case_when(
dat == "102" & vartreat == "Red Bordeaux Control" ~ "c",
dat == "102" & vartreat == "Berry Blossom N+" ~ "a",
dat == "102" & vartreat == "Red Bordeaux N+" ~ "b",
dat == "102" & vartreat == "Tahoe Control" ~ "d",
dat == "102" & vartreat == "Berry Blossom Control" ~ "cd",
dat == "102" & vartreat == "Tahoe N+" ~ "ab"))
########### manuscript plant height figure
line.height.bw <- ggplot(height.stats, aes(x=dat, y=mean, group = vartreat, shape = vartreat, linetype = vartreat)) +
geom_point(size = 4) +
geom_line(size = 1) +
scale_shape_manual(labels = c('BBc', 'BBn', 'RBc', 'RBn', 'TCc', 'TCn'), values=c(15, 0, 17, 2, 18, 9))+
scale_linetype_discrete(labels = c('BBc', 'BBn', 'RBc', 'RBn', 'TCc', 'TCn')) +
#geom_pointrange(aes(ymin=mean-sd, ymax=mean+sd)) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, size=1,position=position_dodge(0)) +
theme_classic() +
scale_fill_grey()+
ylab(bquote('Plant height '(cm~plant^-1))) +
xlab('Days after transplanting') +
#labs(shape = 'Cultivar - Treatment', linetype = 'Cultivar - Treatment') + #rename legend title
theme(axis.title.x = element_text(size = 16), axis.text = element_text(size = 16)) +
theme(axis.title.y = element_text(size = 16)) +
theme(axis.title.y = element_text(vjust=0.9)) +
#ggtitle('Plant Height linear model - Field 2021') +
theme(legend.text=element_text(size=16)) +
theme(legend.title = element_blank()) +
#theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 16)) +
scale_y_continuous(expand = c(0,0),limits = c(0, 150))+
geom_text_repel(aes(label=l), size = 7, nudge_x = 0.2)+
theme(legend.position = c(.1, .8)) +
theme(legend.box.background = element_rect(color="black", size=1))
#theme(legend.position = 'none')
line.height.bw
###### merge canopy cover and plant height manuscript figures #######
cc.height.bw2 <- plot_grid(cc.line.bw, line.height.bw, labels = "AUTO", label_size = 18)
#ggsave(cc.height.bw2, file="cc.height.bw.TIFF",width=13, height=6,dpi=600,path="C:/Users/mfarnisa/OneDrive - University of Nevada, Reno/Thesis/Figures")
######### Model Building - Stem Diameter Stats
diameter.stats <- ddply(measurements1, c("variety", "treatment", "dat", "vartreat"),
summarise,
N = length(Stem.Diameter..mm.),#We use length instead of count.
mean = mean(Stem.Diameter..mm.),
sd = sd(Stem.Diameter..mm.),
se = sd / sqrt(N))
diameter.stats
#write.table(diameter.stats, file = 'Stem Diameter Means field 2021.csv', sep = ",", quote = FALSE, row.names = F)
ggplot(diameter.stats, aes(x=dat, y=mean, group = vartreat, shape = vartreat, linetype = vartreat)) +
geom_point(size = 4) +
geom_line(size = 1) +
scale_shape_manual(labels = c('BBc', 'BBn', 'RBc', 'RBn', 'Tc', 'Tn'), values=c(15, 0, 17, 2, 18, 9))+
scale_linetype_discrete(labels = c('BBc', 'BBn', 'RBc', 'RBn', 'Tc', 'Tn')) +
#geom_pointrange(aes(ymin=mean-sd, ymax=mean+sd)) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, size=1,position=position_dodge(0)) +
theme_classic() +
scale_fill_grey()+
ylab(bquote('Diameter '(mm~plant^-1))) +
xlab('Days after transplanting') +
#labs(shape = 'Cultivar - Treatment', linetype = 'Cultivar - Treatment') + #rename legend title
theme(axis.title.x = element_text(size = 16), axis.text = element_text(size = 16)) +
theme(axis.title.y = element_text(size = 16)) +
theme(axis.title.y = element_text(vjust=0.9)) +
#ggtitle('Plant Height linear model - Field 2021') +
theme(legend.text=element_text(size=16)) +
theme(legend.title = element_blank()) +
#theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 16)) +
#scale_y_continuous(expand = c(0,0),limits = c(0, 150))+
#geom_text_repel(aes(label=l), size = 7, nudge_x = 0.2)+
theme(legend.position = c(.1, .8)) +
theme(legend.box.background = element_rect(color="black", size=1))
#theme(legend.position = 'none')
library(lme4)
library(rcompanion)
d.transfrom = transformTukey(measurements1$Stem.Diameter..mm., plotit=T)
d.sqr = (measurements1$Stem.Diameter..mm.)^(0.4) # Avoid complex numbers
d1 <- lmer(Stem.Diameter..mm. ~ treatment*variety + (1|block) + (1|dat), data = measurements1, REML = F)
#d3 <- lmer(Stem.Diameter..mm. ~ treatment*variety + (1|block/Plant.Number) + (1|dat), data = measurements1, REML = F)
d4 <- lmer(log(Stem.Diameter..mm.) ~ treatment*variety + (1|block) + (1|dat), data = measurements1, REML = F)
d5 <- lmer(d.sqr ~ treatment*variety + (1|block) + (1|dat), data = measurements1, REML = F)
library(merTools)
RMSE.merMod(d1)
RMSE.merMod(d4)
RMSE.merMod(d5)
library(see)
library(performance)
### diagnostic plots
#check_model(d1)
check_model(d4)
check_model(d5)
#Anova(d1)
Anova(d4)
Anova(d5)
# estimated marginal means
e1 = emmeans(d4, specs = pairwise ~ treatment|variety, adjust = "none", type = "response") # compare levels of treatment within group
e1
e2 = emmeans(d4, ~ treatment*variety, type = "response", adjust = "none")
e2
e3 = emmeans(d5, ~ treatment*variety, type = "response", adjust = "none")
e3
# comparisons
# confidence intervals with statistical tests
contrast(e2, method="pairwise",adjust="none", type = "response", infer = T)
SPAD.contrasts <- pairs(e2, alpha = 0.05, adjust = "none") # contrast stats without CI's
#write.csv(SPAD.contrasts, file = 'SPAD.contrasts.csv', quote = FALSE, row.names = T)
#summary(contrast(e2, method="pairwise",adjust="tukey"), infer=c(TRUE, TRUE)) # same as pairs
pwpp(e2, by = "treatment", adjust = "none")
pairs(e2, adjust = "none")
plot(e2, comparisons = T, adjust = "none", by = "variety") # if red arrows overlap groups are not sig from each other
cld(e2,
alpha = 0.05,
reversed = T, ### reverse the order of letters
Letters = letters, ### Use lower-case letters for .group
#type = "response", ### Report emmeans in orginal scale
adjust = "none",
method = "pairwise") ### no adjustment = LSD for multiple comparisons
cld(e3,
alpha = 0.05,
reversed = T, ### reverse the order of letters
Letters = letters, ### Use lower-case letters for .group
type = "response", ### Report emmeans in orginal scale
adjust = "none",
method = "pairwise") ### no adjustment = LSD for multiple comparisons
############# Dried Shoot Biomass ##############
read.csv('Biomass Weights.csv')
biomass <- read.csv('Biomass Weights.csv', header = T, sep = ",")
#make dates into a date format
biomass$date <- as.Date(biomass$Date,'%m/%d/%Y')
#create DAT column
biomass$dat <- as.factor(difftime(as.POSIXct(biomass$date), as.POSIXct('2021-06-14', tz="PT"), units="days"))
#factor variety
biomass$variety <- as.factor(biomass$Variety)
#factor treatment
biomass$treatment <- as.factor(biomass$Treatment)
# factor row
biomass$row <- as.factor(biomass$Row)
# create blocks
biomass <- biomass %>%
mutate(block = case_when(
row == "1" ~ "1",
row == "2" ~ "1",
row == "3" ~ "2",
row == "4" ~ "2",
row == "5" ~ "3",
row == "6" ~ "3",
row == "7" ~ "4",
row == "8" ~ "4"
))
biomass$vartreat <- as.factor(paste(biomass$variety, biomass$treatment))
###Check to see that all combinations are correct
xtabs(~ variety + date, data = biomass)
xtabs(~ treatment + dat, data = biomass)
xtabs(~ treatment + variety, data = biomass)
xtabs(~ block + variety, data = biomass)
#calculate summary statistics of variables
leafshoot.stats <- ddply(biomass, c("variety", "treatment"),
summarise,
N = length(Leaf.Shoot.Total.Dried_g),#We use length instead of count.
mean = mean(Leaf.Shoot.Total.Dried_g),
sd = sd(Leaf.Shoot.Total.Dried_g),
se = sd / sqrt(N))
leafshoot.stats
#write.table(leafshoot.stats, file = 'Field Shoot Biomass Means.csv', sep = ",", quote = FALSE, row.names = F)
levels(leafshoot.stats$variety)[levels(leafshoot.stats$variety)=='Tahoe '] <- 'Tahoe Cinco'
boxplot(Leaf.Shoot.Total.Dried_g ~ vartreat, data = biomass, col = "lightgray")
library(ggplot2)
#Bar plot of mean and s.e.
biomass.treatment.bar <- ggplot(leafshoot.stats, aes(x = treatment, y=mean))+
facet_wrap(~ variety) +
#facet_grid(vars(Leaf.Position), vars(variety), scales = "free", space = 'free') +
geom_bar(stat = 'identity', position="dodge")+
#geom_jitter(position = position_jitterdodge(jitter.width = 0.2, dodge.width = 0.8)) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, position=position_dodge(0.9))+
theme_classic() +
ylab("Shoot Weight (g)") +
xlab("Treatment") +
ggtitle('Dried Biomass - Field 2021') +
theme(axis.title.x = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(axis.title.y = element_text(size = 14), axis.text.y = element_text(size = 14)) +
theme(legend.text=element_text(size=12)) +
theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 14)) +
scale_y_continuous(expand = c(0,0), limits = c(0,1500)) +
#scale_y_continuous(expand = c(0,0)) +
scale_x_discrete(expand = expansion(add=c(0.2,0.2)))
#geom_text(aes(label=letters.biomass, y = mean + se), vjust = -.5, size = 6)
biomass.treatment.bar
###### Model Building ~ biomass #######
b1 <- lmer(Leaf.Shoot.Total.Dried_g ~ treatment*variety + (1|block), data = biomass, REML = F)
# b2 <- lmer(log(Leaf.Shoot.Total.Dried_g) ~ treatment*variety + (1|block), data = biomass, REML = F)
# b3 <- lmer(sqrt(Leaf.Shoot.Total.Dried_g) ~ treatment*variety + (1|block), data = biomass, REML = F)
b4 <- lmer(Leaf.Shoot.Total.Dried_g ~ treatment+variety + (1|block), data = biomass, REML = F)
# b5 <- lmer(log(Leaf.Shoot.Total.Dried_g) ~ treatment+variety + (1|block), data = biomass, REML = F)
# b6 <- lmer(sqrt(Leaf.Shoot.Total.Dried_g) ~ treatment+variety + (1|block), data = biomass, REML = F)
b7 <- lmer(leaf.sqr ~ treatment*variety + (1|block), data = biomass, REML = F)
interaction.plot(x.factor = biomass$treatment,
trace.factor = biomass$variety,
response = biomass$Leaf.Shoot.Total.Dried_g,
fun = mean,
type="b",
col=c("black","red","green"), ### Colors for levels of trace var.
pch=c(19, 17, 15), ### Symbols for levels of trace var.
fixed=TRUE, ### Order by factor order in data
leg.bty = "o")
library(rcompanion)
T_tuk = transformTukey(biomass$Leaf.Shoot.Total.Dried_g, plotit=T)
leaf.sqr = (biomass$Leaf.Shoot.Total.Dried_g)^(0.35) # Avoid complex numbers
### check assumptions
check_model(b1)
#check_model(b4)
check_model(b7)
AIC(b1, b4)
Anova(b1)
#Anova(b4)
Anova(b7)
# estimated marginal means
e2 = emmeans(b1, ~ treatment*variety, type = "response", adjust = "none")
e2
e3 = emmeans(b7, ~ treatment*variety, type = "response", adjust = "none")
e3
cld(e2,
alpha = 0.05,
reversed = T, ### reverse the order of letters
Letters = letters, ### Use lower-case letters for .group
#type = "response", ### Report emmeans in orginal scale
adjust = "none",
method = "pairwise") ### no adjustment = LSD for multiple comparisons
cld(e3,
alpha = 0.05,
reversed = T, ### reverse the order of letters
Letters = letters, ### Use lower-case letters for .group
#type = "response", ### Report emmeans in orginal scale
adjust = "none",
method = "pairwise") ### no adjustment = LSD for multiple comparisons
# comparisons
# confidence intervals with statistical tests
contrast(e3, method="pairwise",adjust="none", type = "response", infer = T)
pairs(e2, alpha = 0.05, adjust = "none") # contrast stats without CI's
#write.csv(SPAD.contrasts, file = 'SPAD.contrasts.csv', quote = FALSE, row.names = T)
#summary(contrast(e2, method="pairwise",adjust="tukey"), infer=c(TRUE, TRUE)) # same as pairs
pwpp(e2, adjust = "none")
pairs(e2, adjust = "none")
plot(e2, comparisons = T, adjust = "none", by = "variety") # if red arrows overlap groups are not sig from each other
letters.biomass = c("c", "a", "c", "b", "d", "bc")
ggplot(leafshoot.stats, aes(x=treatment, y=mean, fill = treatment)) +
facet_wrap(~ variety) +
geom_bar(stat = 'identity', position="dodge")+
scale_fill_manual(values = c("#1B9E77", '#E7298A'))+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, size=1,position=position_dodge(0)) +
theme_classic() +
ylab(bquote('Dried shoot biomass '(g~plant^-1))) +
xlab('Treatment') +
labs(color = 'Treatment', linetype = 'Cultivar') + #rename legend title
theme(axis.title.x = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(axis.title.y = element_text(size = 14), axis.text.y = element_text(size = 14)) +
theme(legend.text=element_text(size=12)) +
theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 14)) +
theme(axis.title.y = element_text(vjust=0.9)) +
scale_y_continuous(expand = c(0,0),limits = c(0, 1600))+
scale_x_discrete(expand = expansion(add=c(0.2,0.2)))+
geom_text(aes(label=letters.biomass, y = mean + se), vjust = -.5, size = 6)+
theme(legend.position = 'none')
############# Dried Inflorescence Biomass ################
#calculate summary statistics of variables
flower.stats <- ddply(biomass, c("variety", "treatment"),
summarise,
N = length(Flower.Total.Dried_g),#We use length instead of count.
mean = mean(Flower.Total.Dried_g),
sd = sd(Flower.Total.Dried_g),
se = sd / sqrt(N))
flower.stats
#write.table(flower.stats, file = 'Field Flower Biomass Means.csv', sep = ",", quote = FALSE, row.names = F)
levels(flower.stats$variety)[levels(flower.stats$variety)=='Tahoe '] <- 'Tahoe Cinco'
flower.treatment.bar <- ggplot(flower.stats, aes(x = treatment, y=mean))+
facet_wrap(~ variety) +
#facet_grid(vars(Leaf.Position), vars(variety), scales = "free", space = 'free') +
geom_bar(stat = 'identity', position="dodge")+
#geom_jitter(position = position_jitterdodge(jitter.width = 0.2, dodge.width = 0.8)) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, position=position_dodge(0.9))+
theme_classic() +
ylab("Flower Weight (g)") +
xlab("Treatment") +
ggtitle('Dried Biomass - Field 2021') +
theme(axis.title.x = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(axis.title.y = element_text(size = 14), axis.text.y = element_text(size = 14)) +
theme(legend.text=element_text(size=12)) +
theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 14)) +
scale_y_continuous(expand = c(0,0), limits = c(0,900)) +
#scale_y_continuous(expand = c(0,0)) +
scale_x_discrete(expand = expansion(add=c(0.2,0.2)))
#geom_text(aes(label=letters.flower, y = mean + se), vjust = -.5, size = 6)
flower.treatment.bar
interaction.plot(x.factor = biomass$treatment,
trace.factor = biomass$variety,
response = biomass$Flower.Total.Dried_g,
fun = mean,
type="b",
col=c("black","red","green"), ### Colors for levels of trace var.
pch=c(19, 17, 15), ### Symbols for levels of trace var.
fixed=TRUE, ### Order by factor order in data
leg.bty = "o")
f1 <- lmer(Flower.Total.Dried_g ~ treatment*variety + (1|block), data = biomass, REML = F)
f4 <- lmer(flower.sqr ~ treatment*variety + (1|block), data = biomass, REML = F)
#f2 <- lmer(log(Flower.Total.Dried_g) ~ treatment*variety + (1|block), data = biomass, REML = F)
#f3 <- lmer(sqrt(Flower.Total.Dried_g) ~ treatment*variety + (1|block), data = biomass, REML = F)
library(rcompanion)
T_tuk = transformTukey(biomass$Flower.Total.Dried_g, plotit=T)
flower.sqr = (biomass$Flower.Total.Dried_g)^(0.25) # Avoid complex numbers
### check assumptions
check_model(f1)
#check_model(f2)
#check_model(f3)
check_model(f4)
Anova(f1)
#Anova(f2)
#Anova(f3)
Anova(f4)
# estimated marginal means
ff = emmeans(f1, ~ treatment*variety, type = "response", adjust = "none")
ff
ff3 = emmeans(f4, ~ treatment*variety, type = "response", adjust = "none")
ff3
# comparisons
# confidence intervals with statistical tests
contrast(ff, method="pairwise",adjust="none", type = "response", infer = T)
pairs(e2, alpha = 0.05, adjust = "none") # contrast stats without CI's
#write.csv(SPAD.contrasts, file = 'SPAD.contrasts.csv', quote = FALSE, row.names = T)
#summary(contrast(e2, method="pairwise",adjust="tukey"), infer=c(TRUE, TRUE)) # same as pairs
pwpp(e2, adjust = "none")
pairs(e2, adjust = "none")
plot(e2, comparisons = T, adjust = "none", by = "variety") # if red arrows overlap groups are not sig from each other
cld(ff,
alpha = 0.05,
reversed = T, ### reverse the order of letters
Letters = letters, ### Use lower-case letters for .group
#type = "response", ### Report emmeans in orginal scale
adjust = "none",
method = "pairwise") ### no adjustment = LSD for multiple comparisons
cld(ff3,
alpha = 0.05,
reversed = T, ### reverse the order of letters
Letters = letters, ### Use lower-case letters for .group
#type = "response", ### Report emmeans in orginal scale
adjust = "none",
method = "pairwise") ### no adjustment = LSD for multiple comparisons
#write.csv(SPAD.lmer.cld, file = 'SPAD.cld.csv', quote = FALSE, row.names = T)
letters.flower = c("cd", "ab", "cd", "bc", "d", "a")
ggplot(flower.stats, aes(x=treatment, y=mean, fill = treatment)) +
facet_wrap(~ variety) +
geom_bar(stat = 'identity', position="dodge")+
scale_fill_manual(values = c("#1B9E77", '#E7298A'))+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, size=1,position=position_dodge(0)) +
theme_classic() +
ylab(bquote('Dried inflorescence biomass '(g~plant^-1))) +
xlab('Treatment') +
labs(color = 'Treatment', linetype = 'Cultivar') + #rename legend title
theme(axis.title.x = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(axis.title.y = element_text(size = 14), axis.text.y = element_text(size = 14)) +
theme(legend.text=element_text(size=12)) +
theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 14)) +
theme(axis.title.y = element_text(vjust=0.9)) +
scale_y_continuous(expand = c(0,0),limits = c(0, 1000))+
scale_x_discrete(expand = expansion(add=c(0.2,0.2)))+
geom_text(aes(label=letters.flower, y = mean + se), vjust = -.5, size = 6)+
theme(legend.position = 'none')
########### Dried Inflorescence-to-Shoot Biomass Ratio ###########
library(MASS)
biomass$ratio = biomass$Flower.Total.Dried_g/biomass$Leaf.Shoot.Total.Dried_g
#calculate summary statistics of variables
ratio.stats <- ddply(biomass, c("variety", "treatment"),
summarise,
N = length(ratio),#We use length instead of count.
mean = mean(ratio),
sd = sd(ratio),
se = sd / sqrt(N))
ratio.stats
#write.table(ratio.stats, file = 'Biomass Ratio Means.csv', sep = ",", quote = FALSE, row.names = F)
ggplot(ratio.stats, aes(x=treatment, y=mean, fill = treatment)) +
facet_wrap(~ variety) +
geom_point(stat = 'identity', position="dodge")+
scale_fill_manual(values = c("#1B9E77", '#E7298A'))+
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, size=1,position=position_dodge(0)) +
theme_classic() +
ylab(bquote('Dried inflorescence biomass '(g~plant^-1))) +
xlab('Treatment') +
labs(color = 'Treatment', linetype = 'Cultivar') + #rename legend title
theme(axis.title.x = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(axis.title.y = element_text(size = 14), axis.text.y = element_text(size = 14)) +
theme(legend.text=element_text(size=12)) +
theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 14)) +
theme(axis.title.y = element_text(vjust=0.9)) +
scale_y_continuous(expand = c(0,0),limits = c(0, 2))+
scale_x_discrete(expand = expansion(add=c(0.2,0.2)))+
#geom_text(aes(label=letters.biomass, y = mean + se), vjust = -.5, size = 6)+
theme(legend.position = 'none')
r1 <- lmer(ratio ~ treatment*variety + (1|row), data = biomass, REML = F)
r2 <- lmer(log(ratio) ~ treatment*variety + (1|row), data = biomass, REML = F)
r3 <- lmer(sqrt(ratio) ~ treatment*variety + (1|block), data = biomass, REML = F)
### check assumptions
check_model(r2)
#find optimal lambda for Box-Cox transformation
#bc <- boxcox(ratio ~ treatment*variety, data = biomass)
#(lambda <- bc$x[which.max(bc$y)])
#fit new linear regression model using the Box-Cox transformation
#new_model <- lm(((ratio^lambda-1)/lambda) ~ treatment*variety, data = biomass)
#Q-Q plot for Box-Cox transformed model
qqnorm(new_model$residuals)
qqline(new_model$residuals)
AIC(r2, new_model)
AIC(r2) + 2*sum(log(biomass$ratio))
# r2 8 21.80522 4.2
# new_model 7 20.84490
Anova(r2)
#Anova(new_model)
br2 = emmeans(r2, ~ treatment*variety, type = "response", adjust = "none")
br2
#br = emmeans(new_model, ~ treatment*variety, type = "response", adjust = "none")
#br
cld(br2,
alpha = 0.05,
reversed = T, ### reverse the order of letters
Letters = letters, ### Use lower-case letters for .group
#type = "response", ### Report emmeans in orginal scale
adjust = "none",
method = "pairwise") ### no adjustment = LSD for multiple comparisons
########### SLA (specific leaf area) #############
read.csv('SLA.csv')
sla <- read.csv('SLA.csv', header = T, sep = ",")
#make dates into a date format
sla$date <- as.Date(sla$Date,'%m/%d/%Y')
#create DAT column
sla$dat <- as.factor(difftime(as.POSIXct(sla$date), as.POSIXct('2021-06-14', tz="PT"), units="days"))
## remove dat 66 due to sample mislabeling!
sla <- subset(sla, dat != 66)
#factor variety
sla$variety <- as.factor(sla$Variety)
#factor treatment
sla$treatment <- as.factor(sla$Treatment)
# create blocks for pot.number
# create blocks
sla <- sla %>%
mutate(block = case_when(
Row == "1" ~ "1",
Row == "2" ~ "1",
Row == "3" ~ "2",
Row == "4" ~ "2",
Row == "5" ~ "3",
Row == "6" ~ "3",
Row == "7" ~ "4",
Row == "8" ~ "4"))
###Check to see that all combinations are correct
xtabs(~ block + Plant.Number, data = sla)
xtabs(~ treatment + dat, data = sla)
xtabs(~ Plant.Number + dat, data = sla)
xtabs(~ treatment + variety, data = sla)
#Combined Variety & Treatment
sla$vartreat <- as.factor(paste(sla$variety, sla$treatment))
plot(sla$SLA.cm.2.g ~ sla$vartreat)
library(ggplot2)
sla.stats.dat <- ddply(sla, c("variety", "treatment", 'dat'),
summarise,
N = length(SLA.cm.2.g),#We use length instead of count.
mean = mean(SLA.cm.2.g),
sd = sd(SLA.cm.2.g),
se = sd / sqrt(N))
sla.stats.dat
line.sla.stats <- ggplot(sla.stats.dat, aes(x=dat, y=mean, group = treatment, color = treatment)) +
facet_wrap(~ variety) +
geom_point(size = 4) +
geom_line(size = 1) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, size=1,
position=position_dodge(0)) +
theme_classic() +
ylab('SLA (cm^2/g)') +
xlab('Days After Transplanting') +
labs(color = 'Treatment', shape = 'Treatment') + #rename legend title
theme(axis.title.x = element_text(size = 14), axis.text = element_text(size = 14)) +
theme(axis.title.y = element_text(size = 14)) +
#xlim('11', '18', '25', '32', '39') +
ggtitle('SLA Field - 2021') +
theme(legend.text=element_text(size=12)) +
theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 14))
line.sla.stats
library(plyr)
sla.stats <- ddply(sla, c("variety", "treatment"),
summarise,
N = length(SLA.cm.2.g),#We use length instead of count.
mean = mean(SLA.cm.2.g),
sd = sd(SLA.cm.2.g),
se = sd / sqrt(N))
sla.stats
#Bar plot of mean and s.e.
sla.treatment.bar <- ggplot(sla.stats, aes(x = treatment, y=mean))+
facet_wrap(~ variety) +
#facet_grid(vars(Leaf.Position), vars(variety), scales = "free", space = 'free') +
geom_bar(stat = 'identity', position="dodge")+
#geom_jitter(position = position_jitterdodge(jitter.width = 0.2, dodge.width = 0.8)) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.5, position=position_dodge(0.9))+
theme_classic() +
ylab("SLA (cm^2/g)") +
xlab("Treatment") +
ggtitle('SLA - Field 2021') +
theme(axis.title.x = element_text(size = 14), axis.text.x = element_text(size = 14)) +
theme(axis.title.y = element_text(size = 14), axis.text.y = element_text(size = 14)) +
theme(legend.text=element_text(size=12)) +
theme(legend.title=element_text(size=14)) +
theme(strip.text = element_text(size = 14)) +
scale_y_continuous(expand = c(0,0), limits = c(0,70)) +
#scale_y_continuous(expand = c(0,0)) +
scale_x_discrete(expand = expansion(add=c(0.2,0.2)))
#geom_text(aes(label=letters.chl, y = mean + se), vjust = -.5, size = 6)
sla.treatment.bar