plotmo (version 3.0.0)

plotmo: Plot a model's response over a range of predictor values

Description

Plot a model's response when varying one or two predictors while holding the other predictors constant. A poor man's partial dependence plot.

See the ../doc/plotmo-notes.pdf{plotmo} vignette.

Usage

plotmo(object=stop("no 'object' argument"),
    type=NULL, nresponse=NA,
    pt.col=0, jitter=NULL, smooth.col=0, level=0,
    func=NULL, inverse.func=NULL, nrug=0, grid.col=0,
    type2="persp",
    degree1=TRUE, all1=FALSE, degree2=TRUE, all2=FALSE,
    do.par=TRUE, clip=TRUE, ylim=NULL, caption=NULL, trace=0,
    grid.func=median, grid.levels=NULL, extend=0,
    ngrid1=50, ngrid2=20, ndiscrete=5, npoints=3000,
    center=FALSE, xflip=FALSE, yflip=FALSE, swapxy=FALSE, int.only.ok=TRUE,
    ...)

Arguments

object
The model object.
type
Type parameter passed to predict. For allowed values see the predict method for your object (such as predict.earth). By
nresponse
Which column to use when predict returns multiple columns. This can be a column index or column name (which may be abbreviated, partial matching is used).
pt.col
The color of response points (or response sites in degree2 plots). This refers to the response y in the data used to build the model. Note that the displayed points are jittered (see the jitter argument). Default is 0
jitter
Applies only if pt.col is specified. The default is jitter=NULL, meaning automatically jitter the points. Points are jittered horizontally and vertically. Use jitter=0 to disable this automatic jittering. Otherwise s
smooth.col
Color of smooth line through the response points. (The points themselves will not be plotted unless pt.col is specified.) Default is 0, no smooth line. Example:mod <- lm(Volume~Height, data=trees) plotmo(mod, pt.color=1, smo
level
Draw estimated confidence or prediction interval bands at the given level, if the predict method for the model supports them. Default is 0, bands not plotted. Else a fraction, for example level=.95. See P
func
Superimpose func(x) on the plot. Example:mod <- lm(Volume~Girth, data=trees) estimated.volume <- function(x) .17 * x$Girth^2 plotmo(mod, pt.col=2, func=estimated.volume) The func is called for each plot with a single argu
inverse.func
A function applied to the response before plotting. Useful to transform a transformed response back to the original scale. Example:mod <- lm(log(Volume)~., data=trees) plotmo(mod, inverse.func=exp) # exp() is inverse of log()
nrug
Number of points in the rug rug along the bottom of the plot (a sample of nrug points is plotted). Default is 0, no rug. Use nrug=TRUE or -1 for all p
grid.col
Default is 0, no grid. Else add a background grid of the specified color to the degree1 plots. The special value grid.col=TRUE is treated as "lightgray".
type2
Degree2 plot type. One of "persp" (default), "image", or "contour". You can pass argumen
degree1
An index vector specifying which subset of degree1 (main effect) plots to include (after selecting the relevant predictors as described in Which variables are plotted? in the plotmo vignette). Default is TRUE<
all1
Default is FALSE. Use TRUE to plot all predictors, not just those usually selected by plotmo. The all1 argument increases the number of plots; the degree1 argument reduces the number of plo
degree2
An index vector specifying which subset of degree2 (interaction) plots to include. Default is TRUE meaning all (after selecting the relevant interaction terms as described in Which variables are plotted? in the
all2
Default is FALSE. Use TRUE to plot all pairs of predictors, not just those usually selected by plotmo.
do.par
One of NULL, FALSE, TRUE, or 2, as follows:

do.par=NULL. Same as do.par=FALSE if the number of plots is one; else the same as TRUE.

do.par=FALSE. Use

clip
The default is clip=TRUE, meaning ignore very outlying predictions when determining the automatic ylim. This keeps ylim fairly compact while still covering all or nearly all the data, even if there are a few crazy p
ylim
Three possibilities: ylim=NULL (default). Automatically determine a ylim to use across all graphs. ylim=NA. Each graph has its own ylim. ylim=c(ymin,ymax). Use the specified limits.
caption
Overall caption. By default create the caption automatically. Use caption="" for no caption. (Use main to set the title of individual plots, can be a vector.)
trace
Default is 0. trace=1 (or TRUE) for a summary trace (shows how predict is invoked for the current object). trace=2 for detailed tracing. tra
grid.func
Function applied to columns of the x matrix to pin the values of variables not on the axes. Default is median. This argument is not related to the grid.col argument. Examples:p
grid.levels
Default is NULL. Else a list of variables and their fixed value to be used when the variable is not on the axis. Supersedes grid.func for variables in the list. Names and values can be abbreviated, partial matching is used. Examp
extend
Amount to extend the horizontal axis in each plot. The default is 0, do not extend (i.e. use the range of the variable in the training data). Else something like extend=.5, which will extend both the lower and upper xlim
ngrid1
Number of equally spaced x values in each degree1 plot. Default is 50.
ngrid2
Grid size for degree2 plots (ngrid2 x ngrid2 points are plotted). Default is 20. The default will sometimes be too small for contour and image plots. With large ngrid2 values, persp<
npoints
Number of response points to be plotted (a sample of npoints points is plotted). Applies only if pt.col is specified. The default is 3000 (not all, to avoid overplotting on large models). Use npoints=TRUE or -
ndiscrete
Default 5 (a somewhat arbitrary value). Variables with no more than ndiscrete unique values are plotted as quantized in plots (a staircase rather than a curve). Factors are always considered discrete.
int.only.ok
Plot the model even if it is an intercept-only model. Do this by plotting a single degree1 plot for the first predictor. The default is TRUE. Use int.only.ok=FALSE to instead issue an error message for intercept-only models.
center
Center the plotted response. Default is FALSE.
xflip
Default FALSE. Use TRUE to flip the direction of the x axis. This argument (and yflip and swapxy) is useful when comparing to a plot from another source and you want the axes to be the same.
yflip
Default FALSE. Use TRUE to flip the direction of the y axis of the degree2 graphs.
swapxy
Default FALSE. Use TRUE to swap the x and y axes on the degree2 graphs.
...
Dot arguments are passed to the predict and plot functions. Dot argument names, whether prefixed or not, should be specified in full and not abbreviated. Prefixed arguments are passed directly to the associated function. For example the

concept

partial dependence plot

See Also

Please see the ../doc/plotmo-notes.pdf{plotmo} vignette.

There is a brief section on plotmo in the rpart.plot vignette http://www.milbo.org/rpart-plot/prp.pdf{Plotting rpart trees with prp}.

Examples

Run this code
if (require(rpart)) {
    data(kyphosis)
    rpart.model <- rpart(Kyphosis~., data=kyphosis)
    plotmo(rpart.model, type="prob", nresponse="present")
}
if (require(earth)) {
    data(ozone1)
    earth.model <- earth(O3 ~ ., data=ozone1, degree=2)
    plotmo(earth.model)
}

Run the code above in your browser using DataCamp Workspace