lsmip {lsmeans} | R Documentation

## Least-squares (predicted marginal) means interaction plot

### Description

This function creates an interaction plot of the least-squares means based on a fitted model and a simple formula specification.

### Usage

    ## Default S3 method:
    lsmip(object, formula, type,
        pch = c(1,2,6,7,9,10,15:20),
        lty = 1, col = NULL, plotit = TRUE, ...)

    pmmip(...)

### Arguments

`object` | An object of class `lsmobj`, or a fitted model of a class supported by `lsmeans`.
`formula` | 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.
`type` | 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`.
`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` | If `TRUE`, the plot is displayed. Otherwise, one may use the `"lattice"` attribute of the returned object and print it, perhaps after additional manipulation.
`...` | Additional arguments passed to `lsmeans` or to `xyplot`.

### Details

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’.

### Value

(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.

### Note

This function uses the `xyplot` function in the `lattice` package (an error is returned if `lattice` is not installed). Conceptually, it is equivalent to `interaction.plot` where the summarization function is the least-squares means.

### Author(s)

Russell V. Lenth

### See Also

`interaction.plot`

### Examples

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

[Package lsmeans version 2.27-62 Index]