How to implement One Way ANOVA in R?

Description

To implement the one way ANOVA using R programming.

One Way ANOVA:
  • Compares means of more than twoindependent groups.
 Hypothesis:
  • H0: Means of different groups are same
  • H1: Atleast one sample mean is notequal to others
 Assmptions of One-Way ANOVA:
  • Groups are independent with eachother
  • Data of each group are normallydistributed
  • Normal Population should have commonvariance
 R Functions :
  • R Function :aov(formula)
  • formula -- a formula specifyingthe model
  • R Function : TukeyHSD(x) -- to evaluatepair means
  • x -- a fitted model object, usually
Interpretation of plotted pairwise t test :
  • Significant differences are the oneswhich not cross the zero value.

#One way ANOVA
#Input
View(iris)
input<-iris$Sepal.Width
input1<-iris$Species

#Box Plot
boxplot(input~input1,col=c(“green”,”yellow”,”blue”),horizontal=FALSE)
title(main = “Box Plot”,xlab = “Species”,ylab = “Petal.Width”)

#Normality of data of each group
#Histogram
#install.packages(“FSA”)
library(“FSA”)
hist(Sepal.Length~Species,data=iris,col=c(“red”,”yellow”,”blue”))

#Mean value
mean_val<-round(tapply(input,input1,mean),digits = 2)
print(mean_val)

#Plotting Means
#install.packages(“gplots”)
library(“gplots”)
plotmeans(input~input1,col = “red”,mean.labels = TRUE,pos=4,xlab = “Species”,ylab = “Petal Width”,main=”Plot of Petal Width means by Species”,pch=15,cex=1)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit