Learn R Programming

ks (version 1.8.13)

kde: Kernel density estimate for multivariate data

Description

Kernel density estimate for 1- to 6-dimensional data.

Usage

kde(x, H, h, gridsize, gridtype, xmin, xmax, supp=3.7, eval.points, 
    binned=FALSE, bgridsize, positive=FALSE, adj.positive, w,
    compute.cont=FALSE, approx.cont=TRUE)

Arguments

x
matrix of data values
H,h
bandwidth matrix/scalar bandwidth. If these are missing, Hpi or hpi is called by default.
gridsize
vector of number of grid points
gridtype
not yet implemented
xmin,xmax
vector of minimum/maximum values for grid
supp
effective support for standard normal
eval.points
points at which estimate is evaluated
binned
flag for binned estimation. Default is FALSE.
bgridsize
vector of binning grid sizes
positive
flag if 1-d data are positive. Default is FALSE.
adj.positive
adjustment applied to positive 1-d data
w
vector of weights. Default is a vector of all ones.
compute.cont
flag for computing 1% to 99% probability contour levels. Default is FALSE.
approx.cont
flag for computing approximate probability contour levels. Default is TRUE.

Value

  • A kernel density estimate is an object of class kde which is a list with fields:
  • xdata points - same as input
  • eval.pointspoints at which the estimate is evaluated
  • estimatedensity estimate at eval.points
  • hscalar bandwidth (1-d only)
  • Hbandwidth matrix
  • gridtype"linear"
  • griddedflag for estimation on a grid
  • binnedflag for binned estimation
  • namesvariable names
  • wweights
  • contprobability contour levels (if compute.cont=TRUE)

Details

For d=1, if h is missing, the default bandwidth is hpi(x=x, nstage=2, binned=TRUE), and for d>1, if H is missing, the default is Hpi(x=x, nstage=2, binned=n>1000, pilot="samse").

supp is the effective support for a normal kernel, i.e. all values outside [-supp,supp]^d are set to zero. The default xmin is min(x)-Hmax*supp and xmax is max(x)+Hmax*supp where Hmax is the maximum of the diagonal elements of H.The default weights w is a vector of all ones.

For d=1, 2, 3, 4, and if eval.points is not specified, then the density estimate is computed over a grid defined by gridsize (if binned=FALSE) or by bgridsize (if binned=TRUE). If eval.points is specified, then the density estimate is computed exactly at eval.points. For d>4, the kernel density estimate is computed exactly and eval.points must be specified.

For d=1, if positive=TRUE then x<-log(x+adj.positive) where the default adj.positive is the minimum of x.

See Also

plot.kde

Examples

Run this code
## positive data example
x <- 2^rnorm(100)
fhat <- kde(x=x, positive=TRUE)
plot(fhat)

## See other examples in ? plot.kde

Run the code above in your browser using DataLab