Recall that when the interaction effect is significant, the effect of one factor is dependent on the other factor
When the interaction effect is significant, the main effects are no longer sensible
Thus, in the presence of significant interaction effect, we do post hoc test of the levels of one factor at each (fixed) level of the other factor
For example, we can compare the additives (c1, c2, c, c4, c5) for each base polymer, say Mylar; (separately) repeat this for Nylon and Polyetheylene
f2rbd <- read.csv("two_factorial_rcbd.csv")
mod1 <- aov(TS ~ Day + A + B + A:B,
data = f2rbd)
knitr::kable(anova(mod1))
Df | Sum Sq | Mean Sq | F value | Pr(>F) | |
---|---|---|---|---|---|
Day | 2 | 18.576444 | 9.2882222 | 11.848182 | 0.0001870 |
A | 4 | 6.325778 | 1.5814444 | 2.017312 | 0.1192491 |
B | 2 | 10.145778 | 5.0728889 | 6.471046 | 0.0048959 |
A:B | 8 | 33.100889 | 4.1376111 | 5.277993 | 0.0004341 |
Residuals | 28 | 21.950222 | 0.7839365 | NA | NA |
emmeans::emmip(mod1, A ~ B,
xlab = "Polymers",
ylab = "Mean Tensile Strength",
tlab = "Additives")
f2rbd %>%
group_by(B, A) %>%
summarize(meanTS = round(mean(TS),2)) %>%
knitr::kable()
B | A | meanTS |
---|---|---|
Mylar | c1 | 8.60 |
Mylar | c2 | 8.57 |
Mylar | c3 | 8.87 |
Mylar | c4 | 10.80 |
Mylar | c5 | 9.97 |
Nylon | c1 | 7.60 |
Nylon | c2 | 7.73 |
Nylon | c3 | 9.73 |
Nylon | c4 | 7.87 |
Nylon | c5 | 8.73 |
Peth | c1 | 8.60 |
Peth | c2 | 11.47 |
Peth | c3 | 9.20 |
Peth | c4 | 8.77 |
Peth | c5 | 8.57 |
We can use the emmeans() function in the emmeans package to perform post hoc analysis when interaction effect is signficant. A sample code chunck is given below.
emmeans(mod1, list(pairwise ~ A | B),
adjust = "tukey",
lmer.df = "satterthwaite")
## $`emmeans of A | B`
## B = Mylar:
## A emmean SE df lower.CL upper.CL
## c1 8.60 0.511 28 7.55 9.65
## c2 8.57 0.511 28 7.52 9.61
## c3 8.87 0.511 28 7.82 9.91
## c4 10.80 0.511 28 9.75 11.85
## c5 9.97 0.511 28 8.92 11.01
##
## B = Nylon:
## A emmean SE df lower.CL upper.CL
## c1 7.60 0.511 28 6.55 8.65
## c2 7.73 0.511 28 6.69 8.78
## c3 9.73 0.511 28 8.69 10.78
## c4 7.87 0.511 28 6.82 8.91
## c5 8.73 0.511 28 7.69 9.78
##
## B = Peth:
## A emmean SE df lower.CL upper.CL
## c1 8.60 0.511 28 7.55 9.65
## c2 11.47 0.511 28 10.42 12.51
## c3 9.20 0.511 28 8.15 10.25
## c4 8.77 0.511 28 7.72 9.81
## c5 8.57 0.511 28 7.52 9.61
##
## Results are averaged over the levels of: Day
## Confidence level used: 0.95
##
## $`pairwise differences of A | B`
## B = Mylar:
## 2 estimate SE df t.ratio p.value
## c1 - c2 0.0333 0.723 28 0.046 1.0000
## c1 - c3 -0.2667 0.723 28 -0.369 0.9958
## c1 - c4 -2.2000 0.723 28 -3.043 0.0373
## c1 - c5 -1.3667 0.723 28 -1.890 0.3455
## c2 - c3 -0.3000 0.723 28 -0.415 0.9934
## c2 - c4 -2.2333 0.723 28 -3.089 0.0336
## c2 - c5 -1.4000 0.723 28 -1.937 0.3223
## c3 - c4 -1.9333 0.723 28 -2.674 0.0837
## c3 - c5 -1.1000 0.723 28 -1.522 0.5577
## c4 - c5 0.8333 0.723 28 1.153 0.7773
##
## B = Nylon:
## 2 estimate SE df t.ratio p.value
## c1 - c2 -0.1333 0.723 28 -0.184 0.9997
## c1 - c3 -2.1333 0.723 28 -2.951 0.0460
## c1 - c4 -0.2667 0.723 28 -0.369 0.9958
## c1 - c5 -1.1333 0.723 28 -1.568 0.5293
## c2 - c3 -2.0000 0.723 28 -2.767 0.0689
## c2 - c4 -0.1333 0.723 28 -0.184 0.9997
## c2 - c5 -1.0000 0.723 28 -1.383 0.6430
## c3 - c4 1.8667 0.723 28 2.582 0.1013
## c3 - c5 1.0000 0.723 28 1.383 0.6430
## c4 - c5 -0.8667 0.723 28 -1.199 0.7520
##
## B = Peth:
## 2 estimate SE df t.ratio p.value
## c1 - c2 -2.8667 0.723 28 -3.965 0.0039
## c1 - c3 -0.6000 0.723 28 -0.830 0.9190
## c1 - c4 -0.1667 0.723 28 -0.231 0.9993
## c1 - c5 0.0333 0.723 28 0.046 1.0000
## c2 - c3 2.2667 0.723 28 3.135 0.0302
## c2 - c4 2.7000 0.723 28 3.735 0.0070
## c2 - c5 2.9000 0.723 28 4.011 0.0035
## c3 - c4 0.4333 0.723 28 0.599 0.9740
## c3 - c5 0.6333 0.723 28 0.876 0.9033
## c4 - c5 0.2000 0.723 28 0.277 0.9986
##
## Results are averaged over the levels of: Day
## P value adjustment: tukey method for comparing a family of 5 estimates
We can manually assign the letter designations, based on the above results.
But we can use the cld() function in the multcomp package to make letter assignments automatic. This is illustrated in the code chunk below.
emm <- emmeans(mod1, list(pairwise ~ A | B),
adjust = "tukey",
lmer.df = "satterthwaite")
cld(emm,
alpha=0.05,
Letters=letters,
adjust="tukey",
reversed = T)
## B = Mylar:
## A emmean SE df lower.CL upper.CL .group
## c4 10.80 0.511 28 9.39 12.21 a
## c5 9.97 0.511 28 8.56 11.37 ab
## c3 8.87 0.511 28 7.46 10.27 ab
## c1 8.60 0.511 28 7.19 10.01 b
## c2 8.57 0.511 28 7.16 9.97 b
##
## B = Nylon:
## A emmean SE df lower.CL upper.CL .group
## c3 9.73 0.511 28 8.33 11.14 a
## c5 8.73 0.511 28 7.33 10.14 ab
## c4 7.87 0.511 28 6.46 9.27 ab
## c2 7.73 0.511 28 6.33 9.14 ab
## c1 7.60 0.511 28 6.19 9.01 b
##
## B = Peth:
## A emmean SE df lower.CL upper.CL .group
## c2 11.47 0.511 28 10.06 12.87 a
## c3 9.20 0.511 28 7.79 10.61 b
## c4 8.77 0.511 28 7.36 10.17 b
## c1 8.60 0.511 28 7.19 10.01 b
## c5 8.57 0.511 28 7.16 9.97 b
##
## Results are averaged over the levels of: Day
## Confidence level used: 0.95
## Conf-level adjustment: sidak method for 5 estimates
## P value adjustment: tukey method for comparing a family of 5 estimates
## significance level used: alpha = 0.05
## NOTE: If two or more means share the same grouping symbol,
## then we cannot show them to be different.
## But we also did not show them to be the same.
Alternatively, a very flexible and quite comprehensive package for analysis of experiments is the ExpDes package. For example, the code chunck below does just what we did earlier using emmeans() and cld().
with(f2rbd, fat2.rbd(factor1 = A,
factor2 = B,
block = Day,
resp = TS,
quali = c(TRUE, TRUE),
mcomp = "tukey",
fac.names = c("Additives","Polymers")))
## ------------------------------------------------------------------------
## Legend:
## FACTOR 1: Additives
## FACTOR 2: Polymers
## ------------------------------------------------------------------------
##
##
## Analysis of Variance Table
## ------------------------------------------------------------------------
## DF SS MS Fc Pr>Fc
## Block 2 18.576 6 11.8482 0.000187
## Additives 4 6.326 3 2.0173 0.119249
## Polymers 2 10.146 5 6.4710 0.004896
## Additives*Polymers 8 33.101 4 5.2780 0.000434
## Residuals 28 21.950 2
## Total 44 90.099 1
## ------------------------------------------------------------------------
## CV = 9.83 %
##
## ------------------------------------------------------------------------
## Shapiro-Wilk normality test
## p-value: 0.09840045
## According to Shapiro-Wilk normality test at 5% of significance, residuals can be considered normal.
## ------------------------------------------------------------------------
##
##
##
## Significant interaction: analyzing the interaction
## ------------------------------------------------------------------------
##
## Analyzing Additives inside of each level of Polymers
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
## DF SS MS Fc Pr.Fc
## Block 2 18.57644 9.28822 11.8482 2e-04
## Polymers 2 10.14578 5.07289 6.471 0.0049
## Additives:Polymers Mylar 4 11.67600 2.919 3.7235 0.0149
## Additives:Polymers Nylon 4 9.70667 2.42667 3.0955 0.0314
## Additives:Polymers Peth 4 18.04400 4.511 5.7543 0.0016
## Residuals 28 21.95022 0.78394
## Total 44 90.09911
## ------------------------------------------------------------------------
##
##
##
## Additives inside of the level Mylar of Polymers
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a c4 10.8
## ab c5 9.966667
## ab c3 8.866667
## b c1 8.6
## b c2 8.566667
## ------------------------------------------------------------------------
##
##
## Additives inside of the level Nylon of Polymers
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a c3 9.733333
## ab c5 8.733333
## ab c4 7.866667
## ab c2 7.733333
## b c1 7.6
## ------------------------------------------------------------------------
##
##
## Additives inside of the level Peth of Polymers
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a c2 11.46667
## b c3 9.2
## b c4 8.766667
## b c1 8.6
## b c5 8.566667
## ------------------------------------------------------------------------
##
##
##
## Analyzing Polymers inside of each level of Additives
## ------------------------------------------------------------------------
## ------------------------------------------------------------------------
## Analysis of Variance Table
## ------------------------------------------------------------------------
## DF SS MS Fc Pr.Fc
## Block 2 18.57644 9.28822 11.8482 2e-04
## Additives 4 6.32578 1.58144 2.0173 0.1192
## Polymers:Additives c1 2 2.00000 1 1.2756 0.295
## Polymers:Additives c2 2 23.04222 11.52111 14.6965 0
## Polymers:Additives c3 2 1.14667 0.57333 0.7314 0.4902
## Polymers:Additives c4 2 13.54889 6.77444 8.6416 0.0012
## Polymers:Additives c5 2 3.50889 1.75444 2.238 0.1254
## Residuals 28 21.95022 0.78394
## Total 44 90.09911
## ------------------------------------------------------------------------
##
##
##
## Polymers inside of the level c1 of Additives
##
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
## Levels Means
## 1 Mylar 8.6
## 2 Nylon 7.6
## 3 Peth 8.6
## ------------------------------------------------------------------------
##
##
## Polymers inside of the level c2 of Additives
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a Peth 11.46667
## b Mylar 8.566667
## b Nylon 7.733333
## ------------------------------------------------------------------------
##
##
## Polymers inside of the level c3 of Additives
##
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
## Levels Means
## 1 Mylar 8.866667
## 2 Nylon 9.733333
## 3 Peth 9.200000
## ------------------------------------------------------------------------
##
##
## Polymers inside of the level c4 of Additives
## ------------------------------------------------------------------------
## Tukey's test
## ------------------------------------------------------------------------
## Groups Treatments Means
## a Mylar 10.8
## b Peth 8.766667
## b Nylon 7.866667
## ------------------------------------------------------------------------
##
##
## Polymers inside of the level c5 of Additives
##
## According to the F test, the means of this factor are statistical equal.
## ------------------------------------------------------------------------
## Levels Means
## 1 Mylar 9.966667
## 2 Nylon 8.733333
## 3 Peth 8.566667
## ------------------------------------------------------------------------