-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskGabriel1.R
136 lines (90 loc) · 4.39 KB
/
TaskGabriel1.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
### This Gabriel`s work, please, for our sake, do not alter without consent.
source("01_import-data.R")
library(dplyr)
library(car)
library(agricolae)
library(ggplot2)
library(ggpubr)
library(rstatix)
library(RVAideMemoire)
## The essence of this part is to analyze the effect of treatments on larvae weight(working with the dataframe weight)
### Hypothesis:
#H0: Larval weight does not depend upon the concentration of insecticide it is exposed to.
#H1: Larval weight depends upon the concentration of insecticide it is exposed to.
lavalweight <- weig
View(lavalweight)
### Make new data.frames from lavalweight for the initial and final time (1 & 4)
#for optimum analysis
Initialwgt <- filter(lavalweight, Time == 1)
Finalwgt <- filter(lavalweight, Time == 4)
###Find the difference between the final and initial weight. There is a difference
## in the number of row between the newly created data.frames, because some lavae
#escaped before the final weight and some immediately after the first weight, so
#there is a need to get those reps that have both the final and the initial weight
#to get the difference in weight.
Fordifference <- filter(lavalweight, Time == 4)
Initialweight <- replicate(153, 0)
Fordifference <- data.frame(Fordifference, Initialweight)
for(i in 1:nrow(Fordifference)){
for(j in 1:nrow(Initialwgt)){
if(Fordifference$Rep[i] == Initialwgt$Rep[j]){
Fordifference$Initialweight[i] <- Initialwgt$weight[j]
}}}
###Change the weight to final weight to differentiate between initial and final weight
colnames(Fordifference)[colnames(Fordifference) == "weight"] <- "Finalweight"
colnames(Fordifference)[colnames(Fordifference) == "Rep"] <- "RepID"
##Create another column for difference between final and initial weight
Fordifference$Difference <- (Fordifference$Finalweight - Fordifference$Initialweight)
##Remove the column time from the data.frame
Fordifference <- select(Fordifference, -Time)
##Arrange the column of the data.frame in the order below
Fordifference <- Fordifference[c("RepID", "Treatment", "FIL", "Initialweight",
"Finalweight", "Difference")]
##Check the structure of newly created dataframes
str(Fordifference)
## The treatment, FIL and Time were integer, so i needed to convert them to a
##factor for easier manipulation.
Fordifference$Treatment <- as.factor(Fordifference$Treatment)
Fordifference$FIL <- as.factor(Fordifference$FIL)
str(Fordifference)
#One-way ANOVA to determine the effect of thiamethoxam on weight and shapiro.test
res.aov<- aov(Difference ~ Treatment, data = Fordifference)
rs <- shapiro.test(res.aov$residuals)
print (rs[["p.value"]])
ggdensity(res.aov$residuals, fill = "lightgray", title = "Distribution shape of the data")
qqnorm(res.aov$residuals)
qqline(res.aov$residuals)
## Based on the shapiro.test, we can conclude that the distribution of weight
#diverge from normal distribution. There is need to use another statistical test
#which can perfectly analyze a not normal distributed data.
#Kruskal Wallis to determine the effect of thiamethoxam on pupal weight
weight <- Fordifference$Difference
kruz <- kruskal(weight, trt = Fordifference$Treatment)
print(kruz[["groups"]])
##Based on the Kruskal Wallis test, there is no significant difference between
## treatments
##Make a plot for visual representation of the analysis and comparison between treatments and control
my_comparisons <- list(c("0", "5"), c("0", "15"),c("0", "50"),c("0", "100"),
c("0", "500"))
Fordifference %>%
ggplot(aes(x = Treatment, group = Treatment, y = Difference, color = Treatment)) +
geom_violin(trim = F, width = 0.65, draw_quantiles = c(0.25, 0.5, 0.75)) +
theme_classic()+
scale_y_continuous(limits = c(0.15, 0.70)) +
xlab("Treatment") +
ylab("Weight")+
ggtitle("Comparison of treatment effect on larval weight")+
stat_compare_means(method = "kruskal.test")+
stat_compare_means(comparisons = my_comparisons,label.y = c(0.43,0.46,0.49,
0.52,0.55))+
stat_compare_means(label.y = 70)
###Fisher's test
##Hypothesis : H0 : the treatment has no effect on FIL
#H1 : the treatment has effect on FIL
ff <- table(Fordifference$FIL, Fordifference$Treatment)
ff
fisher.test(ff)
fisher.multcomp(ff)
#p-value 0.3198 is greater than 0.05, therefore,
##there is no sufficient evidence to accept the alternative hypothesis
###########