You are on page 1of 24

Business Statistics

11 f-Distribution

One Way ANOVA

Dr Akhter Raza
Comparing multiple means
A business manager have the responsibility for testing
and comparing the lifetimes of four brands (Apollo,
Bridgestone, CEAT and Falken) of automobile tyres.
The lifetime of these sample observations are
measured in mileage run in ’000 miles. For each brand
of automobile tyre, sample of 15 observations have
been collected. On the basis of these information, you
have to take you decision regarding the four brands of
automobile tyre. The data is provided in the csv file
format (called, tyre.csv).
2
One Way ANOVA
In order to test and compare the lifetimes of four
brands of tyre, you should apply one-way ANOVA
method as there is only one factor or criterion
(mileage run) to classify the sample observations. The
null and alternative hypothesis to be used is given as:

3
Null and alternate hypothesis
Null hypothesis is “brand doesn’t matter in predicting
tire mileage – all brands are the same”

Alternate hypothesis: at least two brands of tyres have


un equal coverage of mileage

4
Variables and their types
Following data set with 60 observations with two
variables one is continuous other is nominal

Column Contains Type


Brands What brand tyre factor
Mileage Tyre life in thousands num

5
Loading data file
tyre<-read.csv(file.choose())

# tyre<-read.csv("tyre.csv") # if you have


#finding structure of data file

summary(tyre)
str(tyre)
head(tyre)
6
Tire data summary

7
Box plot and descriptives
boxplot(tyre$Mileage,
horizontal = TRUE,
main="Mileage distribution across all brands",
col = "blue")

8
Brand wise boxplot
boxplot(tyre$Mileage~tyre$Brands,
main="Boxplot comparing Mileage of Four
Brands of Tyre", col= rainbow(4), horizontal = T)

9
Boxplot by ggplot2
install.packages("ggplot2")
library(ggplot2)

ggplot(tyre,
aes(reorder(Brands,Mileage),Mileage,fill=Brands))+
geom_jitter(colour = "dark gray",width=.1) +
stat_boxplot(geom ='errorbar',width = 0.4) +
geom_boxplot()+

10
Boxplot by ggplot2
labs(title="Boxplot, dotplot and SEM plot of mileage
for four brands of tyres",
x = "Brands (sorted)",
y = "Mileage (in thousands)",
subtitle ="Gray dots=sample data points, Black
dot=outlier, Blue dot=mean, Red=99% confidence
interval",
caption = "Data from
https://datascienceplus.com/one-way-anova-in-r/")
+
11
Boxplot by ggplot2
guides(fill=FALSE) +
stat_summary(fun.data = "mean_cl_normal",
colour = "red", size = 1.5, fun.args =
list(conf.int=.99)) +
stat_summary(geom="point", fun.y=mean,
color="blue") +
theme_bw()

12
Boxplots by ggplot

13
Implementing f-test for ANOVA
tyres.aov<- aov(Mileage~Brands, tyre)

class(tyres.aov)

typeof(tyres.aov)

names(tyres.aov)

14
Implementing f-test for ANOVA

15
ANOVA output
summary(tyres.aov)

16
Pairwise comparisons

pairwise.t.test(tyre$Mileage,tyre$Brands,p.adjus
t.method = "none")

17
Post hoc analysis
TukeyHSD(tyres.aov, conf.level = 0.95)

18
plot(tyres.aov)

19
Computing and plotting residuals
tyre.anova.residuals <- residuals( object = tyres.aov )
hist( x = tyre.anova.residuals )

20
Testing normality of residuals
# shapiro test
shapiro.test( x = tyre.anova.residuals )

21
Kolmogrov Smirnov test
# Kolmogrov test for testing normality of residuals
ks.test(tyre.anova.residuals, "pnorm",
mean(tyre.anova.residuals), sd(tyre.anova.residuals) )

22
Levene test for homoscedasticity
install.packages("car")
library(car)
leveneTest(tyres.aov, center = mean) # traditional Levene

23
Questions?

You might also like