## Fit a two-way ANOVA to the arousal data in arousal.df.
## The factors are gender (female, male) and picture shown to
## subject (infant, landscape, nude.f, nude.m):
data(arousal.df)
arousal.fit = lm(arousal ~ gender * picture, data = arousal.df)
## Create all pairwise comparisons using emmeans, if available.
if (requireNamespace("emmeans", quietly = TRUE)) {
emmeansFun = getExportedValue("emmeans", "emmeans")
arousal.allpairs = pairs(
emmeansFun(arousal.fit, ~ gender * picture),
infer = TRUE
)
## Display only the within-level comparisons:
displayPairs(
arousal.allpairs,
levels1 = c("female", "male"),
levels2 = c("infant", "landscape", "nude.f", "nude.m")
)
}
Run the code above in your browser using DataLab