summary
, print
, plot
, and [
methods for eff
, effpoly
,
efflist
, and mlm.efflist
objects.
"print"(x, type=c("response", "link"), ...)
"print"(x, type=c("probability", "logits"), ...)
"print"(x, ...)
"print"(x, ...)
"print"(x, ...)
"print"(x, ...)
"summary"(object, type=c("response", "link"), ...)
"summary"(object, type=c("probability", "logits"), ...)
"summary"(object, ...)
"summary"(object, ...)
"summary"(object, ...)
"plot"(x, x.var, z.var=which.min(levels), multiline=is.null(x$se), rug=TRUE, xlab, ylab, main=paste(effect, "effect plot"), colors=palette(), symbols=1:length(colors), lines=1:length(colors), cex=1.5, lwd=2, ylim, xlim=NULL, factor.names=TRUE, ci.style, band.transparency=0.15, band.colors=colors, type=c("rescale", "response", "link"), ticks=list(at=NULL, n=5), alternating=TRUE, rotx=0, roty=0, grid=FALSE, layout, rescale.axis, transform.x=NULL, ticks.x=NULL, show.strip.values = !partial.residuals, key.args=NULL, row=1, col=1, nrow=1, ncol=1, more=FALSE, use.splines=TRUE, partial.residuals=!is.null(x$residuals), show.fitted=FALSE, residuals.color="blue", residuals.pch=1, residuals.cex=1, smooth.residuals=TRUE, residuals.smooth.color=residuals.color, span=2/3, ...)
"plot"(x,
type=c("probability", "logit"),
x.var=which.max(levels),
rug=TRUE,
xlab,
ylab=paste(x$response, " (", type, ")", sep=""),
main=paste(effect, "effect plot"),
colors, symbols, lines, cex=1.5, lwd=2,
factor.names=TRUE, show.strip.values = TRUE,
ci.style, band.colors, band.transparency=0.3,
style=c("lines", "stacked"),
confint=(style == "lines" && !is.null(x$confidence.level)),
transform.x=NULL, ticks.x=NULL, xlim=NULL,
ylim, rotx=0, alternating=TRUE, roty=0, grid=FALSE,
layout, key.args=NULL,
row=1, col=1, nrow=1, ncol=1, more=FALSE, use.splines=TRUE, ...)
"plot"(x, selection, rows, cols, ask=FALSE, graphics=TRUE, ...)
"plot"(x, ...)
setStrip(bg=3, fg="black", clip=c("off", "on"))
restoreStrip(saved)
"["(x, ...)
"eff"
, "effpoly"
, "efflist"
, "mlm.efflist"
,
or "summary.eff"
, as appropriate."eff"
, "effpoly"
, "efflist"
, or "mlm.efflist"
,
as appropriate."response"
(the default), effects are printed on the scale of the response
variable; if "link"
, effects are printed on the scale of the linear predictor.
For plotting linear or genealized linearized models, "rescale"
(the default) plots the vertical
axis on the link scale (e.g., the logit scale for a logit model) but labels the axis on the response
scale (e.g., the probability scale for a logit model);
"response"
plots and labels the vertical axis on the scale of the response (e.g., the
probability scale for a logit model); and
"link"
plots and labels the vertical axis
on the scale of the link (e.g., the logit scale for a logit model). For polytomous logit models, this argument takes either "probability"
or "logit"
, with the former as the default.
type
argument instead. Setting
rescale.axis=TRUE
is equivalent to type="rescale"
; setting rescale.axis=FALSE
is equivalent to type="response"
. If specified, rescale.axis
will override type
.multiline = TRUE
.TRUE
, each panel of the display represents combinations
of values of two predictors, with one predictor (corresponding to x.var
)
on the horzontal axis, and the other (corresponding to z.var
) used to define
lines in the graph; defaults to TRUE
if there are no standard errors in
the object being plotted, and FALSE
otherwise.TRUE
,
in which case separate panels are used for different response levels.TRUE
, the default, a rug plot is shown giving the marginal
distribution of the predictor on the horizontal axis, if this predictor is
a covariate. The rug plot is suppressed if partial residuals are plotted.colors[1]
is used to plot effects, colors[2]
to plot
confidence limits when ci.style
is not equal to "bands"
. In a mulitline plot, the successive colors
correspond
to the levels of the z.var
covariate or factor. In a stacked plot or a plot
without confidence bands for a
multinomial or proportional-odds logit model, the successive colors
correspond to the levels of the response factor. In all but stacked plots,
colors
defaults to palette()
. If colors
is
shorter than the number of levels, then it is recycled, so colors="black"
will use black for all levels. For stacked multinomial-logit plots,
colors
defaults to rainbow_hcl(levels)
, where levels
is
the number of levels of the response variable; for stacked proportional-odds model
plots, colors
defautls to sequential_hcl(levels)
. colors
does not recycle for stacked plots.
Warning: This argument
cannot be abbreviated to col
, which is used for a different
purpose (see below).
z.var
covariate
or factor on a multiline plot, or to the successive levels of the response factor
in a line plot for a polytomous logit model.
These arguments are used only if multiline = TRUE
or for polytomous logit models where the effects are plotted without confidence bands;
in these cases a legend is drawn at the top of the display. If these arguments are
too short they are recycled.1.5
.NULL
, the default, then the vertical axes are scaled from the data.
Warning: By default, the vertical axis for a generalized linear model is on the
scale of the linear predictor (e.g., the logit scale for a logit model), not on the scale
of the response (e.g., the probability scale for a logit model), although the tick labels
are by default on the scale of the response. Consequently, the axis limits should be on the scale
of the linear predictor. E.g., for a logit model with axes to run from probabilities of 0.1 to
0.8, you can specify log(c(0.1, 0.8)/c(0.9, 0.2))
.NULL
(the default), then the horizontal
axis limits are computed from the data.TRUE
, that controls the inclusion of
factor names in conditioning-variable labels."bars"
for factors and "bands"
for variates. Style "lines"
can also be used for either of these.
For multiline plots, the default is "none"
for no
confidence bounds, but style "bars"
or "bands"
can also be used. For a variate
the option "bars"
displays the error bars at
each of the levels
points for which the horizontal variable was evaluated.ci.style="bands"
.
The default is band.colors=colors
. For plots with one line, the choice, setting
band.colors="red"
produces a pleasing result, even if color provides no additional
information in this case. If this argument is too short it is recycled.ci.style="bands"
, the alpha transparency of the fill color. Not all
graphic devices support transparency."lines"
(the default
for a line plot, or "stacked"
for a stacked-bar or stacked-area plot. In the latter
case only fitted probabilities may be plotted and confidence envelopes cannot be shown.at
and n
. If at=NULL
(the default), the program
attempts to find `nice' locations for the ticks, and the value of n
(default,
5
) gives the
approximate number of tick marks desired; if at
is non-NULL
, then the
value of n
is ignored. Warning: For a generalized linear model, by default the vertical axis is on the
scale of the linear predictor (e.g., the logit scale for a logit model),
but labels for tick marks are displayed on the scale of
the response (e.g., the probability scale for a logit model); at
should be given
on the response scale (e.g., the probability scale for a logit model).
at
or n
are for the ticks
argument.
If a predictor doesn't appear in the list, or if ticks.x
is NULL
(the default),
then the tick marks are computed by the function.TRUE
for
an effpoly
object, and TRUE
for an eff
object if partial residuals aren't plotted.trans
and inverse
.
The names of the list elements are numeric predictors in the model whose axes are to be transformed; the
trans
function is applied to the values of the predictor, and inverse
is used for computing
proper axis tick labels. If a numeric predictor is missing from transform.x
then its axis is not
transformed; if the argument is NULL
(the default), then no predictor axes are transformed.TRUE
(the default), the tick labels alternate by panels in
multi-panel displays from left to right and top to bottom; if FALSE
, tick labels
appear at the bottom and on the left.TRUE
, add grid lines to the plot. Default is FALSE.layout
argument to the lattice function xyplot
(or, in some cases densityplot
), which
is used to draw the effect display; if not specified, the plot will be formatted so that
it appears on a single page.key
trellis argument to
xyplot
or densityplot
,
e.g., to position the key (legend) in the plotting region; may also be used to modify
the default behavior of the key.row
, col
, nrow
, and ncol
are used to compose
the split
argument and more
the more
argument to print.trellis
.
Normally these arguments are not set by the user, but by plot.efflist
.
Warning: Note that col
is not used to specify colors;
use colors
instead (see above).efflist
object;
if either argument is missing, then the meta-layout will be computed by the plot
method.selection
is not supplied and ask
is TRUE
,
a menu of high-order terms is presented; if ask
is FALSE
(the default), effects for all
high-order terms are plotted in an array.TRUE
(the default), then the menu of terms to plot is presented
in a dialog box rather than as a text menu.TRUE
, the default, then any lines drawn when the horizontal
axis is not a factor use interpolating splines computed by the spline
function. If FALSE, then linear interpoliation is used. This argument is ignored if
the horizontal axis is a factor.TRUE
(the default if residuals are in the effect object), plot partial residuals --- see Effect
;
partial residuals are suppressed (with a warning) in multiline displays.loess
smooth of the partial residuals, if
they are present; the default is TRUE
. For a non-Gaussian glm
model,
a non-robust loess
smooth is used; for a lm
model or a Gaussian glm
model,
a robust smooth is employed.xyplot
smoother to be applied to partial residuals;
the default is 2/3
.TRUE
and partial residuals are present in the effect object, also plot the partial
fitted values (which will be shown as filled circles); the default is FALSE
."blue"
).residuals.color
.1
, open circles).1
).3
), the color of the strips at the tops
of lattice panels are set to gray scale, with the number of graditions, if there is more than one
conditioning variable, corresponding to the value given (which will be rounded to a whole number).
This argument can also be a vector of colors, specified in any manner recognized in R (e.g, by name)."black"
); can be a single value or a vector of values of the same length as bg
."off"
or "on"
, determines whether or not conditioning values in the strips
at the top of lattice panels are clipped on the left and right. The normal lattice default is
"on"
; the default in setStrip
is "off"
, allowing the lines representing numeric
conditioning values to be displayed more clearly at the extreme left and right of strips.setStrip
.summary
method for "eff"
objects returns a "summary.eff"
object with the following components
(those pertaining to confidence limits need not be present):The setStrip
function invisibly returns a list that can supply the argument of the
restoreStrip
function to restore the previous lattice strip specification.The [
method for "efflist"
objects is used to subset an "efflist"
object and returns an object of the same class.
print
and summary
methods for
eff
objects print the computed effects on the scale of the
response variable using the inverse of the
link function. In a logit model, for example, this means that the effects are expressed on the probability
scale.
By default, effects in a GLM are plotted on the scale of the linear predictor, but the vertical
axis is labelled on the response scale. This preserves the linear structure of the model while permitting
interpretation on what is usually a more familiar scale.
This approach may also be used with linear models, for example to display effects on the scale of the
response even if the data are analyzed on a transformed scale, such as log or square-root.
When a factor is on the x-axis, the plot
method for eff
objects
connects the points representing the effect by line segments, creating a
response ``profile.'' If you wish to suppress these lines, add the argument
lty=0
to the call to plot
(see the examples).
In a polytomous (multinomial or proportional-odds) logit model, by default effects are plotted on the
probability scale; they may be alternatively plotted on the scale of the individual-level logits.
The setStrip
and restoreStrip
functions modify the strips that appear in subsequent
lattice plots, including those produced by functions in the effects package. The default call
setStrip()
provides monochrome (rather than the lattice-default colored) strips with up to 3
gray-scale values corresponding to 3 conditioning variables; clipping at the left and right of strips
is also turned off by default by setStrip
. restoreStrip
may be used to reset
lattice strips to previously saved parameters returned by setStrip
.
effect
, allEffects
, xyplot
,
densityplot
, print.trellis
, loess
,
rainbow_hcl
, sequential_hcl
# also see examples in ?effect
mod.cowles <- glm(volunteer ~ sex + neuroticism*extraversion,
data=Cowles, family=binomial)
eff.cowles <- allEffects(mod.cowles, xlevels=list(extraversion=seq(0, 24, 6)))
eff.cowles
as.data.frame(eff.cowles[[2]]) # neuroticism*extraversion interaction
plot(eff.cowles, 'sex', ylab="Prob(Volunteer)", grid=TRUE, rotx=90, lty=0)
.save.strip <- setStrip()
plot(eff.cowles, 'neuroticism:extraversion', ylab="Prob(Volunteer)",
ticks=list(at=c(.1,.25,.5,.75,.9)))
# change color of the confidence bands to 'black' with .15 transparency
plot(eff.cowles, 'neuroticism:extraversion', ylab="Prob(Volunteer)",
ticks=list(at=c(.1,.25,.5,.75,.9)), band.colors="red", band.transparency=.3)
plot(eff.cowles, 'neuroticism:extraversion', multiline=TRUE,
ylab="Prob(Volunteer)", key.args = list(x = 0.75, y = 0.75, corner = c(0, 0)))
# use probability scale in place of logit scale, all lines are black.
plot(eff.cowles, 'neuroticism:extraversion', multiline=TRUE,
ylab="Prob(Volunteer)", key.args = list(x = 0.75, y = 0.75, corner = c(0, 0)),
colors="black", lines=1:8,
ci.style="bands", type="response", band.colors=palette())
plot(effect('sex:neuroticism:extraversion', mod.cowles,
xlevels=list(extraversion=seq(0, 24, 6))), multiline=TRUE)
plot(effect('sex:neuroticism:extraversion', mod.cowles,
xlevels=list(extraversion=seq(0, 24, 6))), multiline=TRUE,
type="response", ci.style="bands")
if (require(nnet)){
mod.beps <- multinom(vote ~ age + gender + economic.cond.national +
economic.cond.household + Blair + Hague + Kennedy +
Europe*political.knowledge, data=BEPS)
plot(effect("Europe*political.knowledge", mod.beps,
xlevels=list(political.knowledge=0:3)))
plot(effect("Europe*political.knowledge", mod.beps,
xlevels=list(political.knowledge=0:3),
given.values=c(gendermale=0.5)),
style="stacked", colors=c("blue", "red", "orange"), rug=FALSE)
}
if (require(MASS)){
mod.wvs <- polr(poverty ~ gender + religion + degree + country*poly(age,3),
data=WVS)
plot(effect("country*poly(age, 3)", mod.wvs))
plot(effect("country*poly(age, 3)", mod.wvs), style="stacked",
colors=c("gray75", "gray50", "gray25"))
plot(effect("country*poly(age, 3)", latent=TRUE, mod.wvs))
}
mod.pres <- lm(prestige ~ log(income, 10) + poly(education, 3) + poly(women, 2),
data=Prestige)
eff.pres <- allEffects(mod.pres, default.levels=50)
plot(eff.pres)
plot(eff.pres[1:2])
plot(eff.pres[1],
transform.x=list(income=list(trans=log10, inverse=function(x) 10^x)),
ticks.x=list(income=list(at=c(1000, 2000, 5000, 10000, 20000))))
restoreStrip(.save.strip)
remove(.save.strip)
Run the code above in your browser using DataLab