nonsmokers <- c(70,58,51,56,53,53,65) light <- c(67,75,65,78,62,70,73) heavy <- c(79,80,77,77,86,68,83)

rate <- c(nonsmokers, light, heavy)

group <- factor(rep(c(“Nonsmoker”,“Light”,“Heavy”), each = 7))

heart_df <- data.frame(rate, group)

boxplot(rate ~ group, data = heart_df, col = c(“lightblue”,“orange”,“red”), main = “Heart Rate by Smoking Group”, ylab = “Heart Rate”)

tapply(rate, group, mean) tapply(rate, group, sd) tapply(rate, group, var)

n <- length(nonsmokers) s2 <- var(nonsmokers)

lower <- (n-1)s2 / qchisq(0.975, df=n-1) upper <- (n-1)s2 / qchisq(0.025, df=n-1)

c(lower, upper)

s1 <- var(light) s2 <- var(heavy)

ratio <- s1/s2

df1 <- length(light)-1 df2 <- length(heavy)-1

lower <- ratio / qf(0.975, df1, df2) upper <- ratio / qf(0.025, df1, df2)

c(lower, upper)

var.test(light, heavy)

fit_oneway <- aov(rate ~ group, data = heart_df) summary(fit_oneway)

qqnorm(residuals(fit_oneway)) qqline(residuals(fit_oneway))

TukeyHSD(fit_oneway)

#Question 2

Location <- factor(rep(c(“Chicago”,“Bolingbrook”,“Peoria”), times = 6))

Service <- factor(rep(c(“Specialty”,“Specialty”,“Specialty”, “General”,“General”,“General”), each = 3))

Price <- c( 79.80,95.96,99.96, 111.80,119.80,107.96, 95.96,115.96,79.80, 87.96,89.80,91.96, 107.80,119.80,99.80, 99.80,112.52,111.96)

oil_df <- data.frame(Location, Service, Price)

interaction.plot(oil_df\(Location, oil_df\)Service, oil_df$Price, col=c(“blue”,“red”), lwd=2) fit_two <- aov(Price ~ Location * Service, data = oil_df) summary(fit_two)

TukeyHSD(fit_two, which=“Location”) TukeyHSD(fit_two, which=“Service”)