Interaction-style plots for estimated marginal means
Creates an interaction plot of EMMs based on a fitted model and a simple formula specification.
emmip(object, formula, ...) ## Default S3 method: emmip(object, formula, type, CIs = FALSE, PIs = FALSE, style, engine = get_emm_option("graphics.engine"), plotit = TRUE, nesting.order = FALSE, ...) emmip_ggplot(emms, style = "factor", dodge = 0.1, xlab = labs$xlab, ylab = labs$ylab, tlab = labs$tlab, facetlab = "label_context", dotarg = list(), linearg = list(), CIarg = list(lwd = 2, alpha = 0.5), PIarg = list(lwd = 1.25, alpha = 0.33), ...) emmip_lattice(emms, style = "factor", xlab = labs$xlab, ylab = labs$ylab, tlab = labs$tlab, pch = c(1, 2, 6, 7, 9, 10, 15:20), lty = 1, col = NULL, ...)
object |
An object of class |
formula |
Formula of the form
|
... |
Additional arguments passed to |
type |
As in |
CIs |
Logical value. If |
PIs |
Logical value. If |
style |
Optional character value. This has an effect only when the
horizontal variable is a single numeric variable. If |
engine |
Character value matching |
plotit |
Logical value. If |
nesting.order |
Logical value. If |
emms |
A |
dodge |
Numerical amount passed to |
xlab, ylab, tlab |
Character labels for the horizontal axis, vertical
axis, and traces (the different curves), respectively. The |
facetlab |
Labeller for facets (when by variables are in play).
Use |
dotarg |
|
linearg |
|
CIarg, PIarg |
|
pch |
The plotting characters to use for each group (i.e., levels of
|
lty |
The line types to use for each group. Recycled as needed. |
col |
The colors to use for each group, recycled as needed. If not specified, the default trellis colors are used. |
If plotit = FALSE
, a data.frame
(actually, a
summary_emm
object) with the table of EMMs that would be plotted.
The variables plotted are named xvar
and yvar
, and the trace
factor is named tvar
. This data frame has an added "labs"
attribute containing the labels xlab
, ylab
, and tlab
for these respective variables. The confidence limits are also
included, renamed LCL
and UCL
.
If plotit = TRUE
, the function
returns an object of class "ggplot"
or a "trellis"
, depending
on engine
.
If object
is a fitted model, emmeans
is called with an
appropriate specification to obtain estimated marginal means for each
combination of the factors present in formula
(in addition, any
arguments in ...
that match at
, trend
,
cov.reduce
, or fac.reduce
are passed to emmeans
).
Otherwise, if object
is an emmGrid
object, its first element is
used, and it must contain one estimate for each combination of the factors
present in formula
.
The functions emmip_ggplot
and emmip_lattice
are called when plotit == TRUE
to render the plots;
but they may also be called later on an object saved via plotit = FALSE
(or engine = "none"
). The functions require that emms
contains variables
xvar
, yvar
, and tvar
, and attributes "labs"
and "vars"
.
Confidence intervals are plotted if variables LCL
and UCL
exist;
and prediction intervals are plotted if LPL
and UPL
exist.
Finally, it must contain the variables named in attr(emms, "vars")
.
Conceptually, this function is equivalent to
interaction.plot
where the summarization function is thought
to return the EMMs.
#--- Three-factor example noise.lm = lm(noise ~ size * type * side, data = auto.noise) # Separate interaction plots of size by type, for each side emmip(noise.lm, type ~ size | side) # One interaction plot, using combinations of size and side as the x factor # ... with added confidence intervals and some formatting changes emmip(noise.lm, type ~ side * size, CIs = TRUE, linearg = list(linetype = "dashed"), CIarg = list(lwd = 1, alpha = 1)) # One interaction plot using combinations of type and side as the trace factor emmip(noise.lm, type * side ~ size) # Individual traces in panels emmip(noise.lm, ~ size | type * side) # Example for the 'style' argument fib.lm = lm(strength ~ machine * sqrt(diameter), data = fiber) fib.rg = ref_grid(fib.lm, at = list(diameter = c(3.5, 4, 4.5, 5, 5.5, 6)^2)) emmip(fib.rg, machine ~ diameter) # curves (because diameter is numeric) emmip(fib.rg, machine ~ diameter, style = "factor") # points and lines # For an example using extra ggplot2 code, see 'vignette("messy-data")', # in the section on nested models.
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.