Learn R Programming

ks (version 1.8.11)

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
bandwidth matrix(ces)
h
scalar bandwidth(s)
gridsize
vector of number of grid points
gridtype
not yet implemented
xmin
vector of minimum values for grid
xmax
vector of maximum values for grid
supp
effective support for standard normal.
eval.points
points at which density 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 data x <- log(x + adj.positive) when positive=TRUE. Default is the minimum of x.
w
vector of weights (non-negative and sum is equal to sample size). Default is a vector of all ones.
compute.cont
flag for computing probability contour levels from 1% to 99%. 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:
  • xdata points - same as input
  • eval.pointspoints at which the density estimate is evaluated
  • estimatedensity estimate at eval.points
  • Hbandwidth matrix
  • hscalar bandwidth (1-d only)
  • wweights
  • contprobability contour levels

Details

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.

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.

See Also

plot.kde

Examples

Run this code
## trivariate example
library(MASS)
x <- iris[,1:3]
H.pi <- Hpi(x, pilot="dscalar")
fhat <- kde(x, H=H.pi, compute.cont=TRUE)  
plot(fhat, drawpoints=TRUE)

## See other examples in ? plot.kde

Run the code above in your browser using DataLab