mmplot {marginalmodelplots} | R Documentation |
Marginal model plots are a non parametric form of verifying model adequacy. The Structure of a marginal model plot is a plot with the response variable along the vertical axis, and a predictor variable, or any linear combination of predictor variables allong the horizontal axis. Two non parametric smooths are added to the plots. One for the response on the predictor and another for the fitted values on the predictor. If the two curves match closely then the model is determined to be adaquate.
The mmplot
fuction, as implimented here, is capable of computing an optimal
bandwidth using generalized cross validation (gcv
), Akaike's information criteria (aic
),
or Akaike's information criteria corrected (aicc
).
mmplot(object,exclude=NULL,layout=NULL,ask,...) mmplot1(object, ...) mmplot1.lm(object,u=predict(object), label=deparse(substitute(u)), locfit.control=list(nn=2/3), colors=c("blue","red"), ...) mmplot1.glm(object,u=predict(object),mean=TRUE, label=deparse(substitute(u)), locfit.control=list(nn=2/3), subset=NULL, colors=c("blue","red"),family=NULL,link=NULL,yhat.autoquasi=TRUE, inc.legend=TRUE,...)
object |
A regression object, of type either lm or glm,
for which there is a predict
method defined. |
exclude |
A vector of indices of variables for which a plot is not
required. For example, c(2,4) would exclude the second and fourth
terms in the model, excluding the intercept. |
layout |
A reasonable layout for the plots in the window is
determined by the program. If you don't like the default you can set your
own layout: c(2,3) means two rows and three columns. |
ask |
If TRUE, ask before clearing the graph window to draw more plots. |
u |
The quantity to be plotted on the horizontal axis. The
default is the predicted values predict(object) . Can be any other
vector of length equal to the number of observations in the object. |
mean |
If TRUE, compare mean smooths. Depreciated, should allways be left as TRUE. |
label |
label for horizontal axis |
locfit.control |
A list of control parameters to pass to the locfit function to adjust
the nature of the curve. the primary purpose of this will be to set the bandwidth
or nearest neighbor parameter for smoothing, although any of the locfit
parameters may be set here. To use a optimally computed bandwidth use h='aic' or nn='gcv'
for an AIC optimal fixed bandwidth or a GCV optimal nearest neighbor, respectivly. |
subset |
logical vector indicating the observations to use. See subset. |
colors |
colors for response and fitted values smooths, respectively |
family |
Overrides the family used for the local glm fit in glm models. |
link |
Overrides the link used for the local glm fit in glm models. |
yhat.autoquasi |
Determines if the quasi version of the family should be used to fit the fitted values curve. The default is True, since the fitted values do not have constant variance. |
inc.legend |
Determines if there is a legend included on the plot. Defaults to TRUE. |
... |
additional arguments passed to plot |
mmplot1
draws one marginal model plot. mmplot
draws all marginal model plots,
versus each of the terms in the model and versus fitted values. mmplot
should not be used if some of the terms in the model are factors or
interactions.
Special attention is paid to logistic regression models. The vertical axis is labeled with the levels of the factor if the response was a factor. Also points are colored if the predicted outcome differs from the observed response.
The mmplot
implimentation here uses the locfit package to generate the non parametric smooths.
A lm
model is equivalent to using a local polynomial smooth, but with glm
models
the smooth is a local glm fit of the same family as the model, unless overridden by user.
mmplot1
functions return (invisible) an object with the smothing parameters used.
The first componenent being the parameters for the data (named y
), the second for the fitted values (named yhat
).
The components of the smoothing parameters are first the bandwidth (h
) if used, otherwise NULL
. Second the nearest neighbor parameter(nn
) if used, otherwise NULL
.
The mmplot
function returns an unnamed list of the smoothing parameters in the order the graph appear.
A large number of warnings can be produced from locfit when running mmplot, especially with optimized smoothing parameters. Warnings that are passed from the locfit procedures are for the final fit.
Andrew Redd, aredd at stat.tamu.edu
S. Weisberg (2005), Applied Linear Regression, third edition, Wiley, Chapter 8
data(Bordeaux) m<-lm(Price~ParkerPoints+CoatesPoints+FirstGrowth+Pomerol+VintageSuperstar+CultWine,data=Bordeaux) mmplot(m,locfit.control=list(nn=2/3)) data(MichelinNY) m4 <- glm(InMichelin~Food+Decor*Service+log(Cost),family=binomial(),data=MichelinNY) mmplot(m4) mmplot(m4,locfit.control=list(nn=.7)) mmplot(m4,locfit.control=list(nn='aic'))