library(readxl)
Lab3 <- read_excel("Lab3.xlsx")
str(Lab3)
## Classes 'tbl_df', 'tbl' and 'data.frame': 54 obs. of 5 variables:
## $ RunningTemperature: chr "high" "high" "high" "low" ...
## $ StorageTemperature: chr "high" "high" "high" "high" ...
## $ Formulation : chr "F1" "F1" "F1" "F1" ...
## $ Machine : chr "M1" "M3" "M2" "M2" ...
## $ LifeinHours : num 25 16 20 27 24 26 26 26 20 24 ...
plot(density(Lab3$LifeinHours))

library(moments)
agostino.test(Lab3$LifeinHours)
##
## D'Agostino skewness test
##
## data: Lab3$LifeinHours
## skew = 0.49196, z = 1.57380, p-value = 0.1155
## alternative hypothesis: data have a skewness
bartlett.test( Lab3$LifeinHours,Lab3$RunningTemperature)
##
## Bartlett test of homogeneity of variances
##
## data: Lab3$LifeinHours and Lab3$RunningTemperature
## Bartlett's K-squared = 5.3959, df = 2, p-value = 0.06734
bartlett.test( Lab3$LifeinHours,Lab3$StorageTemperature)
##
## Bartlett test of homogeneity of variances
##
## data: Lab3$LifeinHours and Lab3$StorageTemperature
## Bartlett's K-squared = 3.9424, df = 2, p-value = 0.1393
bartlett.test( Lab3$LifeinHours,Lab3$Formulation)
##
## Bartlett test of homogeneity of variances
##
## data: Lab3$LifeinHours and Lab3$Formulation
## Bartlett's K-squared = 0.7178, df = 1, p-value = 0.3969
model <- aov(LifeinHours ~ RunningTemperature*StorageTemperature*Formulation + Machine, data = Lab3)
summary(model)
## Df Sum Sq Mean Sq
## RunningTemperature 2 770.3 385.1
## StorageTemperature 2 585.5 292.7
## Formulation 1 363.0 363.0
## Machine 2 64.0 32.0
## RunningTemperature:StorageTemperature 4 201.6 50.4
## RunningTemperature:Formulation 2 7.1 3.6
## StorageTemperature:Formulation 2 4.6 2.3
## RunningTemperature:StorageTemperature:Formulation 4 1.0 0.2
## Residuals 34 474.6 14.0
## F value Pr(>F)
## RunningTemperature 27.589 7.60e-08 ***
## StorageTemperature 20.970 1.17e-06 ***
## Formulation 26.001 1.28e-05 ***
## Machine 2.294 0.1163
## RunningTemperature:StorageTemperature 3.611 0.0148 *
## RunningTemperature:Formulation 0.256 0.7756
## StorageTemperature:Formulation 0.164 0.8490
## RunningTemperature:StorageTemperature:Formulation 0.017 0.9994
## Residuals
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
TukeyHSD(model, c("RunningTemperature","StorageTemperature","Formulation"))
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = LifeinHours ~ RunningTemperature * StorageTemperature * Formulation + Machine, data = Lab3)
##
## $RunningTemperature
## diff lwr upr p adj
## low-high 9.111111 6.059283 12.162939 0.0000001
## med-high 5.944444 2.892617 8.996272 0.0000981
## med-low -3.166667 -6.218494 -0.114839 0.0406306
##
## $StorageTemperature
## diff lwr upr p adj
## low-high 8.000000 4.948172 11.05182766 0.0000007
## med-high 4.888889 1.837061 7.94071654 0.0011388
## med-low -3.111111 -6.162939 -0.05928346 0.0449486
##
## $Formulation
## diff lwr upr p adj
## F2-F1 5.185185 3.11863 7.251741 1.28e-05
tapply(Lab3$LifeinHours,Lab3[,1:3], mean)
## , , Formulation = F1
##
## StorageTemperature
## RunningTemperature high low med
## high 20.33333 25.66667 22.66667
## low 25.66667 38.33333 29.33333
## med 24.00000 30.33333 31.00000
##
## , , Formulation = F2
##
## StorageTemperature
## RunningTemperature high low med
## high 24.66667 29.33333 27.66667
## low 31.00000 44.33333 36.33333
## med 29.00000 34.66667 37.00000
library(carData)
## Warning: package 'carData' was built under R version 3.4.4
interaction.plot(Lab3$RunningTemperature,Lab3$StorageTemperature,Lab3$LifeinHours)

Lab3$RunningTemperature <- factor(Lab3$RunningTemperature, levels = c("low","med","high"))
Lab3$StorageTemperature <- factor(Lab3$StorageTemperature, levels = c("low","med","high"))
interaction.plot(Lab3$RunningTemperature,Lab3$StorageTemperature,Lab3$LifeinHours)

TukeyHSD(model,"RunningTemperature:StorageTemperature")
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = LifeinHours ~ RunningTemperature * StorageTemperature * Formulation + Machine, data = Lab3)
##
## $`RunningTemperature:StorageTemperature`
## diff lwr upr p adj
## low:high-high:high 5.8333333 -1.3044705 12.9711372 0.1841865
## med:high-high:high 4.0000000 -3.1378038 11.1378038 0.6475577
## high:low-high:high 5.0000000 -2.1378038 12.1378038 0.3600327
## low:low-high:high 18.8333333 11.6955295 25.9711372 0.0000000
## med:low-high:high 10.0000000 2.8621962 17.1378038 0.0014913
## high:med-high:high 2.6666667 -4.4711372 9.8044705 0.9422793
## low:med-high:high 10.3333333 3.1955295 17.4711372 0.0009592
## med:med-high:high 11.5000000 4.3621962 18.6378038 0.0001998
## med:high-low:high -1.8333333 -8.9711372 5.3044705 0.9941701
## high:low-low:high -0.8333333 -7.9711372 6.3044705 0.9999817
## low:low-low:high 13.0000000 5.8621962 20.1378038 0.0000259
## med:low-low:high 4.1666667 -2.9711372 11.3044705 0.5979620
## high:med-low:high -3.1666667 -10.3044705 3.9711372 0.8621541
## low:med-low:high 4.5000000 -2.6378038 11.6378038 0.4986512
## med:med-low:high 5.6666667 -1.4711372 12.8044705 0.2130636
## high:low-med:high 1.0000000 -6.1378038 8.1378038 0.9999261
## low:low-med:high 14.8333333 7.6955295 21.9711372 0.0000021
## med:low-med:high 6.0000000 -1.1378038 13.1378038 0.1583827
## high:med-med:high -1.3333333 -8.4711372 5.8044705 0.9993722
## low:med-med:high 6.3333333 -0.8044705 13.4711372 0.1153824
## med:med-med:high 7.5000000 0.3621962 14.6378038 0.0333593
## low:low-high:low 13.8333333 6.6955295 20.9711372 0.0000083
## med:low-high:low 5.0000000 -2.1378038 12.1378038 0.3600327
## high:med-high:low -2.3333333 -9.4711372 4.8044705 0.9730950
## low:med-high:low 5.3333333 -1.8044705 12.4711372 0.2803362
## med:med-high:low 6.5000000 -0.6378038 13.6378038 0.0977980
## med:low-low:low -8.8333333 -15.9711372 -1.6955295 0.0067147
## high:med-low:low -16.1666667 -23.3044705 -9.0288628 0.0000004
## low:med-low:low -8.5000000 -15.6378038 -1.3621962 0.0101667
## med:med-low:low -7.3333333 -14.4711372 -0.1955295 0.0402654
## high:med-med:low -7.3333333 -14.4711372 -0.1955295 0.0402654
## low:med-med:low 0.3333333 -6.8044705 7.4711372 1.0000000
## med:med-med:low 1.5000000 -5.6378038 8.6378038 0.9985376
## low:med-high:med 7.6666667 0.5288628 14.8044705 0.0275519
## med:med-high:med 8.8333333 1.6955295 15.9711372 0.0067147
## med:med-low:med 1.1666667 -5.9711372 8.3044705 0.9997649
tapply(Lab3$LifeinHours,Lab3$RunningTemperature:Lab3$StorageTemperature, mean)
## low:low low:med low:high med:low med:med med:high high:low
## 41.33333 32.83333 28.33333 32.50000 34.00000 26.50000 27.50000
## high:med high:high
## 25.16667 22.50000
qqnorm(model$residuals)
qqline(model$residuals)

shapiro.test(model$residuals)
##
## Shapiro-Wilk normality test
##
## data: model$residuals
## W = 0.96994, p-value = 0.1917