Learn R Programming

emmeans (version 1.3.2)

emmip: Interaction-style plots for estimated marginal means

Description

Creates an interaction plot of EMMs based on a fitted model and a simple formula specification.

Usage

emmip(object, formula, ...)

# S3 method for default emmip(object, formula, type, CIs = FALSE, engine = get_emm_option("graphics.engine"), pch = c(1, 2, 6, 7, 9, 10, 15:20), lty = 1, col = NULL, plotit = TRUE, ...)

Arguments

object

An object of class emmGrid, or a fitted model of a class supported by the emmeans package

formula

Formula of the form trace.factors ~ x.factors | by.factors. The EMMs are plotted against x.factor for each level of trace.factors. by.factors is optional, but if present, it determines separate panels. Each element of this formula may be a single factor in the model, or a combination of factors using the * operator.

...

Additional arguments passed to emmeans (when object is not already an emmGrid object), ggplot, or xyplot.

type

As in predict.emmGrid, this determines whether we want to inverse-transform the predictions (type = "response") or not (any other choice). The default is "link", unless the "predict.type" option is in force; see emm_options.

CIs

Logical value. If TRUE, confidence intervals (or HPD intervals for Bayesian models) are added to the plot (works only with engine = "ggplot").

engine

Character value matching "ggplot" (default) or "lattice". The graphics engine to be used to produce the plot. These require, respectively, the ggplot2 or lattice package to be installed.

pch

The plotting characters to use for each group (i.e., levels of trace.factors). They are recycled as needed.

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.

plotit

Logical value. If TRUE, the plot is displayed. Otherwise, one may use the "lattice" attribute of the returned object and print it, perhaps after additional manipulation.

Value

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.

Details

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.

See Also

emmeans, interaction.plot

Examples

Run this code
# NOT RUN {
#--- 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
emmip(noise.lm, type ~ side * size, CIs = TRUE)

# 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)

# }

Run the code above in your browser using DataLab