Problem 1

library(readxl)
HW5_prob1 <- read_excel("C:/Users/Joshu/OneDrive/Desktop/WSU courses/STAT511/test 2 material/HW5/HW5_prob1.xlsx")
attach(HW5_prob1)
mod1 = aov(y ~ soil * fert, data = HW5_prob1)
summary(mod1)
##             Df Sum Sq Mean Sq F value Pr(>F)  
## soil         2 141.75   70.87   4.573 0.0248 *
## fert         1 121.50  121.50   7.839 0.0118 *
## soil:fert    2  14.25    7.12   0.460 0.6387  
## Residuals   18 279.00   15.50                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
interaction.plot(soil,fert,y)

Tukey’s Procedure

soil_hsd = TukeyHSD(mod1, "soil", conf.level = .95)
soil_hsd
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = y ~ soil * fert, data = HW5_prob1)
## 
## $soil
##        diff        lwr       upr     p adj
## S2-S1 4.500 -0.5239382  9.523938 0.0837066
## S3-S1 5.625  0.6010618 10.648938 0.0269159
## S3-S2 1.125 -3.8989382  6.148938 0.8368074
fert_hsd = TukeyHSD(mod1, "fert", conf.level = .95)
fert_hsd
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = y ~ soil * fert, data = HW5_prob1)
## 
## $fert
##       diff     lwr     upr     p adj
## FB-FA  4.5 1.12324 7.87676 0.0118426
plot(soil_hsd)

qqnorm(residuals(mod1))
qqline(residuals(mod1), col = "red")

plot(fitted(mod1), residuals(mod1))

detach(HW5_prob1)

Problem 2

HW5_prob2 <- read_excel("C:/Users/Joshu/OneDrive/Desktop/WSU courses/STAT511/test 2 material/HW5/HW5_prob2.xlsx")
attach(HW5_prob2)
mod2 = aov(y ~ company * region, data = HW5_prob2)
summary(mod2)
##                Df Sum Sq Mean Sq F value  Pr(>F)   
## company         2   26.6   13.32   0.461 0.63445   
## region          3  446.0  148.67   5.142 0.00462 **
## company:region  6  108.2   18.03   0.624 0.71013   
## Residuals      36 1040.8   28.91                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
interaction.plot(company,region,y, col = 1:5)

Tukey’s Procedure

company_hsd = TukeyHSD(mod2, "company", conf.level = .95)
company_hsd
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = y ~ company * region, data = HW5_prob2)
## 
## $company
##         diff       lwr      upr     p adj
## B-A  1.82500 -2.821738 6.471738 0.6064798
## C-A  0.90625 -3.740488 5.552988 0.8826786
## C-B -0.91875 -5.565488 3.727988 0.8796366
plot(company_hsd)

region_hsd = TukeyHSD(mod2, "region", conf.level = .95)
region_hsd
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = y ~ company * region, data = HW5_prob2)
## 
## $region
##            diff        lwr        upr     p adj
## NE-MW  4.125000  -1.787029 10.0370287 0.2548209
## SE-MW -4.183333 -10.095362  1.7286954 0.2436859
## WW-MW -1.900000  -7.812029  4.0120287 0.8224546
## SE-NE -8.308333 -14.220362 -2.3963046 0.0030220
## WW-NE -6.025000 -11.937029 -0.1129713 0.0444000
## WW-SE  2.283333  -3.628695  8.1953620 0.7272263
plot(region_hsd)

qqnorm(residuals(mod2))
qqline(residuals(mod2), col = "red")

plot(fitted(mod2), residuals(mod2))

detach(HW5_prob2)

Problem 3

prob3 <- read_excel("C:/Users/Joshu/OneDrive/Desktop/WSU courses/STAT511/test 2 material/HW5/prob3.xlsx")
prob3$isolation = as.factor(prob3$isolation)
attach(prob3)

\(H_{0}:\) Level of reinforcement and level of isolation do not interact. 
\(H_{a}:\) Level of reinforcement and level of isolation do interact. 

mod3 = aov(value ~ level + isolation)
summary(mod3)
##             Df Sum Sq Mean Sq F value Pr(>F)  
## level        1  225.0  225.00   4.845 0.0351 *
## isolation    2  181.6   90.78   1.955 0.1581  
## Residuals   32 1486.0   46.44                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
interaction.plot(x.factor = isolation, trace.factor = level, response = value,col=1:2, fun = mean, xlab = "Isolation time", ylab = "mean value", legend = TRUE)

Tukey’s procedure

isolation_hsd = TukeyHSD(mod3, "isolation", conf.level = .95)
isolation_hsd
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = value ~ level + isolation)
## 
## $isolation
##            diff        lwr       upr     p adj
## 40-20  5.333333  -1.503101 12.169767 0.1502797
## 60-20  1.500000  -5.336434  8.336434 0.8526731
## 60-40 -3.833333 -10.669767  3.003101 0.3641799
level_hsd = TukeyHSD(mod3, "level", conf.level = .95)
level_hsd
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = value ~ level + isolation)
## 
## $level
##     diff       lwr      upr     p adj
## v-n    5 0.3731014 9.626899 0.0350534
qqnorm(residuals(mod3))
qqline(residuals(mod3), col = "red")

plot(fitted(mod3), residuals(mod3))

detach(prob3)

Problem 4

HW5_prob4 <- read_excel("C:/Users/Joshu/OneDrive/Desktop/WSU courses/STAT511/test 2 material/HW5/HW5_prob4.xlsx")
attach(HW5_prob4)

\(H_{0}: \mu_{1} = \mu_{2} = \mu_{3}\) 
\(H_{0}:\) At least one of the means are different. 

mod4 = aov(Score ~ Method + Block)
summary(mod4)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## Method       2 1295.0   647.5 103.754 1.32e-10 ***
## Block        9  433.4    48.2   7.716 0.000132 ***
## Residuals   18  112.3     6.2                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
interaction.plot(Method,Block,Score, col = 1:9, pch = c(1:9, 0, letters))

We reject \(H_{0}\) for each of Tukey’s comparisons

Method_hsd = TukeyHSD(mod4, "Method", conf.level = .95)
Method_hsd
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Score ~ Method + Block)
## 
## $Method
##         diff       lwr       upr     p adj
## "B"-"A"  4.0  1.148709  6.851291 0.0057634
## "C"-"A" 15.5 12.648709 18.351291 0.0000000
## "C"-"B" 11.5  8.648709 14.351291 0.0000000
qqnorm(residuals(mod4))
qqline(residuals(mod4), col = "red")

plot(fitted(mod4), residuals(mod4))