EVOLUTION-MANAGER
Edit File: termplot.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Plot Regression Terms</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for termplot {stats}"><tr><td>termplot {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Plot Regression Terms</h2> <h3>Description</h3> <p>Plots regression terms against their predictors, optionally with standard errors and partial residuals added. </p> <h3>Usage</h3> <pre> 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, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>model</code></td> <td> <p>fitted model object</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>data frame in which variables in <code>model</code> can be found</p> </td></tr> <tr valign="top"><td><code>envir</code></td> <td> <p>environment in which variables in <code>model</code> can be found</p> </td></tr> <tr valign="top"><td><code>partial.resid</code></td> <td> <p>logical; should partial residuals be plotted?</p> </td></tr> <tr valign="top"><td><code>rug</code></td> <td> <p>add <a href="../../graphics/html/rug.html">rug</a>plots (jittered 1-d histograms) to the axes?</p> </td></tr> <tr valign="top"><td><code>terms</code></td> <td> <p>which terms to plot (default <code>NULL</code> means all terms); a vector passed to <code><a href="predict.html">predict</a>(.., type = "terms", terms = *)</code>.</p> </td></tr> <tr valign="top"><td><code>se</code></td> <td> <p>plot pointwise standard errors?</p> </td></tr> <tr valign="top"><td><code>xlabs</code></td> <td> <p>vector of labels for the x axes</p> </td></tr> <tr valign="top"><td><code>ylabs</code></td> <td> <p>vector of labels for the y axes</p> </td></tr> <tr valign="top"><td><code>main</code></td> <td> <p>logical, or vector of main titles; if <code>TRUE</code>, the model's call is taken as main title, <code>NULL</code> or <code>FALSE</code> mean no titles.</p> </td></tr> <tr valign="top"><td><code>col.term, lwd.term</code></td> <td> <p>color and line width for the ‘term curve’, see <code><a href="../../graphics/html/lines.html">lines</a></code>.</p> </td></tr> <tr valign="top"><td><code>col.se, lty.se, lwd.se</code></td> <td> <p>color, line type and line width for the ‘twice-standard-error curve’ when <code>se = TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>col.res, cex, pch</code></td> <td> <p>color, plotting character expansion and type for partial residuals, when <code>partial.resid = TRUE</code>, see <code><a href="../../graphics/html/points.html">points</a></code>.</p> </td></tr> <tr valign="top"><td><code>ask</code></td> <td> <p>logical; if <code>TRUE</code>, the user is <em>ask</em>ed before each plot, see <code><a href="../../graphics/html/par.html">par</a>(ask=.)</code>.</p> </td></tr> <tr valign="top"><td><code>use.factor.levels</code></td> <td> <p>Should x-axis ticks use factor levels or numbers for factor terms?</p> </td></tr> <tr valign="top"><td><code>smooth</code></td> <td> <p><code>NULL</code> or a function with the same arguments as <code><a href="../../graphics/html/panel.smooth.html">panel.smooth</a></code> to draw a smooth through the partial residuals for non-factor terms</p> </td></tr> <tr valign="top"><td><code>lty.smth, col.smth, span.smth</code></td> <td> <p>Passed to <code>smooth</code></p> </td></tr> <tr valign="top"><td><code>ylim</code></td> <td> <p>an optional range for the y axis, or <code>"common"</code> when a range sufficient for all the plot will be computed, or <code>"free"</code> when limits are computed for each plot.</p> </td></tr> <tr valign="top"><td><code>plot</code></td> <td> <p>if set to <code>FALSE</code> plots are not produced: instead a list is returned containing the data that would have been plotted.</p> </td></tr> <tr valign="top"><td><code>transform.x</code></td> <td> <p>logical vector; if an element (recycled as necessary) is <code>TRUE</code>, 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 <code>smooth-panel.smooth</code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>other graphical parameters.</p> </td></tr> </table> <h3>Details</h3> <p>The <code>model</code> object must have a <code>predict</code> method that accepts <code>type = "terms"</code>, e.g., <code><a href="glm.html">glm</a></code> in the <span class="pkg">stats</span> package, <code><a href="../../survival/html/coxph.html">coxph</a></code> and <code><a href="../../survival/html/survreg.html">survreg</a></code> in the <a href="https://CRAN.R-project.org/package=survival"><span class="pkg">survival</span></a> package. </p> <p>For the <code>partial.resid = TRUE</code> option <code>model</code> must have a <code><a href="residuals.html">residuals</a></code> method that accepts <code>type = "partial"</code>, which <code><a href="lm.html">lm</a></code> and <code><a href="glm.html">glm</a></code> do. </p> <p>The <code>data</code> argument should rarely be needed, but in some cases <code>termplot</code> may be unable to reconstruct the original data frame. Using <code>na.action=na.exclude</code> makes these problems less likely. </p> <p>Nothing sensible happens for interaction terms, and they may cause errors. </p> <p>The <code>plot = FALSE</code> option is useful when some special action is needed, e.g. to overlay the results of two different models or to plot confidence bands. </p> <h3>Value</h3> <p>For <code>plot = FALSE</code>, a list with one element for each plot which would have been produced. Each element of the list is a data frame with variables <code>x</code>, <code>y</code>, and optionally the pointwise standard errors <code>se</code>. For continuous predictors <code>x</code> 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 <code>"constant"</code> copied from the predicted terms object. </p> <p>Otherwise, the number of terms, invisibly. </p> <h3>See Also</h3> <p>For (generalized) linear models, <code><a href="plot.lm.html">plot.lm</a></code> and <code><a href="predict.glm.html">predict.glm</a></code>.</p> <h3>Examples</h3> <pre> 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") </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>