Case Study 5-01

Read in the data into a data frame

> case0501 = read.table("case0501.csv",sep=",",header=T)

Make sure the structure of the data frame is correct.

> str(case0501)

Attach the data frame so variables can be refered to by name.

> attach(case0501)

Find sample size, means, and SDs for each group

> unlist(lapply(split(LIFETIME,DIET),length))
> unlist(lapply(split(LIFETIME,DIET),mean))
> unlist(lapply(split(LIFETIME,DIET),sd))

Fit an ANOVA using lm

> fit1 = lm(LIFETIME ~ DIET)
> summary(fit1)
> anova(fit1)

Fit an ANOVA using aov

> fit2 = aov(LIFETIME ~ DIET)
> summary(fit2)

Make several summary plots

> plot(fit1)

Plot Residuals versus fitted values

> plot(fitted(fit1),residuals(fit1))