STP 531 HW 2

Question 1

df = data.frame(prod = c(7.6,8.2,6.8,5.8,6.9,6.6,6.3,7.7,6.0,6.7,8.1,9.4,8.6,7.8,7.7,8.9,7.9,8.3,8.7,7.1,8.4,8.5,9.7,10.1,7.8,9.6,9.5),
           level = c(rep("low",9),rep("moder",12),rep("high",6)))
ggplot2.dotplot(data=df, xName='level',yName='prod', groupName='level',legendPosition="top",addBoxplot=TRUE)
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.

av = aov(prod~level,data=df)
low.mean = mean(df$prod[df$level == "low"])
moder.mean = mean(df$prod[df$level == "moder"])
high.mean = mean(df$prod[df$level == "high"])
low.mean
## [1] 6.877778
moder.mean
## [1] 8.133333
high.mean
## [1] 9.2
round(sum(av$residuals),5)
## [1] 0

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

anova(av)
## Analysis of Variance Table
## 
## Response: prod
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## level      2 20.125 10.0626   15.72 4.331e-05 ***
## Residuals 24 15.362  0.6401                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Question 2

Insert Plot

anova(av)
## Analysis of Variance Table
## 
## Response: prod
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## level      2 20.125 10.0626   15.72 4.331e-05 ***
## Residuals 24 15.362  0.6401                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
mse = 0.6401
se = sqrt( mse/6)
t = qt(.975,24)
c(high.mean - t*se,high.mean + t*se)
## [1] 8.525881 9.874119
d1 = moder.mean - low.mean
se1 = sqrt(mse*(1/9+1/12))
c(d1 - t*se1,d1 + t*se1)
## [1] 0.5274237 1.9836874
d2 = high.mean - low.mean
d3 = high.mean - moder.mean
se2 = (sqrt(mse*(1/9+1/6)))
se3 = (sqrt(mse*(1/12+1/6)))

tuk = qtukey(.9,3,24)/sqrt(2)

q1 = sqrt(2)*d1/se1
q2 = sqrt(2)*d2/se2
q3 = sqrt(2)*d3/se3

c(d1 - tuk*se1,d1 + tuk*se1)
## [1] 0.4954121 2.0156990
c(d2 - tuk*se2,d2 + tuk*se2)
## [1] 1.413677 3.230767
c(d3 - tuk*se3,d3 + tuk*se3)
## [1] 0.2047451 1.9285883
q1
## [1] 5.033027
q2
## [1] 7.788362
q3
## [1] 3.770942

All of \(q_1,q_2,q_3\) are out of their respective confidence intervals. Thus all the difference are significant

(tuk < qf(.9,3,24)) & (tuk < qt(1-.025/3,24))
## [1] TRUE