Description Usage Arguments Value Acknowledgements Note Author(s) References See Also Examples
Compute bivariate kernel density estimate using five parameter Gaussian kernels which can also use non equally spaced and adaptive bandwidths
1 2 |
x |
vector of |
y |
vector of |
xgridsize |
integer for number of ordinates at which to calculate the smoothed estimate: default=100 |
ygridsize |
integer for number of ordinates at which to calculate the smoothed estimate: default=100 |
correlation |
|
xbandwidth |
value of |
ybandwidth |
value of |
range.x |
total range of the estimate in the |
range.y |
total range of the estimate in the |
na.rm |
NA behaviour: |
returns two vectors and a matrix:
xords |
vector of ordinates at which the density has been estimated in the |
yords |
vector of ordinates at which the density has been estimated in the |
zden |
matrix of density for |
Written in collaboration with A.M.Pollard <mark.pollard@rlaha.ox.ac.uk> with the financial support of the Natural Environment Research Council (NERC) grant GR3/11395
Slow code suitable for visualisation and display of correlated p.d.f, where highly generalised k.p.d.fs are needed - bkde2D
is much faster when uncorrelated, uniformly grided, single bandwidth, k.p.d.fs are required.
This function doesn't use bins as such, it calculates the density at a set of points in each dimension. These points can be thought of as 'bin centres' but in reality they're not.
From version 1.00 onwards a number of improvements have been made: NA's are now handled semi-convincingly by dropping if required. A multi-element vector of bandwidths associated with each case can be sent for either dimension, so it is possible to accept the default, give a fixed bandwidth, or a bandwidth associated with each case. A multi-element vector of correlations can be sent, rather than a single correlation.
It should be noted that if a vector is sent for correlation, or either bandwidth, they must be of the same length as the data vectors. Furthermore, vectors which approximate the bin centres, can be sent rather than the extreme limits in the range; which means that the points at which the density is to be calculated need not be uniformly spaced.
Unlike KernSec
this function does not yet support local bandwidths.
If the default bandwidth
is to be used there must be at least five unique values for in the x
and y
vectors. If not the function will return an error. If you don't have five unique values in the vector then send a value, or vector for bandwidth
The number of ordinates defaults to the length of range.x
if range.x
is a vector of ordinates, otherwise it is xgridsize
, or 100 if that isn't specified.
Finally, the various modes of sending parameters can be mixed, ie: the extremes of the range can be sent to define the range for x
, but a multi-element vector could be sent to define the ordinates in the y
dimension, or, a vector could be sent to describe the bandwidth for each case in the x
direction, and a single-element vector defines all bandwidths in the y
.
Version 1.1-0 has a bugfix in that it now outputs the magnetude of the density function at the specified bi-variate points, not an approximation to the volumes.
David Lucy <d.lucy@lancaster.ac.uk> http://www.maths.lancs.ac.uk/~lucy/
Robert Aykroyd <r.g.aykroyd@leeds.ac.uk>http://www.amsta.leeds.ac.uk/~robert/
Lucy, D. Aykroyd, R.G. & Pollard, A.M.(2002) Non-parametric calibration for age estimation. Applied Statistics 51(2): 183-196
KernSec
per
density
hist
bkde
bkde2D
dpik
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | x <- c(2,4,6,8,10) # make up some x-y data
y <- x
# calculate and plot a surface with zero correlation based on above data
op <- KernSur(x,y, xgridsize=50, ygridsize=50, correlation=0,
xbandwidth=1, ybandwidth=1, range.x=c(0,13), range.y=c(0,13))
image(op$xords, op$yords, op$zden, col=terrain.colors(100), axes=TRUE)
contour(op$xords, op$yords, op$zden, add=TRUE)
box()
# re-calculate and re-plot the above using a 0.8 correlation
op <- KernSur(x,y, xgridsize=50, ygridsize=50, correlation=0.8,
xbandwidth=1, ybandwidth=1, range.x=c(0,13), range.y=c(0,13))
image(op$xords, op$yords, op$zden, col=terrain.colors(100), axes=TRUE)
contour(op$xords, op$yords, op$zden, add=TRUE)
box()
# calculate and plot a surface of the above data with an ascending
# correlation and bandwidths and a vector of equally spaced ordinates
bands <- c(1,1.1,1.2,1.3,1.0)
cors <- c(0,-0.2,-0.4,-0.6, -0.7)
rnge.x <- seq(from=0, to=13, length=100)
op <- KernSur(x,y, xgridsize=50, ygridsize=50, correlation=cors,
xbandwidth=bands, ybandwidth=bands, range.x=rnge.x, range.y=c(0,13))
image(op$xords, op$yords, op$zden, col=terrain.colors(100), axes=TRUE)
contour(op$xords, op$yords, op$zden, add=TRUE)
box()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.