car (version 2.0-0)

mmps: Marginal Model Plotting

Description

For a regression object, plots the response on the vertical axis versus a linear combination $u$ of terms in the mean function on the horizontal axis. Added to the plot are a loess smooth for the graph, along with a loess 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, AsIs=FALSE, ...)

marginalModelPlot(...)

## S3 method for class 'lm':
mmp(model, variable, mean = TRUE, sd = FALSE,
    xlab = deparse(substitute(variable)), degree = 1, span = 2/3, key=TRUE,
    col.line = palette()[c(4, 2)], 
    ...)
    
## S3 method for class 'default':
mmp(model, variable, mean = TRUE, sd = FALSE, xlab =
                 deparse(substitute(variable)), degree = 1, span = 2/3,
                 key = TRUE, col.line = palette()[c(4,2)],   
                 labels, id.method = "y", 
                 id.n=if(id.method[1]=="identify") Inf else 0, 
                 id.cex = 1, id.col=palette()[1], grid=TRUE, ...)
   
## S3 method for class 'glm':
mmp(model, variable, mean = TRUE, sd = FALSE,
    xlab = deparse(substitute(variable)), degree = 1, span = 2/3, key=TRUE,
    col.line = palette()[c(4, 2)],
    labels, id.method="y", 
    id.n=if(id.method[1]=="identify") Inf else 0,
    id.cex=1, id.col=palette()[1], grid=TRUE, ...)

Arguments

model
A regression object, usually of class either lm or glm, for which there is a predict method defined.
terms
A one-sided formula. A marginal model plot will be drawn for each variable on the right-side of this formula that is not a factor. The default is ~ ., which specifies that all the terms in formula(object) will be used
fitted
If the default TRUE, then a marginal model plot in the direction of the fitted values or linear predictor of a generalized linear model will be drawn.
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.
main
Main title for the array of plots. Use main="" to suppress the title; if missing, a title will be supplied.
AsIs
If FALSE, the default, terms that use the as-is function I are skipped; if TRUE they are included.
...
Additional arguments passed from mmps to mmp and then to plot. Users should generally use mmps, or equivalently marginalModelPlots.
variable
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. Thus the mmp function can be
mean
If TRUE, compare mean smooths
sd
If TRUE, compare sd smooths. For a binomial regression with all sample sizes equal to one, this argument is ignored as the SD bounds don't make any sense.
xlab
label for horizontal axis
degree
Degree of the local polynomial, passed to loess. The usual default for loess is 2, but the default here is 1.
span
Span, the smoothing parameter for loess.
key
If TRUE, include a key at the top of the plot, if FALSE omit the key
id.method,labels,id.n,id.cex,id.col
Arguments for labelling points. The default id.n=0 suppresses labelling, and setting this argument greater than zero will include labelling. See showLabels for these arguments.
col.line
colors for data and model smooth, respectively. Using the default palette, these are blue and red.
grid
If TRUE, the default, a light-gray background grid is put on the graph

Value

  • Used for its side effect of producing plots.

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, interactions, and spline terms. For polynomial terms in one variable, plots are against the first-order term.

References

Fox, J. and Weisberg, S. (2011) An R Companion to Applied Regression, Second Edition. Sage. Weisberg, S. (2005) Applied Linear Regression, Third Edition, Wiley, Chapter 8.

See Also

loess, plot

Examples

Run this code
c1 <- lm(infant.mortality ~ gdp, UN)
mmps(c1)
# include SD lines
p1 <- lm(prestige ~ income + education, Prestige)
mmps(p1, sd=TRUE)
# logisitic regression example
m1 <- glm(lfp ~ ., family=binomial, data=Mroz)
mmps(m1)

Run the code above in your browser using DataCamp Workspace