plotmo(object = stop("no 'object' arg"),
degree1 = TRUE, degree2 = TRUE, ycolumn = 1, type="response",
caption = if(do.par) NULL else "",
ylim = NULL, clip = TRUE, inverse.func = NULL,
col.response = 0, pch.response = 1, trace = FALSE,
grid.func = median, grid.levels = NULL,
ndegree1 = 500, lty.degree1 = 1, col.degree1 = 1,
se = 0, col.shade = "lightblue", col.se = 0, lty.se = 2,
func = NULL, col.func = "pink", pch.func = 20, nrug = 0,
type2 = "persp", ngrid = 20,
col.persp = "lightblue", col.image = grey(0:9/10),
do.par = TRUE, main = NULL, theta = NA, phi = 30, shade = 0.5,
ticktype = "simple", xlab = "", ylab = "", cex = NULL, ...)TRUE, meaning all.
Perhaps the easiest way to use this argument (and degree2) is to
first plot all figures to see how the figures are numbered, then
TRUE, meaning all.predict.
Default is "response".
See predict.earth for other values for earth models.if(do.par) NULL else "". Values are:
"string" string
"" no caption
NULL generate a caption from object$call and the response name.TRUE to trace operation.
Useful for tracking down error messages.
Default is FALSE.NULL (default) all y axes have same limits
(where "y" is actually "z" on degree2 plots).
The limits are the min and max values of y across all (degree1 and degree2) plots.
If col.response!=0 then the orTRUE.NULL, meaning do not apply a function.
For example, you could use inverse.func=exp if your
model formula is log(y)~x.
Note, hpersp plots.col.response.
Default is 1.grid.levels argument below.)
Default is median.
grid.func argument above but applies to
factor predictors, not numeric predictors.
It is a list specifying which factor level to use for f500.
Special value -1 means use nrow(x).1.1.0 meaning no rug.
Special value -1 for all, i.e., nrow(x).se times the pointwise standard errors.
Default is 0, meaning no standard error bands.
A common value is 2.
The predict method for object must bse shading. Default is "lightblue".
Set to 0 for no shading.se lines. Default is 0 meaning no lines just shading.se lines. Default is 2.func(x) if func is not NULL.
Default is NULL.
This is useful if you are comparing the model to a known function.
Note that func is called with a single argument whfunc points.
Default is "pink".func points.
Default is 20.
The following arguments are for degree2 plots"persp" (default), "contour", or "image".persp surface. Default is "lightblue".
Set to 0 for no color.image plot. Default is grey(0:9/10).
The default excludes grey(1) because that is the "color" of clipped
values, see clip.20.
The following settings are related to par() and are included so you can override the defaults.par() for global settings as appropriate.
Default is TRUE.
Set to FALSE if you want to append figures to an existing plot.NULL, meaning generate figure headings automatically.persp.
Default is NA, meaning automatically rotate each graph so the highest corner is furthest away.
Use theta=-45 for x and y increasing as you movepersp. Default is 30.persp. Default is 0.5.persp plot. One of simple or detailed.
Default is "simple"."", meaning none, which gives more plottable area.
Set to NULL to use the predictor names as"", meaning none, which gives more plottable area.plotmo.
Using arguments here may cause warnings which can often be safely ignored.Plotmo is a general purpose model plotting function
(but comes with the earth package).
It is intended for models with quantitative responses.The general idea
Plotmo plots a degree1 plot of predicted values by changing one predictor while holding all other predictors at a constant value. For degree2 plots, plotmo changes two variables while holding all other predictors at a constant value.
The question arises: what should the constant value be for each predictor?
For numerical predictors it is the median of the predictor values in the input matrix x;
for factor predictors it is the first level of the factor.
You can change those defaults with the grid.func and grid.levels arguments.
Each graph shows only a thin slice of the data because most variables are fixed. You should be aware of that when interpreting the graph.
Details of operation
Let's say the model object has three predictors,
x1, x2, and x3 (all numeric)
and plotmo is about to plot the degree1 plot for x2.
Plotmo first builds an input matrix
with ndegree1 rows and with column names x1, x2, and x3.
It sets all entries for the x1 column to x1's median value (actually,
the value returned by grid.func applied to x1).
Likewise for the x3 column.
It sets the x2 column to an equally spaced sequence of values
from min(x2) to max(x2).
Finally, it calls predict(type=type) with the newly created input matrix,
and plots the predicted values against the sequence of x2 values.
Operation is similar for degree2 plots: all columns of the input
matrix for predict are set to their medians except for the columns of the two
predictors being plotted.
Note that by default plotmo calls predict with new data and
type="response", whereas termplot
calls predict with type="terms".
Limitations
NAs are not allowed.
To prevent confusing error messages from plotmo,
remove NAs before building your model.
(To be safe, you can use na.action=na.fail when building your model
so you get an error message if you inadvertently have a NA.)
Weights are currently ignored, with a warning.
Factor predictors are not supported on degree2 graphs (you will get a reminder message).
To avoid confusing error messages from plotmo,
keep the original formula you used to build the model simple.
By default (i.e., when using get.plotmo.x.default and get.pairs.default),
plotmo parses the input formula using gsub.
This crude approach is not infallible but works for the common formulas.
It determines which predictors are paired by looking for
forms such as "x1:x2" or "x1*x2" in the model formula.
Variable names containing $ are not supported.
The work around is to build the model using temporary variables
or to use attach.
Plotmo can get confused by predictors in formulas which use indexing, such as x[,3].
The symptom is usually a message along the lines
Error in model.frame: invalid type (list) for variable 'x[,3]'.
A mesage like
Warning in model.frame.default: 'newdata' had 50 rows but variable(s) found have 31 rows
means that model.frame.default cannot find all the variables in the data frame
created by plotmo.
Minimum Requirements
Plotmo requires the following of the model object.
These requirements are for default operation, which can be changed
as described in the next section.
1) object must have a predict method that supports type=response.
2) object must have the following two components
(which are searched for in the order given for each):
$x, or$call$formula(formulais required for degree2 plots),
or$call$x.$y, or$call$formula, or$call$y.se argument),
object must have a predict
method that can be called with se.fit=TRUE.Extending plotmo
Plotmo calls the following generic functions, all defined in
the file plotmo.R:
plotmo.prolog
get.plotmo.x
get.plotmo.y
plotmo.predict
get.singles
get.pairs
Thus plotmo can be extended
by writing new method functions, although the default
functions may suffice for your object's class.
See the source comments for details.
FAQ
I want to add lines or points to a plot created by plotmo.
and am having trouble getting my axis scaling right. Help?
Use do.par=FALSE.
With do.par=FALSE, the axis scales match the axis labels.
With do.par=TRUE, plot.earth restores the
par parameters and axis scales to
what they were before calling plot.earth.
This usually means that the x- and y-axis scales are both 0 to 1.
termplot,
plot.earth,
plot.earth.modelsdata(ozone1)
a <- earth(O3 ~ ., data = ozone1, degree = 2)
plotmo(a)
# example with some arguments
plotmo(a, caption = "example", ylim = NULL, degree1 = c(1,2,4),
degree2 = 4, col.response = 3, clip = FALSE, ticktype = "d", theta = -30)
# examples using functions other than earth
plotmo(lm(O3 ~ log(temp) + humidity*temp, data=ozone1), se=2)
library(gam)
data(airquality)
airquality <- na.omit(airquality) # plotmo doesn't know how to deal with NAs
plotmo(gam(Ozone^(1/3) ~ lo(Solar.R) + lo(Wind, Temp), data = airquality))
library(mgcv)
plotmo(gam(O3 ~ s(doy) + s(humidity,temp), data=ozone1), se=2, ylim=NA)Run the code above in your browser using DataLab