Q2

Data Import

t7q2 <- read.table("C:/Users/Wei Hao/Desktop/ST2137/Tutorials/Data/locate.txt", header=T)
attach(t7q2)

ANOVA Model

Fit an analysis of variance model by a call to lm for each stratum.

model1 <- aov(sales~location)

Model Checking For Normality

mcheck <- function(obj) {
  rs <- obj$resid
  fv <- obj$fitted
  par(mfrow=c(2,1))
  plot(fv, rs, xlab="Fitted values", ylab="Residuals")
  abline(h=0, lty=2)
  qqnorm(rs, xlab="normal scores", ylab="ordered residuals")
  qqline(rs, lty=2)
  par(mfrow=c(1,1))
}
mcheck(model1)

One-sample Kolmogorov-Smirnov test

ks.test(model1$resid,"pnorm",mean(model1$resid),sd(model1$resid))
## Warning in ks.test(model1$resid, "pnorm", mean(model1$resid),
## sd(model1$resid)): ties should not be present for the Kolmogorov-Smirnov
## test
## 
##  One-sample Kolmogorov-Smirnov test
## 
## data:  model1$resid
## D = 0.11468, p-value = 0.9719
## alternative hypothesis: two-sided

The plots and the test show no evidence of violating the normality assumption.