EVOLUTION-MANAGER
Edit File: cdplot.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: Conditional Density Plots</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 cdplot {graphics}"><tr><td>cdplot {graphics}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Conditional Density Plots</h2> <h3>Description</h3> <p>Computes and plots conditional densities describing how the conditional distribution of a categorical variable <code>y</code> changes over a numerical variable <code>x</code>. </p> <h3>Usage</h3> <pre> cdplot(x, ...) ## Default S3 method: cdplot(x, y, plot = TRUE, tol.ylab = 0.05, ylevels = NULL, bw = "nrd0", n = 512, from = NULL, to = NULL, col = NULL, border = 1, main = "", xlab = NULL, ylab = NULL, yaxlabels = NULL, xlim = NULL, ylim = c(0, 1), ...) ## S3 method for class 'formula' cdplot(formula, data = list(), plot = TRUE, tol.ylab = 0.05, ylevels = NULL, bw = "nrd0", n = 512, from = NULL, to = NULL, col = NULL, border = 1, main = "", xlab = NULL, ylab = NULL, yaxlabels = NULL, xlim = NULL, ylim = c(0, 1), ..., subset = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>an object, the default method expects a single numerical variable (or an object coercible to this).</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>a <code>"factor"</code> interpreted to be the dependent variable</p> </td></tr> <tr valign="top"><td><code>formula</code></td> <td> <p>a <code>"formula"</code> of type <code>y ~ x</code> with a single dependent <code>"factor"</code> and a single numerical explanatory variable.</p> </td></tr> <tr valign="top"><td><code>data</code></td> <td> <p>an optional data frame.</p> </td></tr> <tr valign="top"><td><code>plot</code></td> <td> <p>logical. Should the computed conditional densities be plotted?</p> </td></tr> <tr valign="top"><td><code>tol.ylab</code></td> <td> <p>convenience tolerance parameter for y-axis annotation. If the distance between two labels drops under this threshold, they are plotted equidistantly.</p> </td></tr> <tr valign="top"><td><code>ylevels</code></td> <td> <p>a character or numeric vector specifying in which order the levels of the dependent variable should be plotted.</p> </td></tr> <tr valign="top"><td><code>bw, n, from, to, ...</code></td> <td> <p>arguments passed to <code><a href="../../stats/html/density.html">density</a></code></p> </td></tr> <tr valign="top"><td><code>col</code></td> <td> <p>a vector of fill colors of the same length as <code>levels(y)</code>. The default is to call <code><a href="../../grDevices/html/gray.colors.html">gray.colors</a></code>.</p> </td></tr> <tr valign="top"><td><code>border</code></td> <td> <p>border color of shaded polygons.</p> </td></tr> <tr valign="top"><td><code>main, xlab, ylab</code></td> <td> <p>character strings for annotation</p> </td></tr> <tr valign="top"><td><code>yaxlabels</code></td> <td> <p>character vector for annotation of y axis, defaults to <code>levels(y)</code>.</p> </td></tr> <tr valign="top"><td><code>xlim, ylim</code></td> <td> <p>the range of x and y values with sensible defaults.</p> </td></tr> <tr valign="top"><td><code>subset</code></td> <td> <p>an optional vector specifying a subset of observations to be used for plotting.</p> </td></tr> </table> <h3>Details</h3> <p><code>cdplot</code> computes the conditional densities of <code>x</code> given the levels of <code>y</code> weighted by the marginal distribution of <code>y</code>. The densities are derived cumulatively over the levels of <code>y</code>. </p> <p>This visualization technique is similar to spinograms (see <code><a href="spineplot.html">spineplot</a></code>) and plots <i>P(y | x)</i> against <i>x</i>. The conditional probabilities are not derived by discretization (as in the spinogram), but using a smoothing approach via <code><a href="../../stats/html/density.html">density</a></code>. </p> <p>Note, that the estimates of the conditional densities are more reliable for high-density regions of <i>x</i>. Conversely, the are less reliable in regions with only few <i>x</i> observations. </p> <h3>Value</h3> <p>The conditional density functions (cumulative over the levels of <code>y</code>) are returned invisibly. </p> <h3>Author(s)</h3> <p>Achim Zeileis <a href="mailto:Achim.Zeileis@R-project.org">Achim.Zeileis@R-project.org</a> </p> <h3>References</h3> <p>Hofmann, H., Theus, M. (2005), <em>Interactive graphics for visualizing conditional distributions</em>, Unpublished Manuscript. </p> <h3>See Also</h3> <p><code><a href="spineplot.html">spineplot</a></code>, <code><a href="../../stats/html/density.html">density</a></code> </p> <h3>Examples</h3> <pre> ## NASA space shuttle o-ring failures fail <- factor(c(2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1), levels = 1:2, labels = c("no", "yes")) temperature <- c(53, 57, 58, 63, 66, 67, 67, 67, 68, 69, 70, 70, 70, 70, 72, 73, 75, 75, 76, 76, 78, 79, 81) ## CD plot cdplot(fail ~ temperature) cdplot(fail ~ temperature, bw = 2) cdplot(fail ~ temperature, bw = "SJ") ## compare with spinogram (spineplot(fail ~ temperature, breaks = 3)) ## highlighting for failures cdplot(fail ~ temperature, ylevels = 2:1) ## scatter plot with conditional density cdens <- cdplot(fail ~ temperature, plot = FALSE) plot(I(as.numeric(fail) - 1) ~ jitter(temperature, factor = 2), xlab = "Temperature", ylab = "Conditional failure probability") lines(53:81, 1 - cdens[[1]](53:81), col = 2) </pre> <hr /><div style="text-align: center;">[Package <em>graphics</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>