mcPlots {car} | R Documentation |
Draw Linear Model Marginal and Conditional Plots in Parallel or Overlaid
Description
These functions take a fitted lm
object and draw two plots for each regressor, one showing the marginal relationship between the response and the regressor, centered but otherwise ignoring all other regressors, and the other an added-variable plot, showing the conditional relationship of Y and X given all other regressors. The added variable plot by default is drawn using the same xlim and ylim as the centered marginal plot to emphasize that conditioning removes variation in both the regressor and the response.
Usage
mcPlots(model, terms=~., layout=NULL, ask, overlaid=TRUE, ...)
mcPlot(model, ...)
## S3 method for class 'lm'
mcPlot(model, variable,
id.method = list(abs(residuals(model, type="pearson")), "x"),
labels,
id.n = if(id.method[1]=="identify") Inf else 0,
id.cex=1, id.col=palette()[1],
col.marginal="blue", col.conditional="red", col.arrows="gray",
pch = c(16, 1), lwd = 2, grid=TRUE, ###removed arg main
ellipse=FALSE, ellipse.args=list(levels=0.5),
overlaid=TRUE, new=TRUE, ...)
Arguments
model |
model object produced by |
terms |
A one-sided formula that specifies a subset of the predictors.
One added-variable plot is drawn for each term. For example, the
specification |
variable |
A quoted string giving the name of a regressor in the model matrix for the horizontal axis |
layout |
If set to a value like |
ask |
If |
... |
|
id.method , labels , id.n , id.cex , id.col |
Arguments for the labelling of
points. The default is |
overlaid |
If TRUE, overlay the marginal and conditional plots; otherwise plot them side-by-side |
col.marginal , col.conditional |
colors for points, lines, ellipses in the marginal and conditional plots, respectively |
col.arrows |
color for the arrows with |
pch |
Plotting character for marginal and conditional plots, respectively. |
lwd |
line width; default is |
grid |
If |
ellipse |
If |
ellipse.args |
Arguments to pass to the |
new |
if |
Details
With an lm
object, suppose the response is Y, X is a focal regressor of interest, and Z is all the remaining regressors. This function produces two graphs. The marginal plot is simply of Y versus X, with each variable centered around its mean. The conditional plot is the added-variable plot of e(Y|Z) versus e(X|Z) where e(a|b) means the ordinary residuals from the regression of a on b. If overlaid=TRUE
, these two plots are overlaid in one graph, with the points in different colors. In addition, each point in the marginal plot is joined to its value in the conditional plot by an arrow. Least squares regression lines fit to the marginal and conditional graphs are also shown; data ellipsoids can also be added. If overlaid=FALSE
, then the two graphs are shown in side-by-side plots, and the arrows are omitted.
These graphs are primarily for teaching, as the marginal plot shows the relationship between Y and X ignoring Z, while the conditional is the relationship between Y and X given X. By keeping the scales the same in both graphs the effect of conditioning on both X and Y can be visualized.
These graphs are closely related to the ARES plots proposed by Cook and Weisberg (1989). This plot would benefit from animation.
Value
These functions are used for their side effect id producing plots.
Author(s)
John Fox jfox@mcmaster.ca, Sanford Weisberg sandy@umn.edu
References
Cook, R. D. and Weisberg, S. (1989) Regression diagnostics with dynamic graphics, Technometrics, 31, 277.
Fox, J. (2008) Applied Regression Analysis and Generalized Linear Models, Second Edition. Sage.
Fox, J. and Weisberg, S. (2011) An R Companion to Applied Regression, Second Edition, Sage.
Weisberg, S. (2014) Applied Linear Regression, Fourth Edition, Wiley.
See Also
avPlots
, residualPlots
, crPlots
, ceresPlots
,
dataEllipse
Examples
m1 <- lm(partic ~ tfr + menwage + womwage + debt + parttime, data = Bfox)
mcPlot(m1, "womwage")
mcPlot(m1, "womwage", overlaid=FALSE, ellipse=TRUE)