
Last chance! 50% off unlimited learning
Sale ends in
termplot(model, data = NULL, envir = environment(formula(model)), partial.resid = FALSE, rug = FALSE, terms = NULL, se = FALSE, xlabs = NULL, ylabs = NULL, main = NULL, col.term = 2, lwd.term = 1.5, col.se = "orange", lty.se = 2, lwd.se = 1, col.res = "gray", cex = 1, pch = par("pch"), col.smth = "darkred", lty.smth = 2, span.smth = 2/3, ask = dev.interactive() && nb.fig < n.tms, use.factor.levels = TRUE, smooth = NULL, ylim = "common", plot = TRUE, transform.x = FALSE, ...)
model
can be
foundmodel
can be foundNULL
means all
terms); a vector passed to
predict(.., type = "terms", terms = *)
.TRUE
, the
model's call is taken as main title, NULL
or FALSE
mean
no titles.lines
.se = TRUE
.partial.resid = TRUE
, see
points
.TRUE
, the user is asked before
each plot, see par(ask=.)
.NULL
or a function with the same arguments as
panel.smooth
to draw a smooth through the partial
residuals for non-factor termssmooth
"common"
when
a range sufficient for all the plot will be computed, or
"free"
when limits are computed for each plot.FALSE
plots are not produced: instead a
list is returned containing the data that would have been plotted.TRUE
, partial residuals for the corresponding term are
plotted against transformed values.
The model response is then a straight line, allowing a
ready comparison against the data or against the curve
obtained from smooth-panel.smooth
.plot = FALSE
, a list with one element for each plot which
would have been produced. Each element of the list is a data frame
with variables x
, y
, and optionally the pointwise
standard errors se
. For continuous predictors x
will
contain the ordered unique values and for a factor it will be a factor
containing one instance of each level. The list has attribute
"constant"
copied from the predicted terms object.Otherwise, the number of terms, invisibly.
model
object must have a predict
method that accepts
type = "terms"
, e.g., glm
in the stats package,
coxph
and survreg
in
the \href{https://CRAN.R-project.org/package=#1}{\pkg{#1}}survivalsurvival package. For the partial.resid = TRUE
option model
must have a
residuals
method that accepts type = "partial"
,
which lm
and glm
do.
The data
argument should rarely be needed, but in some cases
termplot
may be unable to reconstruct the original data
frame. Using na.action=na.exclude
makes these problems less likely.
Nothing sensible happens for interaction terms, and they may cause errors.
The plot = FALSE
option is useful when some special action is needed,
e.g.\ifelse{latex}{\out{~}}{ } to overlay the results of two different models or to plot
confidence bands.
plot.lm
and
predict.glm
.require(graphics)
had.splines <- "package:splines" %in% search()
if(!had.splines) rs <- require(splines)
x <- 1:100
z <- factor(rep(LETTERS[1:4], 25))
y <- rnorm(100, sin(x/10)+as.numeric(z))
model <- glm(y ~ ns(x, 6) + z)
par(mfrow = c(2,2)) ## 2 x 2 plots for same model :
termplot(model, main = paste("termplot( ", deparse(model$call)," ...)"))
termplot(model, rug = TRUE)
termplot(model, partial.resid = TRUE, se = TRUE, main = TRUE)
termplot(model, partial.resid = TRUE, smooth = panel.smooth, span.smth = 1/4)
if(!had.splines && rs) detach("package:splines")
## requires recommended package MASS
hills.lm <- lm(log(time) ~ log(climb)+log(dist), data = MASS::hills)
termplot(hills.lm, partial.resid = TRUE, smooth = panel.smooth,
terms = "log(dist)", main = "Original")
termplot(hills.lm, transform.x = TRUE,
partial.resid = TRUE, smooth = panel.smooth,
terms = "log(dist)", main = "Transformed")
Run the code above in your browser using DataLab