bandplot.html 3.62 KB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>R: Plot x-y Points with Locally Smoothed Mean and Standard Deviation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../R.css">
</head><body>

<table width="100%" summary="page for bandplot {gplots}"><tr><td>bandplot {gplots}</td><td align="right">R Documentation</td></tr></table>
<h2>Plot x-y Points with Locally Smoothed Mean and Standard Deviation</h2>


<h3>Description</h3>

<p>
Plot x-y Points with lines showing the locally smoothed mean and
standard deviation.
</p>


<h3>Usage</h3>

<pre>
  bandplot(x, y, ..., add = FALSE, sd = c(-2:2),
           sd.col = c("lightblue", "blue", "red", "blue", "lightblue"),
           method = "frac", width = 1/5, n=50) 
</pre>


<h3>Arguments</h3>

<table summary="R argblock">
<tr valign="top"><td><code>x</code></td>
<td>
numeric vector of x locations</td></tr>
<tr valign="top"><td><code>y</code></td>
<td>
numeric vector of x locations</td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
Additional plotting parameters. </td></tr>
<tr valign="top"><td><code>add</code></td>
<td>
Boolean indicating whether the local mean and standard
deviation lines should be added to an existing plot.  Defaults to
FALSE.</td></tr>
<tr valign="top"><td><code>sd</code></td>
<td>
Vector of multiples of the standard devation that should be
plotted.  <code>0</code> gives the mean, <code>-1</code> gives the mean minus
one standard deviation, etc.  Defaults to -2:2.</td></tr>
<tr valign="top"><td><code>sd.col</code></td>
<td>
Color of each plotted line.</td></tr>
<tr valign="top"><td><code>method, width, n</code></td>
<td>
Parameters controlling the smoothing. See the
help page for <code><a href="wapply.html">wapply</a></code> for details.</td></tr>
</table>

<h3>Details</h3>

<p>
<code>bandplot</code> was created to look for changes in the mean or
variance of scatter plots, particularly plots of regression residuals.
</p>
<p>
The local mean and standard deviation are calculated by calling
'wapply'.  By default, bandplot asks wapply to smooth using intervals
that include the nearest 1/5 of the data.  See the documentation of
that function for details on the algorithm.
</p>


<h3>Value</h3>

<p>
Invisibly returns a list containing the x,y points plotted for each line.</p>

<h3>Author(s)</h3>

<p>
Gregory R. Warnes <a href="mailto:warnes@bst.rochester.edu">warnes@bst.rochester.edu</a>
</p>


<h3>See Also</h3>

<p>
<code><a href="wapply.html">wapply</a></code>, <code><a href="lowess.html">lowess</a></code>
</p>


<h3>Examples</h3>

<pre>

# fixed mean, changing variance
x &lt;- 1:1000
y &lt;- rnorm(1000, mean=1, sd=1 + x/1000 )
bandplot(x,y)

# fixed varance, changing mean
x &lt;- 1:1000
y &lt;- rnorm(1000, mean=x/1000, sd=1)
bandplot(x,y)

#
# changing mean and variance
#
x &lt;- abs(rnorm(500))
y &lt;- rnorm(500, mean=2*x, sd=2+2*x)

# the changing mean and dispersion are hard to see whith the points alone:
plot(x,y )

# regression picks up the mean trend, but not the change in variance
reg &lt;- lm(y~x)
summary(reg)

# using bandplot on the original data helps to show the mean and
# variance trend
bandplot(x,y)

# using bandplot on the residuals helps to see that regression removes
# the mean trend but leaves the trend in variability
bandplot(predict(reg),resid(reg))

</pre>



<hr><div align="center">[Package <em>gplots</em> version 2.3.2 <a href="00Index.html">Index]</a></div>

</body></html>