-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_analysis_phyllochron.R
184 lines (159 loc) · 7.28 KB
/
stats_analysis_phyllochron.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
#stats analysis phyllochron 1-2
#stats analysis phyllochron 1-3
#by Dana Looschelders
library(agricolae)
library(PMCMRplus)
library(PMCMR)
library(tidyverse)
library(MASS)
setwd("C:/00 Dana/Uni/Internship/Work")
dat=read.table("Phyllochron.csv", sep=";", dec=" ", header=T)
names(dat)=c("ID", "Variety", "Treatment", "Chamber", "Phyllo12", "Phyllo13", "Phyllo14", "Phyllo23", "Phyllo24", "Phyllo34", "Phyllo1S", "Type")
str(dat)
phyllo=cbind.data.frame("Variety"=dat$Variety,
"Treatment"=dat$Treatment,
"Phyllochron"=dat$Phyllo12,
"type"=dat$Type)
str(phyllo)
#write Master Table with signficance results (only kruskal, not posthoc)
master_stats=data.frame(names(dat[,5:11]), "sig_treatment"=NA, "sig_Variety"=NA, "sig_type"=NA)
master_stats=master_stats[-7,]
#data exploration
boxplot(phyllo$Phyllochron~phyllo$type,
main="Phyllochron 1-2 among types",
xlab="Treatment", ylab="Phyllochron [d]")
boxplot(phyllo$Phyllochron~phyllo$Treatment,
main="Phyllochron 1-2 among Treatments",
xlab="Treatment", ylab="Phyllochron [d]")
boxplot(phyllo$Phyllochron~phyllo$Variety)
#test for normality
qqnorm(phyllo$Phyllochron)
qqline(phyllo$Phyllochron)
shapiro.test(phyllo$Phyllochron) #p-value is 8.838*10^-7
#data is not normally distributed
#use kruskal test
kruskal.test(phyllo$Phyllochron~phyllo$type) #p-value = 0.02205
master_stats$sig_type[master_stats$names.dat...5.11..=="Phyllo12"]=0.02205
kruskal.test(phyllo$Phyllochron~phyllo$Variety) #p-value = 2.181e-06
master_stats$sig_Variety[master_stats$names.dat...5.11..=="Phyllo12"]=2.18e-06
kruskal.test(phyllo$Phyllochron~phyllo$Treatment) #p-value = 0.03885
master_stats$sig_treatment[master_stats$names.dat...5.11..=="Phyllo12"]=0.0389
#posthoc test
posthoc.kruskal.nemenyi.test(phyllo$Phyllochron~phyllo$type, dist="Chisquare")
posthoc.kruskal.nemenyi.test(phyllo$Phyllochron~phyllo$Treatment, dist="Chisquare") #no significance
posthoc.kruskal.nemenyi.test(phyllo$Phyllochron~phyllo$Variety, dist="Chisquare")
#glm
phyllo_glm=glm(phyllo$Phyllochron~phyllo$type+phyllo$Treatment+phyllo$Variety)
summary(phyllo_glm)
plot(phyllo_glm)
#glm
glm(phyllo$Phyllochron~phyllo$type)
#*******************************************************************************************************
#phyllochron 1-3
phyllo13=cbind.data.frame("Variety"=dat$Variety,
"Treatment"=dat$Treatment,
"Phyllochron"=dat$Phyllochron.1.3,
"type"=dat$type)
str(phyllo13)
#data exploration
hist(phyllo13$Phyllochron)
boxplot(phyllo13$Phyllochron~phyllo13$Treatment)
boxplot(phyllo13$Phyllochron~phyllo13$Variety)
boxplot(phyllo13$Phyllochron~phyllo13$type)
#test assumptions
qqnorm(phyllo13$Phyllochron)
qqline(phyllo13$Phyllochron)
shapiro.test(phyllo13$Phyllochron) #not normally distributed p-value: 0.00013
#kruskal test
kruskal.test(phyllo13$Phyllochron~phyllo13$Variety) #significant: p value 1.664e-06
master_stats$sig_type[master_stats$names.dat...5.11..=="Phyllo13"]=1.66e-06
kruskal.test(phyllo13$Phyllochron~phyllo13$Treatment) #significant: p value 0.0005
master_stats$sig_Variety[master_stats$names.dat...5.11..=="Phyllo13"]=0.0005
kruskal.test(phyllo13$Phyllochron~phyllo13$type) ##significant: p-value = 0.02428
master_stats$sig_treatment[master_stats$names.dat...5.11..=="Phyllo13"]=0.02428
#posthoc tests
posthoc.kruskal.nemenyi.test(phyllo13$Phyllochron~phyllo13$Variety, dist="Chisquare")
posthoc.kruskal.nemenyi.test(phyllo13$Phyllochron~phyllo13$Treatment, dist="Chisquare")
posthoc.kruskal.nemenyi.test(phyllo13$Phyllochron~phyllo13$type, dist="Chisquare")
#fit a glm
summary(glm(phyllo13$Phyllochron~phyllo13$Treatment*phyllo13$Variety))
#try a boxcox transformation
test.lm=lm(phyllo13$Phyllochron~phyllo13$Treatment*phyllo13$Variety)
plot(test.lm)
bc=boxcox(test.lm)
#phyllochron 2-3
hist(dat$Phyllo23)
boxplot(dat$Phyllo23~dat$Variety)
boxplot(dat$Phyllo23~dat$Treatment)
boxplot(dat$Phyllo23~dat$Type)
#test for normality
qqnorm(dat$Phyllo23)
qqline(dat$Phyllo23)
shapiro.test(dat$Phyllo23)
#not normally distributed
kruskal.test(dat$Phyllo23~dat$Variety) #not significant
kruskal.test(dat$Phyllo23~dat$Treatment) #barely significant
kruskal.test(dat$Phyllo23~dat$Type) #not significant
master_stats$sig_treatment[master_stats$names.dat...5.11..=="Phyllo23"]=0.0469
master_stats$sig_Variety[master_stats$names.dat...5.11..=="Phyllo23"]="NOT"
master_stats$sig_type[master_stats$names.dat...5.11..=="Phyllo23"]="NOT"
posthoc.kruskal.nemenyi.test(dat$Phyllo23~dat$Treatment) #no significane
#phyllo 34
hist(dat$Phyllo34)
boxplot(dat$Phyllo34~dat$Variety)
boxplot(dat$Phyllo34~dat$Treatment)
boxplot(dat$Phyllo34~dat$Type)
qqnorm(dat$Phyllo34)
qqline(dat$Phyllo34)
shapiro.test(dat$Phyllo34)
kruskal.test(dat$Phyllo34~dat$Variety) #significant
kruskal.test(dat$Phyllo34~dat$Treatment) #not significant
kruskal.test(dat$Phyllo34~dat$Type) #not significant
master_stats$sig_treatment[master_stats$names.dat...5.11..=="Phyllo34"]="NOT"
master_stats$sig_Variety[master_stats$names.dat...5.11..=="Phyllo34"]=0.0117
master_stats$sig_type[master_stats$names.dat...5.11..=="Phyllo34"]="NOT"
#pyhllo 14
hist(dat$Phyllo14)
boxplot(dat$Phyllo14~dat$Variety)
boxplot(dat$Phyllo14~dat$Treatment)
boxplot(dat$Phyllo14~dat$Type)
qqnorm(dat$Phyllo14)
qqline(dat$Phyllo14)
shapiro.test(dat$Phyllo14) #not normally distributed
kruskal.test(dat$Phyllo14~dat$Variety) #significant 4.29e-06
kruskal.test(dat$Phyllo14~dat$Treatment) #not significant
kruskal.test(dat$Phyllo14~dat$Type) #not significant
master_stats$sig_treatment[master_stats$names.dat...5.11..=="Phyllo14"]="NOT"
master_stats$sig_Variety[master_stats$names.dat...5.11..=="Phyllo14"]=4.29e-06
master_stats$sig_type[master_stats$names.dat...5.11..=="Phyllo14"]="NOT"
#phyllo 24
hist(dat$Phyllo24)
boxplot(dat$Phyllo24~dat$Variety)
boxplot(dat$Phyllo24~dat$Treatment)
boxplot(dat$Phyllo24~dat$Type)
qqnorm(dat$Phyllo24)
qqline(dat$Phyllo24)
shapiro.test(dat$Phyllo24) #not normally distributed
kruskal.test(dat$Phyllo24~dat$Variety) #significant
kruskal.test(dat$Phyllo24~dat$Treatment) #not significant
kruskal.test(dat$Phyllo24~dat$Type) #not significant
master_stats$sig_treatment[master_stats$names.dat...5.11..=="Phyllo24"]="NOT"
master_stats$sig_Variety[master_stats$names.dat...5.11..=="Phyllo24"]=0.00144
master_stats$sig_type[master_stats$names.dat...5.11..=="Phyllo24"]="NOT"
write.csv(x=master_stats, file="master_stats.csv")
#write master table to aggregate data for all phyllochrons
agg_data_mean=aggregate(cbind(Phyllo12, Phyllo13, Phyllo14, Phyllo23, Phyllo24, Phyllo34)~Variety+Treatment, data=dat, FUN =mean)
agg_data_sd=aggregate(cbind(Phyllo12, Phyllo13, Phyllo14, Phyllo23, Phyllo24, Phyllo34)~Variety+Treatment, data=dat, FUN =sd)
names=names(agg_data_sd)
names_new=paste("sd_",names)
names(agg_data_sd)=names_new
names2=names(agg_data_mean)
names(agg_data_mean)=paste("mean_",names2)
agg_data=cbind(agg_data_mean, agg_data_sd)
str(agg_data)
agg_data=agg_data[,-9]
agg_data=agg_data[,-9]
str(agg_data)
plot(agg_data$Variety[agg_data$Treatment=="CON"], agg_data$Phyllo12[agg_data$Treatment=="CON"],"l")
summary(agg_data)
write.csv(agg_data, file="agg_data.csv")