plotmo | R Documentation |
Plot model surfaces for a wide variety of models.
This function plots the model's response when varying one or two predictors while holding the other predictors constant (a poor man's partial-dependence plot).
It can also generate partial-dependence plots (by specifying
pmethod="partdep"
).
Please see the plotmo vignette (also available here).
plotmo(object=stop("no 'object' argument"),
type=NULL, nresponse=NA, pmethod="plotmo",
pt.col=0, jitter=.5, 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=NULL, 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,
...)
object |
The model object. | ||||||||||||||||||||||||||||||||
type |
Type parameter passed to | ||||||||||||||||||||||||||||||||
nresponse |
Which column to use when | ||||||||||||||||||||||||||||||||
pmethod |
Plotting method. One of:
| ||||||||||||||||||||||||||||||||
pt.col |
The color of response points (or response sites in degree2 plots).
This refers to the response | ||||||||||||||||||||||||||||||||
jitter |
Applies only if | ||||||||||||||||||||||||||||||||
smooth.col |
Color of smooth line through the response points.
(The points themselves will not be plotted unless mod <- lm(Volume~Height, data=trees) plotmo(mod, pt.color=1, smooth.col=2) You can adjust the amount of smoothing with | ||||||||||||||||||||||||||||||||
level |
Draw estimated confidence or prediction interval bands at the given mod <- lm(log(Volume)~log(Girth), data=trees) plotmo(mod, level=.95) You can modify the color of the bands with | ||||||||||||||||||||||||||||||||
func |
Superimpose mod <- lm(Volume~Girth, data=trees) estimated.volume <- function(x) .17 * x$Girth^2 plotmo(mod, pt.col=2, func=estimated.volume) The | ||||||||||||||||||||||||||||||||
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 ticks in the | ||||||||||||||||||||||||||||||||
grid.col |
Default is | ||||||||||||||||||||||||||||||||
type2 |
Degree2 plot type.
One of plotmo(mod, persp.ticktype="detailed", persp.nticks=3) plotmo(mod, type2="image") plotmo(mod, type2="image", image.col=heat.colors(12)) plotmo(mod, type2="contour", contour.col=2, contour.labcex=.4) | ||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||
all1 |
Default is | ||||||||||||||||||||||||||||||||
degree2 |
An index vector specifying which subset of degree2 (interaction) plots to include.
| ||||||||||||||||||||||||||||||||
all2 |
Default is | ||||||||||||||||||||||||||||||||
do.par |
One of
| ||||||||||||||||||||||||||||||||
clip |
The default is | ||||||||||||||||||||||||||||||||
ylim |
Three possibilities:
| ||||||||||||||||||||||||||||||||
caption |
Overall caption. By default create the caption automatically.
Use | ||||||||||||||||||||||||||||||||
trace |
Default is | ||||||||||||||||||||||||||||||||
grid.func |
Function applied to columns of the plotmo(mod, grid.func=mean) grid.func <- function(x, ...) quantile(x)[2] # 25% quantile plotmo(mod, grid.func=grid.func) This argument is not related to the | ||||||||||||||||||||||||||||||||
grid.levels |
Default is plotmo(mod, grid.levels=list(sex="m", age=21)) | ||||||||||||||||||||||||||||||||
extend |
Amount to extend the horizontal axis in each plot.
The default is | ||||||||||||||||||||||||||||||||
ngrid1 |
Number of equally spaced x values in each degree1 plot.
Default is | ||||||||||||||||||||||||||||||||
ngrid2 |
Grid size for degree2 plots ( | ||||||||||||||||||||||||||||||||
npoints |
Number of response points to be plotted
(a sample of | ||||||||||||||||||||||||||||||||
ndiscrete |
Default | ||||||||||||||||||||||||||||||||
int.only.ok |
Plot the model even if it is an intercept-only model (no predictors are
used in the model).
Do this by plotting a single degree1 plot for the first predictor.
| ||||||||||||||||||||||||||||||||
center |
Center the plotted response.
Default is | ||||||||||||||||||||||||||||||||
xflip |
Default | ||||||||||||||||||||||||||||||||
yflip |
Default | ||||||||||||||||||||||||||||||||
swapxy |
Default | ||||||||||||||||||||||||||||||||
... |
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.
plotmo(mod, s=1) # error: arg matches multiple formal args plotmo(mod, predict.s=1) # ok now: s=1 will be passed to predict() The prefixes recognized by
The For backwards compatibility, some dot arguments are supported but not
explicitly documented. For example, the old argument |
In general this function won't work on models that don't save the call and data with the model in a standard way. For further discussion please see “Accessing the model data” in the plotmo vignette. Package authors may want to look at Guidelines for S3 Regression Models (also available here).
By default, plotmo
tries to use sensible model-dependent
defaults when calling predict
.
Use trace=1
to see the arguments passed to predict
.
You can change the defaults by using plotmo
's type
argument,
and by using dot arguments prefixed with
predict.
(see the description of “...
” above).
Please see the plotmo vignette (also available here).
if (require(rpart)) {
data(kyphosis)
rpart.model <- rpart(Kyphosis~., data=kyphosis)
# pass type="prob" to plotmo's internal calls to predict.rpart, and
# select the column named "present" from the matrix returned by predict.rpart
plotmo(rpart.model, type="prob", nresponse="present")
}
if (require(earth)) {
data(ozone1)
earth.model <- earth(O3 ~ ., data=ozone1, degree=2)
plotmo(earth.model)
# plotmo(earth.model, pmethod="partdep") # partial dependence plots
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.