Description Usage Arguments Value Author(s) References See Also Examples
densityPlot
contructs and graphs nonparametric density estimates, possibly conditioned on a factor.
By default it uses the standard R density
function or optionally adaptiveKernel
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | densityPlot(x, ...)
## Default S3 method:
densityPlot(x, g, method=c("kernel", "adaptive"),
bw=if (method == "adaptive") bw.nrd0 else "SJ", adjust=1,
kernel, xlim, ylim, normalize=FALSE,
xlab=deparse(substitute(x)), ylab="Density",
col=palette(), lty=seq_along(col), lwd=2, grid=TRUE,
legend.location="topright", legend.title=deparse(substitute(g)), show.bw=FALSE,
rug=TRUE, ...)
## S3 method for class 'formula'
densityPlot(formula, data = NULL, subset,
na.action = NULL, xlab, ylab, ...)
adaptiveKernel(x, kernel=dnorm, bw=bw.nrd0, adjust=1.0, n=500,
from, to, cut=3, na.rm=TRUE)
|
x |
a numeric variable, the density of which is estimated. |
g |
an optional factor to divide the data. |
formula |
an R model formula, of the form |
data |
an optional data frame containing the data. |
subset |
an optional vector defining a subset of the data. |
na.action |
a function to handle missing values; defaults to the value of the R |
method |
either |
bw |
the geometric mean bandwidth for the adaptive-kernel or bandwidth of the kernel density estimate(s). Must be a numerical value
or a function to compute the bandwidth (default |
adjust |
a multiplicative adjustment factor for the bandwidth; the default, |
kernel |
for |
xlim, ylim |
axis limits; if missing, determined from the range of x-values at which the densities are estimated and the estimated densities. |
normalize |
if |
xlab |
label for the horizontal-axis; defaults to the name of the variable |
ylab |
label for the vertical axis; defaults to |
col |
vector of colors for the density estimate(s); defaults to the color |
lty |
vector of line types for the density estimate(s); defaults to the successive integers, starting at 1. |
lwd |
line width for the density estimate(s); defaults to 2. |
grid |
if |
legend.location |
location for the legend when densities are plotted for several groups; defaults to
|
legend.title |
label for the legend, which is drawn if densities are plotted by groups; the default is the name of the factor g. |
n |
number of equally spaced points at which the adaptive-kernel estimator is evaluated; the default is |
from, to, cut |
the range over which the density estimate is computed; the default, if missing, is |
na.rm |
remove missing values from |
show.bw |
if |
rug |
if |
... |
arguments to be passed down. |
densityPlot
invisibly returns the "density"
object computed (or list of "density"
objects) and draws a graph.
adaptiveKernel
returns an object of class "density"
(see density)
.
John Fox jfox@mcmaster.ca
W. N. Venables and B. D. Ripley (2002) Modern Applied Statistics with S. New York: Springer.
B.W. Silverman (1986) Density Estimation for Statistics and Data Analysis. London: Chapman and Hall.
1 2 3 4 5 6 7 8 9 10 11 | densityPlot(~ income, show.bw=TRUE, data=Prestige)
densityPlot(~ income, method="adaptive", show.bw=TRUE, data=Prestige)
densityPlot(~ income, method="adaptive", from=0, normalize=TRUE, show.bw=TRUE, data=Prestige)
densityPlot(income ~ type, method="adaptive", data=Prestige)
plot(adaptiveKernel(UN$infant.mortality, from=0, adjust=0.75), col="magenta")
lines(density(na.omit(UN$infant.mortality), from=0, adjust=0.75), col="blue")
rug(UN$infant.mortality, col="cyan")
legend("topright", col=c("magenta", "blue"), lty=1,
legend=c("adaptive kernel", "kernel"), inset=0.02)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.