| 27442 |
ripley |
1 |
\name{termplot}
|
|
|
2 |
\alias{termplot}
|
|
|
3 |
\title{Plot regression terms}
|
|
|
4 |
\description{
|
|
|
5 |
Plots regression terms against their predictors, optionally with
|
|
|
6 |
standard errors and partial residuals added.
|
|
|
7 |
}
|
|
|
8 |
\usage{
|
|
|
9 |
termplot(model, data=NULL, envir=environment(formula(model)),
|
|
|
10 |
partial.resid=FALSE, rug=FALSE,
|
|
|
11 |
terms=NULL, se=FALSE, xlabs=NULL, ylabs=NULL, main = NULL,
|
|
|
12 |
col.term = 2, lwd.term = 1.5,
|
|
|
13 |
col.se = "orange", lty.se = 2, lwd.se = 1,
|
|
|
14 |
col.res = "gray", cex = 1, pch = par("pch"),
|
| 28044 |
tlumley |
15 |
col.smth = "darkred", lty.smth=2, span.smth=2/3,
|
| 27442 |
ripley |
16 |
ask = interactive() && nb.fig < n.tms && .Device !="postscript",
|
| 28044 |
tlumley |
17 |
use.factor.levels=TRUE, smooth=NULL,
|
| 27442 |
ripley |
18 |
\dots)
|
|
|
19 |
}
|
|
|
20 |
\arguments{
|
|
|
21 |
\item{model}{fitted model object}
|
|
|
22 |
\item{data}{data frame in which variables in \code{model} can be
|
|
|
23 |
found}
|
|
|
24 |
\item{envir}{environment in which variables in \code{model} can be found}
|
|
|
25 |
\item{partial.resid}{logical; should partial residuals be plotted?}
|
|
|
26 |
\item{rug}{add \link{rug}plots (jittered 1-d histograms) to the axes?}
|
|
|
27 |
\item{terms}{which terms to plot (default \code{NULL} means all terms)}
|
|
|
28 |
\item{se}{plot pointwise standard errors?}
|
|
|
29 |
\item{xlabs}{vector of labels for the x axes}
|
|
|
30 |
\item{ylabs}{vector of labels for the y axes}
|
|
|
31 |
\item{main}{logical, or vector of main titles; if \code{TRUE}, the
|
|
|
32 |
model's call is taken as main title, \code{NULL} or \code{FALSE} mean
|
|
|
33 |
no titles.}
|
|
|
34 |
\item{col.term, lwd.term}{color and line width for the \dQuote{term curve},
|
|
|
35 |
see \code{\link{lines}}.}
|
|
|
36 |
\item{col.se, lty.se, lwd.se}{color, line type and line width for the
|
|
|
37 |
\dQuote{twice-standard-error curve} when \code{se = TRUE}.}
|
|
|
38 |
\item{col.res, cex, pch}{color, plotting character expansion and type
|
|
|
39 |
for partial residuals, when \code{partial.resid = TRUE}, see
|
|
|
40 |
\code{\link{points}}.}
|
|
|
41 |
\item{ask}{logical; if \code{TRUE}, the user is \emph{ask}ed before
|
|
|
42 |
each plot, see \code{\link{par}(ask=.)}.}
|
|
|
43 |
\item{use.factor.levels}{Should x-axis ticks use factor levels or
|
|
|
44 |
numbers for factor terms?}
|
| 28044 |
tlumley |
45 |
\item{smooth}{\code{NULL} or a function with the same arguments as
|
|
|
46 |
\code{\link{panel.smooth}} to draw a smooth through the partial
|
|
|
47 |
residuals for non-factor terms}
|
|
|
48 |
\item{lty.smth,col.smth, span.smth}{Passed to \code{smooth}}
|
| 27442 |
ripley |
49 |
\item{\dots}{other graphical parameters}
|
|
|
50 |
}
|
|
|
51 |
\details{
|
|
|
52 |
The model object must have a \code{predict} method that accepts
|
| 27625 |
ripley |
53 |
\code{type=terms}, eg \code{\link{glm}} in the \pkg{base} package,
|
| 27442 |
ripley |
54 |
\code{\link[survival]{coxph}} and \code{\link[survival]{survreg}} in
|
|
|
55 |
the \pkg{survival} package.
|
|
|
56 |
|
|
|
57 |
For the \code{partial.resid=TRUE} option it must have a
|
|
|
58 |
\code{\link{residuals}} method that accepts \code{type="partial"},
|
|
|
59 |
which \code{\link{lm}} and \code{\link{glm}} do.
|
|
|
60 |
|
|
|
61 |
The \code{data} argument should rarely be needed, but in some cases
|
|
|
62 |
\code{termplot} may be unable to reconstruct the original data frame.
|
|
|
63 |
|
|
|
64 |
Nothing sensible happens for interaction terms.
|
|
|
65 |
}
|
|
|
66 |
\seealso{For (generalized) linear models, \code{\link{plot.lm}} and
|
|
|
67 |
\code{\link{predict.glm}}.}
|
|
|
68 |
\examples{
|
|
|
69 |
had.splines <- "package:splines" \%in\% search()
|
|
|
70 |
if(!had.splines) rs <- require(splines)
|
|
|
71 |
x <- 1:100
|
|
|
72 |
z <- factor(rep(LETTERS[1:4],25))
|
|
|
73 |
y <- rnorm(100,sin(x/10)+as.numeric(z))
|
|
|
74 |
model <- glm(y ~ ns(x,6) + z)
|
|
|
75 |
|
|
|
76 |
par(mfrow=c(2,2)) ## 2 x 2 plots for same model :
|
|
|
77 |
termplot(model, main = paste("termplot( ", deparse(model$call)," ...)"))
|
|
|
78 |
termplot(model, rug=TRUE)
|
|
|
79 |
termplot(model, partial=TRUE, se = TRUE, main = TRUE)
|
| 28044 |
tlumley |
80 |
termplot(model, partial=TRUE, smooth=panel.smooth,span.smth=1/4)
|
| 27442 |
ripley |
81 |
if(!had.splines && rs) detach("package:splines")
|
|
|
82 |
}
|
|
|
83 |
\keyword{hplot}
|
|
|
84 |
\keyword{regression}
|