
This function creates an interaction plot of the least-squares means based on a fitted model and a simple formula specification.
# S3 method for default
lsmip(object, formula, type,
pch = c(1,2,6,7,9,10,15:20),
lty = 1, col = NULL, plotit = TRUE, ...)
pmmip(...)
An object of class lsmobj
, or a fitted model of a class supported by lsmeans
.
Formula of the form trace.factors ~ x.factors | by.factors
. The least-squares means 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.
As in predict
, 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 lsm.options
.
The plotting characters to use for each group (i.e., levels of trace.factors
). They are recycled as needed.
The line types to use for each group. Recycled as needed.
The colors to use for each group, recycled as needed. If not specified, the default trellis colors are used.
If TRUE
, the plot is displayed. Otherwise, one may use the "lattice"
attribute of the returned object and print it, perhaps after additional manipulation.
(Invisibly), a data.frame
with the table of least-squares means that were plotted, with an additional "lattice"
attribute containing the trellis
object for the plot.
If object
is a fitted model, lsmeans
is called with an appropriate specification to obtain least-squares 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 lsmeans
).
Otherwise, if object
is an lsmobj
object, its first element is used, and it must contain one lsmean
value for each combination of the factors present in formula
.
The wrapper pmmip
is provided for those who prefer the term ‘predicted marginal means’.
# NOT RUN {
require(lsmeans)
require(lattice)
#--- Two-factor example
warp.lm <- lm(breaks ~ wool * tension, data = warpbreaks)
# Following plot is the same as the usual interaction plot of the data
lsmip(warp.lm, wool ~ tension)
#--- Three-factor example
noise.lm = lm(noise ~ size * type * side, data = auto.noise)
# Separate interaction plots of size by type, for each side
lsmip(noise.lm, type ~ size | side)
# One interaction plot, using combinations of size and side as the x factor
lsmip(noise.lm, type ~ side * size)
# One interaction plot using combinations of type and side as the trace factor
# customize the colors, line types, and symbols to suggest these combinations
lsmip(noise.lm, type * side ~ size, lty=1:2, col=1:2, pch=c(1,1,2,2))
# 3-way interaction is significant, but doesn't make a lot of visual difference...
noise.lm2 = update(noise.lm, . ~ . - size:type:side)
lsmip(noise.lm2, type * side ~ size, lty=1:2, col=1:2, pch=c(1,1,2,2))
# }
Run the code above in your browser using DataLab