library(readxl)
## Warning: package 'readxl' was built under R version 3.4.4
WeeklyLab4Data <- read_excel("~/Downloads/WeeklyLab4Data.xlsx")
View(WeeklyLab4Data)
plot(density(WeeklyLab4Data$LifeinHours))

library(moments)
agostino.test(WeeklyLab4Data$LifeinHours)
##
## D'Agostino skewness test
##
## data: WeeklyLab4Data$LifeinHours
## skew = 0.49196, z = 1.57380, p-value = 0.1155
## alternative hypothesis: data have a skewness
bartlett.test(WeeklyLab4Data$LifeinHours,WeeklyLab4Data$RunningTemperature)
##
## Bartlett test of homogeneity of variances
##
## data: WeeklyLab4Data$LifeinHours and WeeklyLab4Data$RunningTemperature
## Bartlett's K-squared = 5.3959, df = 2, p-value = 0.06734
bartlett.test(WeeklyLab4Data$LifeinHours,WeeklyLab4Data$StorageTemperature)
##
## Bartlett test of homogeneity of variances
##
## data: WeeklyLab4Data$LifeinHours and WeeklyLab4Data$StorageTemperature
## Bartlett's K-squared = 3.9424, df = 2, p-value = 0.1393
bartlett.test(WeeklyLab4Data$LifeinHours,WeeklyLab4Data$Formulation)
##
## Bartlett test of homogeneity of variances
##
## data: WeeklyLab4Data$LifeinHours and WeeklyLab4Data$Formulation
## Bartlett's K-squared = 0.7178, df = 1, p-value = 0.3969
model <- aov(LifeinHours ~ Machine +
Formulation*StorageTemperature*RunningTemperature, data =
WeeklyLab4Data)
summary(model)
## Df Sum Sq Mean Sq
## Machine 2 64.0 32.0
## Formulation 1 363.0 363.0
## StorageTemperature 2 585.5 292.7
## RunningTemperature 2 770.3 385.1
## Formulation:StorageTemperature 2 4.6 2.3
## Formulation:RunningTemperature 2 7.1 3.6
## StorageTemperature:RunningTemperature 4 201.6 50.4
## Formulation:StorageTemperature:RunningTemperature 4 1.0 0.2
## Residuals 34 474.6 14.0
## F value Pr(>F)
## Machine 2.294 0.1163
## Formulation 26.001 1.28e-05 ***
## StorageTemperature 20.970 1.17e-06 ***
## RunningTemperature 27.589 7.60e-08 ***
## Formulation:StorageTemperature 0.164 0.8490
## Formulation:RunningTemperature 0.256 0.7756
## StorageTemperature:RunningTemperature 3.611 0.0148 *
## Formulation:StorageTemperature:RunningTemperature 0.017 0.9994
## Residuals
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tapply(WeeklyLab4Data$LifeinHours, WeeklyLab4Data$Formulation, mean)
## F1 F2
## 27.48148 32.66667
TukeyHSD(model, c("StorageTemperature", "RunningTemperature"))
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = LifeinHours ~ Machine + Formulation * StorageTemperature * RunningTemperature, data = WeeklyLab4Data)
##
## $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
##
## $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
library(lsmeans)
## Warning: package 'lsmeans' was built under R version 3.4.4
## The 'lsmeans' package is being deprecated.
## Users are encouraged to switch to 'emmeans'.
## See help('transition') for more information, including how
## to convert 'lsmeans' objects and scripts to work with 'emmeans'.
WeeklyLab4Data$RunningTemperature <- factor(WeeklyLab4Data$RunningTemperature, levels = c("low", "med",
"high") )
WeeklyLab4Data$StorageTemperature <- factor(WeeklyLab4Data$StorageTemperature, levels = c("low", "med",
"high") )
TukeyHSD(model, "StorageTemperature:RunningTemperature")
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = LifeinHours ~ Machine + Formulation * StorageTemperature * RunningTemperature, data = WeeklyLab4Data)
##
## $`StorageTemperature:RunningTemperature`
## diff lwr upr p adj
## low:high-high:high 5.0000000 -2.1378038 12.1378038 0.3600327
## med:high-high:high 2.6666667 -4.4711372 9.8044705 0.9422793
## high:low-high:high 5.8333333 -1.3044705 12.9711372 0.1841865
## low:low-high:high 18.8333333 11.6955295 25.9711372 0.0000000
## med:low-high:high 10.3333333 3.1955295 17.4711372 0.0009592
## high:med-high:high 4.0000000 -3.1378038 11.1378038 0.6475577
## low:med-high:high 10.0000000 2.8621962 17.1378038 0.0014913
## med:med-high:high 11.5000000 4.3621962 18.6378038 0.0001998
## med:high-low:high -2.3333333 -9.4711372 4.8044705 0.9730950
## high:low-low:high 0.8333333 -6.3044705 7.9711372 0.9999817
## low:low-low:high 13.8333333 6.6955295 20.9711372 0.0000083
## med:low-low:high 5.3333333 -1.8044705 12.4711372 0.2803362
## high:med-low:high -1.0000000 -8.1378038 6.1378038 0.9999261
## low:med-low:high 5.0000000 -2.1378038 12.1378038 0.3600327
## med:med-low:high 6.5000000 -0.6378038 13.6378038 0.0977980
## high:low-med:high 3.1666667 -3.9711372 10.3044705 0.8621541
## low:low-med:high 16.1666667 9.0288628 23.3044705 0.0000004
## med:low-med:high 7.6666667 0.5288628 14.8044705 0.0275519
## high:med-med:high 1.3333333 -5.8044705 8.4711372 0.9993722
## low:med-med:high 7.3333333 0.1955295 14.4711372 0.0402654
## med:med-med:high 8.8333333 1.6955295 15.9711372 0.0067147
## low:low-high:low 13.0000000 5.8621962 20.1378038 0.0000259
## med:low-high:low 4.5000000 -2.6378038 11.6378038 0.4986512
## high:med-high:low -1.8333333 -8.9711372 5.3044705 0.9941701
## low:med-high:low 4.1666667 -2.9711372 11.3044705 0.5979620
## med:med-high:low 5.6666667 -1.4711372 12.8044705 0.2130636
## med:low-low:low -8.5000000 -15.6378038 -1.3621962 0.0101667
## high:med-low:low -14.8333333 -21.9711372 -7.6955295 0.0000021
## low:med-low:low -8.8333333 -15.9711372 -1.6955295 0.0067147
## med:med-low:low -7.3333333 -14.4711372 -0.1955295 0.0402654
## high:med-med:low -6.3333333 -13.4711372 0.8044705 0.1153824
## low:med-med:low -0.3333333 -7.4711372 6.8044705 1.0000000
## med:med-med:low 1.1666667 -5.9711372 8.3044705 0.9997649
## low:med-high:med 6.0000000 -1.1378038 13.1378038 0.1583827
## med:med-high:med 7.5000000 0.3621962 14.6378038 0.0333593
## med:med-low:med 1.5000000 -5.6378038 8.6378038 0.9985376
pairwise.t.test(WeeklyLab4Data$LifeinHours,
WeeklyLab4Data$StorageTemperature:WeeklyLab4Data$RunningTemperature,
p.adj ="none" )
##
## Pairwise comparisons using t tests with pooled SD
##
## data: WeeklyLab4Data$LifeinHours and WeeklyLab4Data$StorageTemperature:WeeklyLab4Data$RunningTemperature
##
## low:low low:med low:high med:low med:med med:high high:low
## low:med 0.00145 - - - - - -
## low:high 3.2e-06 0.06105 - - - - -
## med:low 0.00209 0.89865 0.04629 - - - -
## med:med 0.00716 0.56723 0.01623 0.65609 - - -
## med:high 1.5e-07 0.00716 0.37471 0.00508 0.00145 - -
## high:low 9.3e-06 0.11636 0.75029 0.09064 0.03473 0.23003 -
## high:med 8.7e-07 0.02580 0.70260 0.01898 0.00604 0.61092 0.48478
## high:high 4.5e-09 0.00038 0.06105 0.00026 6.2e-05 0.31100 0.02997
## high:med
## low:med -
## low:high -
## med:low -
## med:med -
## med:high -
## high:low -
## high:med -
## high:high 0.13129
##
## P value adjustment method: none
aggregate(LifeinHours ~ RunningTemperature + StorageTemperature,
data = WeeklyLab4Data, FUN = "mean")
## RunningTemperature StorageTemperature LifeinHours
## 1 low low 41.33333
## 2 med low 32.50000
## 3 high low 27.50000
## 4 low med 32.83333
## 5 med med 34.00000
## 6 high med 25.16667
## 7 low high 28.33333
## 8 med high 26.50000
## 9 high high 22.50000