mcPlot
function draws two plots, or overlay the two graphs on one plot. For a response Y and a regressor X, the first plot is the marginal plot of Y versus X with both variables centered, visualizing the conditional distribution of Y given X ignoring all other regressors. The second plot is an added-variable for X after all other regressors, visualizing the conditional distribution of Y given X after adjusting for all other predictors. 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.The plot is primarily intended as a pedagogical tool for understanding coefficients in first-order models.
mcPlots(model, terms=~., layout=NULL, ask, overlaid=TRUE, ...)
mcPlot(model, ...)
"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], id.location="lr", 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, ...)
lm
.
terms = ~ . - X3
would plot against all terms
except for X3
. If this argument is a quoted name of one of the terms, the
added-variable plot is drawn for that term only.
type
with levels A
, B
and C, using the usual drop-first level parameterization of the factor, the regressors for type
would be typeB
or typeC
.
c(1, 2)
or c(6, 2)
, the layout
of the graph will have this many rows and columns. If not set, behavior depends on the value of the overlaid
argument; see the details
TRUE
, ask the user before drawing the next plot; if FALSE
don't ask.
mcPlots
passes these arguments to mcPlot
.
mcPlot
passes arguments to plot
.
id.n=0
for labeling no points. See
showLabels
for details of these arguments.
overlaid=TRUE
2
(see par
).TRUE
, the default, a light-gray background grid is put on the graph.TRUE
, plot a concentration ellipse; default is FALSE
.dataEllipse
function, in the form of a list
with named elements; e.g., ellipse.args=list(robust=TRUE))
will cause the ellipse to be plotted using
a robust covariance-matrix.TRUE
, the default, the plot window is reset when overlaid=FALSE
using par{mfrow=c(1, 2)}
. If FALSE
, the layout of the plot window is not reset.
Users will ordinarily ignore this argument.lm
object, suppose the response is Y, X is a focal numeric predictor of interest, and Z is all the remaining predictors, possibly including interactions and factors. This function produces two graphs. The first graph is the marginal plot of Y versus X, with each variable centered around its mean. The second conditional plot is the added-variable plot of e(Y|Z) versus e(X|Z) where e(a|b) means the Pearson 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 as long as the second argument to layout
is equal to 2
, or layout
is set by the function. The arrows are omitted if the graphs are not overlaid.
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.This function is intended for first-order models with numeric predictors only. If the focal predictor is a factor, then one (pair) of mcPlots will be produced for each of the basis variables that define the factor, and the resulting plots are not generally meaningful because they depend on parameterization. If the mean function includes interactions, then mcPlots for main effects may violate the hierarchy principle, and may also be of little interest. mcPlots for interactions of numerical predictors, however, can be useful.
These graphs are closely related to the ARES plots proposed by Cook and Weisberg (1989). This plot would benefit from animation.
Fox, J. (2016) Applied Regression Analysis and Generalized Linear Models, Third 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.
avPlots
, residualPlots
, crPlots
, ceresPlots
,
dataEllipse
m1 <- lm(partic ~ tfr + menwage + womwage + debt + parttime, data = Bfox)
mcPlot(m1, "womwage")
mcPlot(m1, "womwage", overlaid=FALSE, ellipse=TRUE)
Run the code above in your browser using DataCamp Workspace