mmps {car} | R Documentation |
Marginal Model Plotting
Description
For a regression object, draw a plot of the response on the vertical axis versus
a linear combination u
of regressors in the mean function on the horizontal
axis. Added to the plot are a smooth for the graph, along with
a smooth from the plot of the fitted values on u
. mmps
is an alias
for marginalModelPlots
, and mmp
is an alias for marginalModelPlot
.
Usage
marginalModelPlots(...)
mmps(model, terms= ~ ., fitted=TRUE, layout=NULL, ask,
main, groups, key=TRUE, ...)
marginalModelPlot(...)
mmp(model, ...)
## S3 method for class 'lm'
mmp(model, variable, sd = FALSE,
xlab = deparse(substitute(variable)),
smooth=TRUE, key=TRUE, pch, groups=NULL, ...)
## Default S3 method:
mmp(model, variable, sd = FALSE,
xlab = deparse(substitute(variable)), ylab, smooth=TRUE,
key=TRUE, pch, groups=NULL,
col.line = carPalette()[c(2, 8)], col=carPalette()[1],
id=FALSE, grid=TRUE, ...)
## S3 method for class 'glm'
mmp(model, variable, sd = FALSE,
xlab = deparse(substitute(variable)), ylab,
smooth=TRUE, key=TRUE, pch, groups=NULL,
col.line = carPalette()[c(2, 8)], col=carPalette()[1],
id=FALSE, grid=TRUE, ...)
Arguments
model |
A regression object, usually of class either |
terms |
A one-sided formula. A marginal model plot will be drawn for
each term on the right-side of this formula that is not a factor. The
default is |
fitted |
If |
layout |
If set to a value like |
ask |
If |
main |
Main title for the array of plots. Use |
... |
Additional arguments passed from |
variable |
The quantity to be plotted on the horizontal axis. If this argument
is missing, the horizontal variable is the linear predictor, returned by
|
sd |
If |
xlab |
label for horizontal axis. |
ylab |
label for vertical axis, defaults to name of response. |
smooth |
specifies the smoother to be used along with its arguments; if |
groups |
The name of a vector that specifies a grouping variable for
separate colors/smoothers. This can also be specified as a conditioning
argument on the |
key |
If |
id |
controls point identification; if |
pch |
plotting character to use if no grouping is present. |
col.line |
colors for data and model smooth, respectively. The default is to use |
col |
color(s) for the plotted points. |
grid |
If TRUE, the default, a light-gray background grid is put on the graph |
Details
mmp
and marginalModelPlot
draw one marginal model plot against
whatever is specified as the horizontal axis.
mmps
and marginalModelPlots
draws marginal model plots
versus each of the terms in the terms
argument and versus fitted values.
mmps
skips factors and interactions if they are specified in the
terms
argument. Terms based on polynomials or on splines (or
potentially any term that is represented by a matrix of regressors) will
be used to form a marginal model plot by returning a linear combination of the
terms. For example, if you specify terms = ~ X1 + poly(X2, 3)
and
poly(X2, 3)
was part of the original model formula, the horizontal
axis of the marginal model plot for X2
will be the value of
predict(model, type="terms")[, "poly(X2, 3)"])
. If the predict
method for the model you are using doesn't support type="terms"
,
then the polynomial/spline term is skipped. Adding a conditioning variable,
e.g., terms = ~ a + b | c
, will produce marginal model plots for a
and b
with different colors and smoothers for each unique non-missing
value of c
.
For linear models, the default smoother is loess.
For generalized linear models, the default smoother uses gamLine
, fitting
a generalized additive model with the same family, link and weights as the fit of the
model. SD smooths are not computed for for generalized linear models.
For generalized linear models the default number of elements in the spline basis is
k=3
; this is done to allow fitting for predictors with just a few support
points. If you have many support points you may wish to set k
to a higher
number, or k=-1
for the default used by gam
.
Value
Used for its side effect of producing plots.
Author(s)
Sanford Weisberg, sandy@umn.edu
References
Cook, R. D., & Weisberg, S. (1997). Graphics for assessing the adequacy of regression models. Journal of the American Statistical Association, 92(438), 490-499.
Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition. Sage.
Weisberg, S. (2005) Applied Linear Regression, Third Edition, Wiley, Section 8.4.
See Also
Examples
c1 <- lm(infantMortality ~ ppgdp, UN)
mmps(c1)
c2 <- update(c1, ~ log(ppgdp))
mmps(c2)
# include SD lines
p1 <- lm(prestige ~ income + education, Prestige)
mmps(p1, sd=TRUE)
# condition on type:
mmps(p1, ~. | type)
# logisitic regression example
# smoothers return warning messages.
# fit a separate smoother and color for each type of occupation.
m1 <- glm(lfp ~ ., family=binomial, data=Mroz)
mmps(m1)