density | R Documentation |
Calculates the Densities of obervation in a 2D cell using Two-dimensional kernel density estimation with an axis-aligned bivariate normal kernel, evaluated on a square grid.
density(x, y, h = c(bandwidth.nrd(x), bandwidth.nrd(y)), n = 11,
lims = c(range(x), range(y)), na.rm = FALSE)
x |
a vector |
y |
a vector |
h |
vector of bandwidths for x and y directions. Defaults to normal reference bandwidth (see bandwidth.nrd). A scalar value will be taken to apply to both directions. |
n |
Number of grid points in each direction. Can be scalar or a length-2 integer vector. |
lims |
The limits of the rectangle covered by the grid as c(xl, xu, yl, yu). |
na.rm |
logical; if true, any NA and NaN's are removed from x before calculations |
a data.frame
with three variables
x, y
coordinates of the grid points, vectors of length n.
z
An n[1] by n[2] matrix of the estimated density: rows correspond to the value of
x, columns to the value of y.
## Not run:
y=rnorm(20)
x =rnorm(20)
density(x,y)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.