library(knitr)
## Warning: package 'knitr' was built under R version 4.0.5
##Get working directory##
getwd()
## [1] "C:/Users/Acer/Desktop"
setwd("C:/Users/Acer/Desktop")
##Set data frame###
dataframe<-read.csv("C:/Users/Acer/Desktop/eggplant.csv")
###load prerequesite##
library(agricolae)
## Warning: package 'agricolae' was built under R version 4.0.5
##Check the data###
names(dataframe)
## [1] "Factor.A" "Factor.B" "Samples" "Plant.ht.2wk" "NoLvs"
##run ANOVA Factorial##
Anova<-aov(Plant.ht.2wk~Factor.A*Factor.B, data=dataframe)
summary(Anova)
## Df Sum Sq Mean Sq F value Pr(>F)
## Factor.A 1 7.37 7.370 6.376 0.02012 *
## Factor.B 1 0.77 0.770 0.666 0.42389
## Factor.A:Factor.B 1 10.27 10.270 8.885 0.00739 **
## Residuals 20 23.12 1.156
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
###Assumption checking##
shapiro.test(Anova$residuals)
##
## Shapiro-Wilk normality test
##
## data: Anova$residuals
## W = 0.9645, p-value = 0.5352
###Assumption plot###
par(mfrow=c(1,1))
plot (Anova)


## hat values (leverages) are all = 0.1666667
## and there are no factor predictors; no plot no. 5


###interaction plot###
interaction.plot(x.factor = dataframe$Factor.B, #x-axis variable
trace.factor = dataframe$Factor.A, #variable for lines
response = dataframe$Plant.ht.2wk, #y-axis variable
fun = median, #metric to plot
ylab = "Number of Leaves",
xlab = "Growing Media",
col = c("pink", "blue"),
lty = 1, #line type
lwd = 2, #line width
trace.label = "Container Size")
