GenKern (version 1.2-60)

KernSur: Bivariate kernel density estimation

Description

Compute bivariate kernel density estimate using five parameter Gaussian kernels which can also use non equally spaced and adaptive bandwidths

Usage

KernSur(x, y, xgridsize=100, ygridsize=100, correlation, xbandwidth, ybandwidth, range.x, range.y, na.rm=FALSE)

Arguments

x
vector of x values
y
vector of y values
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
x,y correlation, or vector of local correlations: default=cor(x,y)
xbandwidth
value of x window width, or vector of local window widths: default=dpik(x)
ybandwidth
value of y window width, or vector of local window widths: default=dpik(y)
range.x
total range of the estimate in the x dimension, or a vector giving the x ordinates: default=range +- 1.5 * mean bandwidth
range.y
total range of the estimate in the y dimension, or a vector giving the y ordinates: default=range +- 1.5 * mean bandwidth
na.rm
NA behaviour: TRUE drops cases with NA's, FALSE stops function with a warning if NA's are detected: default=FALSE

Value

xords
vector of ordinates at which the density has been estimated in the x dimension
yords
vector of ordinates at which the density has been estimated in the y dimension
zden
matrix of density for f(x,y) with dimensions xgridsize, ygridsize

Acknowledgements

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

References

Lucy, D. Aykroyd, R.G. & Pollard, A.M.(2002) Non-parametric calibration for age estimation. Applied Statistics 51(2): 183-196

See Also

KernSec per density hist bkde bkde2D dpik

Examples

Run this code
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()

Run the code above in your browser using DataLab