-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.R
150 lines (126 loc) · 3.85 KB
/
analysis.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
library(tidyverse)
library(lme4)
library(car)
library(gghalves)
library(effects)
library(emmeans)
rm(list=ls())
rice <- read_csv("rice.csv")
rice$AMF <- factor(rice$AMF)
rice$NIT <- factor(rice$NIT, levels=c(0,1), labels=c("low","high"))
rice$PHOS <- factor(rice$PHOS, levels=c(0,1), labels=c("low","high"))
rice$POT <- factor(rice$POT)
m1 <- lm(MASS ~ AMF * NIT * PHOS, data=rice)
# summary(m1)
Anova(m1)
par(mfrow=c(2,2))
plot(m1)
par(mfrow=c(1,1))
m2 <- lm(MASS ~ AMF + NIT + PHOS + AMF:NIT + AMF:PHOS + NIT:PHOS, data=rice)
anova(m1, m2) # no sig diff
par(mfrow=c(2,2))
plot(m2)
par(mfrow=c(1,1))
m3 <- lm(MASS ~ AMF + NIT + PHOS + AMF:NIT + NIT:PHOS, data=rice)
anova(m2, m3) # no sig diff
par(mfrow=c(2,2))
plot(m3)
par(mfrow=c(1,1))
summary(m3)
Anova(m3)
# raw data
ggplot(data=rice, mapping=aes(y=MASS, x=AMF, col=AMF)) +
geom_boxplot(width=0.3, position=position_nudge(0.25)) +
geom_half_point(side='l', alpha=0.5,) +
facet_grid(NIT ~ PHOS, labeller=label_both) +
theme_bw() +
labs(x="AMF Treatment", y="Average MASS of seed yield / kg")
# plot model
# pred <- rice[,c("AMF", "NIT", "PHOS")]
# predOut <- predict(m3, newdata=pred, interval="confidence")
# pred <- cbind(pred, predOut)
# wrong! only use this for continous data
m3Pred <- emmeans(m3, ~ AMF + NIT + PHOS + AMF:NIT)
m3Pred <- as_tibble(m3Pred)
# m3Pred %>%
# unite("COMBI", c(NIT, PHOS))
plot(allEffects(m3), multiline=TRUE, ci.style="bars")
m3Pred$COMBI <- with(m3Pred, paste("NIT: ", NIT, ", PHOS: ", PHOS, sep=""))
m3Pred$COMBI2 <- with(m3Pred, paste("NIT: ", NIT, ", \nPHOS: ", PHOS, sep=""))
# m3Pred$COMBI <- with(m3Pred, paste(AMF, " ", NIT, "NIT, ", PHOS, "PHOS", sep=""))
rice$COMBI <- with(rice, paste("NIT: ", NIT, ", PHOS: ", PHOS, sep=""))
rice$COMBI2 <- with(rice, paste("NIT: ", NIT, ", \nPHOS: ", PHOS, sep=""))
ggplot(data=m3Pred) +
geom_point(
mapping=aes(y=emmean, x=AMF, col=COMBI),
position=position_dodge(width=0.6),
alpha=0.6
) +
geom_errorbar(
mapping=aes(ymin=lower.CL, ymax=upper.CL, x=AMF, col=COMBI),
position=position_dodge(width=0.6),
width=0.3, alpha=0.6
) +
geom_point(data=rice,
mapping=aes(y=MASS, x=AMF, col=COMBI),
position=position_jitterdodge(dodge.width=0.6, jitter.width=0.2),
size=0.5, alpha=0.3) +
theme_bw() +
labs(
x = "AMF Treatment",
y = "Average MASS of seed yield / kg"
) +
scale_color_discrete(name="Nutrient Combination") +
theme(
legend.text=element_text(size=7)
)
# ggplot(data=m3Pred) +
# geom_point(
# mapping=aes(y=emmean, x=AMF, col=COMBI),
# position=position_dodge(width=0.5),
# alpha=0.6
# ) +
# geom_errorbar(
# mapping=aes(ymin=lower.CL, ymax=upper.CL, x=AMF, col=COMBI),
# position=position_dodge(width=0.5),
# width=0.3, alpha=0.6
# ) +
# geom_jitter(data=rice,
# mapping=aes(y=MASS, x=AMF, col=COMBI),
# size=0.5, alpha=0.3) +
# facet_grid(NIT ~ PHOS) +
# theme_bw() +
# labs(
# x = "AMF Treatment",
# y = "Average MASS of seed yield / kg"
# ) +
# scale_color_discrete(name="Nutrient Combination") +
# theme(
# legend.text=element_text(size=7)
# )
ggplot(data=m3Pred) +
geom_point(
mapping=aes(y=emmean, x=COMBI2, col=AMF),
position=position_dodge(width=0.5),
alpha=0.6
) +
geom_errorbar(
mapping=aes(ymin=lower.CL, ymax=upper.CL, x=COMBI2, col=AMF),
position=position_dodge(width=0.5),
width=0.3, alpha=0.6
) +
geom_point(data=rice,
mapping=aes(y=MASS, x=COMBI2, col=AMF),
position=position_jitterdodge(jitter.width=0.2, dodge.width=0.5),
size=0.5, alpha=0.3) +
theme_bw() +
labs(
x = "Combination of NIT & PHOS treatment",
y = "Average MASS of seed yield / kg"
) +
scale_color_discrete(name="AMF Treatment") +
theme(
legend.title=element_text(size=9),
legend.text=element_text(size=7),
axis.text.x=element_text(angle=90)
)