The data contains crop stalk (measured in cm) based on the two grain crops, rye and wheat. There are three synthetic and one organic fertilizer treatments used to investigate the impact in the growth of said crop stalk.
library(knitr)
fertilizer <- read.table(file ="fertilizer.txt", T)
fertilizer
fertilizer$grain.crop <- factor(fertilizer$grain.crop)
fertilizer$fertilizers <- factor(fertilizer$fertilizers)
library(dplyr)
descriptive.grain.crop <-fertilizer %>%
group_by(grain.crop)%>%
summarise(n = n(),mean = mean(stalk.growth),
sd = sd(stalk.growth), IQR = IQR(stalk.growth))
descriptive.grain.crop
library(dplyr)
descriptive.fertilizers <-fertilizer %>%
group_by(fertilizers)%>%
summarise(n = n(),mean = mean(stalk.growth),
sd = sd(stalk.growth), IQR = IQR(stalk.growth))
descriptive.fertilizers
library(ggplot2)
ggplot(fertilizer, aes(y=stalk.growth, x=grain.crop)) + geom_boxplot() +
xlab("Grain Crop") + ylab("Stalk Growth (cm)")
The fertilizers that were used seem to be much more effective in wheat than rye.
library(ggplot2)
ggplot(fertilizer, aes(y=stalk.growth, x=fertilizers)) + geom_boxplot() +
xlab("Type of Fertilizer") + ylab("Stalk Growth (cm)")
Based on the boxplots it seems that the synthetic fertilizers performed better than the organic one.
plot.design(stalk.growth~grain.crop*fertilizers,data=fertilizer)
Based on the plotted means, the synthetic 03 fertilizer has the highest average measurement of its crop stalk across the two grain crops. There is also a high variability in the type of fertilizers that were used but it can be cleary seen that all synthetic fertilizers outperformed the organic one.
with(fertilizer, interaction.plot(grain.crop,fertilizers,stalk.growth,type="b",pch=19,fixed=T,
xlab="Grain Crop", ylab="Stalk Growth (cm)"))
The results are similar on the previous boxplots where it shows that the fertilizers performed better in wheat than rye. Also the synthetic 03 is the best type of fertilizer because it yield the longest average crop stalk among others.
fertilizer.aov <- aov(stalk.growth ~ grain.crop * fertilizers, data=fertilizer)
summary(fertilizer.aov)
## Df Sum Sq Mean Sq F value Pr(>F)
## grain.crop 1 236.7 236.74 69.64 2.71e-10 ***
## fertilizers 3 745.4 248.48 73.10 2.77e-16 ***
## grain.crop:fertilizers 3 50.6 16.86 4.96 0.00508 **
## Residuals 40 136.0 3.40
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Based on the table, all the factors contributed significantly to the model since all of their p-values are less than 0.05. Meaning that the type of grain crop and fertilizers that were used are important in the length of growth of crop stalk.
library(DescTools)
DMRT.fertilizer <- PostHocTest(fertilizer.aov, method = "duncan")
DMRT.fertilizer
##
## Posthoc multiple comparisons of means : Duncan's new multiple range test
## 95% family-wise confidence level
##
## $grain.crop
## diff lwr.ci upr.ci pval
## wheat-rye 4.441667 3.365986 5.517348 2.7e-10 ***
##
## $fertilizers
## diff lwr.ci upr.ci pval
## syn.01-organic 7.758333 6.158815 9.3578513 1.4e-12 ***
## syn.02-organic 5.608333 4.087091 7.1295758 4.5e-09 ***
## syn.03-organic 10.783333 9.132613 12.4340538 1.5e-13 ***
## syn.02-syn.01 -2.150000 -3.671242 -0.6287575 0.00676 **
## syn.03-syn.01 3.025000 1.503758 4.5462425 0.00025 ***
## syn.03-syn.02 5.175000 3.575482 6.7745180 4.2e-08 ***
##
## $`grain.crop:fertilizers`
## diff lwr.ci upr.ci pval
## wheat:organic-rye:organic 2.700000 0.54863827 4.8513617 0.0152 *
## rye:syn.01-rye:organic 7.600000 5.26552870 9.9344713 2.4e-08 ***
## wheat:syn.01-rye:organic 10.616667 8.15862846 13.0747049 7.3e-12 ***
## rye:syn.02-rye:organic 4.866667 2.60460667 7.1287267 6.7e-05 ***
## wheat:syn.02-rye:organic 9.050000 6.62350652 11.4764935 4.9e-10 ***
## rye:syn.03-rye:organic 8.200000 5.81333267 10.5866673 4.9e-09 ***
## wheat:syn.03-rye:organic 16.066667 13.58297664 18.5503567 6.6e-14 ***
## rye:syn.01-wheat:organic 4.900000 2.63794001 7.1620600 6.0e-05 ***
## wheat:syn.01-wheat:organic 7.916667 5.49017319 10.3431601 1.4e-08 ***
## rye:syn.02-wheat:organic 2.166667 0.01530493 4.3180284 0.0485 *
## wheat:syn.02-wheat:organic 6.350000 3.96333267 8.7366673 1.3e-06 ***
## rye:syn.03-wheat:organic 5.500000 3.16552870 7.8344713 1.3e-05 ***
## wheat:syn.03-wheat:organic 13.366667 10.90862846 15.8247049 8.6e-14 ***
## wheat:syn.01-rye:syn.01 3.016667 0.68219537 5.3511380 0.0117 *
## rye:syn.02-rye:syn.01 -2.733333 -4.88469507 -0.5819716 0.0141 *
## wheat:syn.02-rye:syn.01 1.450000 -0.81205999 3.7120600 0.2063
## rye:syn.03-rye:syn.01 0.600000 -1.55136173 2.7513617 0.5761
## wheat:syn.03-rye:syn.01 8.466667 6.07999934 10.8533340 2.2e-09 ***
## rye:syn.02-wheat:syn.01 -5.750000 -8.13666733 -3.3633327 7.8e-06 ***
## wheat:syn.02-wheat:syn.01 -1.566667 -3.71802840 0.5846951 0.1489
## rye:syn.03-wheat:syn.01 -2.416667 -4.67872666 -0.1546067 0.0366 *
## wheat:syn.03-wheat:syn.01 5.450000 3.29863827 7.6013617 8.1e-06 ***
## wheat:syn.02-rye:syn.02 4.183333 1.84886204 6.5178046 0.0006 ***
## rye:syn.03-rye:syn.02 3.333333 1.07127334 5.5953933 0.0045 **
## wheat:syn.03-rye:syn.02 11.200000 8.77350652 13.6264935 1.4e-12 ***
## rye:syn.03-wheat:syn.02 -0.850000 -3.00136173 1.3013617 0.4293
## wheat:syn.03-wheat:syn.02 7.016667 4.75460667 9.2787267 1.0e-07 ***
## wheat:syn.03-rye:syn.03 7.866667 5.53219537 10.2011380 1.1e-08 ***
##
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
posthoc.fertilizer<-as.data.frame(DMRT.fertilizer$`grain.crop:fertilizers`)%>%
slice(1,14,23,28)
posthoc.fertilizer
All fertilizer treatments are significantly different in the growth of crop stalk across the two grain crops.
space.fertilizer<- par(mfrow=c(2,2),cex=0.8)
plot(fertilizer.aov)
par(space.fertilizer)
Based on the plots above, there are some questionable patterns that need to be tested further. In the Normal Q-Q plot, some of the points were clearly deviating from the line so, Shapiro-Wilk test will be used later to confirm the assumption of normality. While in the Scale-Location plot, the standardized residuals are not in a horizontal plot so we need to perform some test to check if there is a need for transformation.
shapiro.test(residuals(object = fertilizer.aov ))
##
## Shapiro-Wilk normality test
##
## data: residuals(object = fertilizer.aov)
## W = 0.96617, p-value = 0.1789
Since the p-value for Shapiro-Wilk Test is greater than 0.05, then we can assume for normality.
library(MASS)
boxcox(fertilizer.aov,lambda = seq(-2, 2, 1/10))
abline(v=1,col="blue")
There is no need for transformation since the 95% confidence level still includes lambda = 1.