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 two
    independent groups.

 

Hypothesis:

  • H0: Means of different groups are same
  • H1: Atleast one sample mean is not
    equal to others

 

Assmptions of One-Way ANOVA:

  • Groups are independent with each
    other
  • Data of each group are normally
    distributed
  • Normal Population should have common
    variance

 

R Functions :

  • R Function :aov(formula)
  • formula — a formula specifying
    the model
  • R Function : TukeyHSD(x) — to evaluate
    pair means
  • x —  a fitted model object, usually

Interpretation of plotted pairwise t test :

  • Significant differences are the ones
    which 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