# NOT RUN {
warp.lm <- lm(breaks ~ wool*tension, data = warpbreaks)
warp.emm <- emmeans(warp.lm, ~ tension | wool)
contrast(warp.emm, "poly") # inherits 'by = "wool"' from warp.emm
pairs(warp.emm) # ditto
contrast(warp.emm, "eff", by = NULL) # contrasts of the 6 factor combs
pairs(warp.emm, simple = "wool") # same as pairs(warp.emm, by = "tension")
# Do all "simple" comparisons, combined into one family
pairs(warp.emm, simple = "each", combine = TRUE)
# }
# NOT RUN {
## Note that the following are NOT the same:
contrast(warp.emm, simple = c("wool", "tension"))
contrast(warp.emm, simple = list("wool", "tension"))
## The first generates contrasts for combinations of wool and tension
## (same as by = NULL)
## The second generates contrasts for wool by tension, and for
## tension by wool, respectively.
# }
# NOT RUN {
# An interaction contrast for tension:wool
tw.emm <- contrast(warp.emm, interaction = c(tension = "poly", wool = "consec"),
by = NULL)
tw.emm # see the estimates
coef(tw.emm) # see the contrast coefficients
# Use of scale and offset
# an unusual use of the famous stack-loss data...
mod <- lm(Water.Temp ~ poly(stack.loss, degree = 2), data = stackloss)
(emm <- emmeans(mod, "stack.loss", at = list(stack.loss = 10 * (1:4))))
# Convert results from Celsius to Fahrenheit:
confint(contrast(emm, "identity", scale = 9/5, offset = 32))
# }
Run the code above in your browser using DataLab