plotmo (version 2.2.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 package vignette ../doc/plotmo-notes.pdf{Notes on the plotmo package}.

Usage

plotmo(object = stop("no 'object' arg"),
       type=NULL, nresponse = NA, clip = TRUE, ylim = NULL,
       center = FALSE, ndiscrete = 5,
       degree1 = TRUE, all1=FALSE, degree2 = TRUE, all2=FALSE, int.only.ok = TRUE,
       grid.func = median, grid.levels = NULL,
       col.response = 0, cex.response = NULL, pch.response = 20,
       jitter.response=0, npoints = -1, inverse.func = NULL,
       level = 0, shade.pints = "mistyrose2", shade2.pints = "mistyrose4",
       trace = 0,
       nrug = 0, col.degree1 = 1, lty.degree1 = 1, lwd.degree1 = 1,
       col.smooth = 0, lty.smooth = 1, lwd.smooth = 1, smooth.f = .5,
       func = NULL, col.func = "lightblue", lty.func = 1, lwd.func = 1,
       ngrid1 = 50,  grid = FALSE,
       type2 = "persp", ngrid2 = 20,
       col.image = gray(0:10/10), col.persp = "lightblue",
       theta = NA, phi = 30, dvalue = 1, shade = 0.5,
       do.par = TRUE, caption = NULL, main = NULL,
       xlim = NULL, xlab = "", ylab = "", cex = NULL, cex.lab = 1,
       xflip = FALSE, yflip = FALSE, swapxy = FALSE, se = 0, ...)

Arguments

object
Model object.
type
Type parameter passed to predict. For allowed values see the predict method for your object (such as predict.earth
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 mat
col.response
Color of response points (or response sites in degree2 plots). This refers to the response y in the data used to build the model. Plotting these points is most helpful only when the model has a single predictor. Can be a vector
cex.response
Relative size of response points. Default is NULL, meaning automatic. Applies only if col.response!=0.
pch.response
Plot character for response points. Default is 20. Applies only if col.response!=0.
jitter.response
Amount to jitter the response points. Applies only if col.response!=0. Default 0, no jitter. A typical useful value is .3, but it depends on the data. Points are jittered horizontally and vertical
npoints
Number of response points to be plotted. Applies only if col.response!=0. Default is the special value -1 meaning all. Otherwise a sample of npoints points is taken.
inverse.func
Default is NULL. Else a function applied to the predicted response before plotting. For example, you could use inverse.func=exp if your model formula is log(y)~x.
level
New in version 2.0.0. Draw estimated confidence or prediction interval bands at the given level. Default is 0, bands not plotted. Else a fraction, something like level=.95. See Prediction interv
shade.pints
Color of level bands. Default is "mistyrose2", a pale pink. Applies only if level > 0.
shade2.pints
Color of additional level bands. Default is "mistyrose4". Applies only if level > 0 and currently only for lm models.
trace
Default is 0. Use 1 (or TRUE) to trace operation. Use values greater than 1 for more detailed tracing. Use -1 to inhibit the grid: message usually issued by plotmo.
nrug
Number of points in (jittered) rug. Default is 0, no rug. Special value -1 for all. Otherwise a sample of nrug points is taken.
col.degree1
Color of degree1 lines. Default is 1.
lty.degree1
Line type of degree1 lines. Default is 1.
lwd.degree1
Line width of degree1 lines. Default is 1.
col.smooth
Color of smoothed line through the response points. (The points themselves will not be plotted unless col.response is set.) This refers to the response y in the data used to build the model. Default is 0
lty.smooth
Default is 1. Applies only if col.smooth!=0.
lwd.smooth
Default is 1. Applies only if col.smooth!=0.
smooth.f
f parameter in internal call to lowess. Default is .5. Applies only if col.smooth!=0.
func
Superimpose func(x) if func is not NULL. Default is NULL. This is useful if you are comparing the model to a known function. The func is called for each plot with a single arg
col.func
Color of func line. Default is "lightblue".
lwd.func
Line width of func line. Default is 1.
lty.func
Line type of func line. Default is 1.
ngrid1
Number of points in degree1 plots. Default is 50.
grid
Default FALSE. Use TRUE to add a grid to the degree1 plots. You can also specify a color here, e.g. grid="darkgray". The following arguments are for degree
type2
Degree2 plot type. One of "persp" (default), "contour", or "image".
ngrid2
Grid size for degree2 plots (ngrid2 x ngrid2 points are plotted, but less for factors and variables with less than ngrid2 discrete values). Default is 20. Note 1: the default will often be too small for
col.image
Colors of image plot. Default is gray(0:10/10), a range of grays. Clipped values will be displayed in blue (only applies if clip=TRUE).
col.persp
Color of persp surface. Default is "lightblue". Use 0 for no color.
theta
Rotation parameter for persp. Default is NA, meaning automatically rotate each graph so the highest corner is furthest away. Use trace=1 to see the calculated value fo
phi
Passed to persp. Default is 30. Lower values to view from the side; higher to view from above.
dvalue
Passed to persp as d. Default is 1. The name was changed from d to avoid partial matching problems.
shade
Passed to persp. Default is 0.5. The following are related to par and other graphical settings.
do.par
Default is TRUE, meaning start a new page and call par as appropriate to display multiple plots on the same page (this adjusts mfrow, cex, mar, and
caption
Overall caption. By default create captions automatically from the type, response name, and call.
main
A vector of titles, one for each plot. By default generate titles automatically from the variable names. See also caption, for the overall title.
xlim
Default is NULL, meaning automatically calculate xlim for each graph. Else used the given xlim for all degree1 graphs.
xlab
Horizontal axis label on degree1 plots (for degree2 plots the labels are always the predictor names). Default is "", no label, which gives more plottable area. The special value NULL means use the current variable
ylab
Vertical axis label. Values as for xlab.
cex
Character expansion.
cex.lab
Relative size of axis labels and text. Default 1.
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
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.
se
Deprecated. Please use the level argument instead. So instead of se=2 use level=.95.
...
Extra arguments are passed on to the plotting functions. (For persp plots, ticktype="d", nticks=2 is useful.)

concept

partial dependence plot

See Also

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

There is 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, nk=21)
    plotmo(earth.model)
}

Run the code above in your browser using DataCamp Workspace