Learn R Programming

ks (version 1.6.13)

kdde: Kernel density dereivative estimate for multivariate data

Description

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

Usage

kdde(x, H, h, deriv.order, gridsize, gridtype, xmin, xmax, supp=3.7, eval.points, 
    binned=FALSE, bgridsize, positive=FALSE, adj.positive, w)

Arguments

x
matrix of data values
H
bandwidth matrix
h
scalar bandwidth
deriv.order
derivative order
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 is [-supp, supp]
eval.points
points at which density estimate is evaluated
binned
flag for binned estimation (default is FALSE)
bgridsize
vector of binning grid sizes - required if binned=TRUE
positive
flag if 1-d data are positive (default is FALSE)
adj.positive
adjustment added to data i.e. when positive=TRUE KDE is carried out on log(x + adj.positive). Default is the minimum of x.
w
vector of weights (non-negative and sum is equal to sample size)

Value

  • Kernel density estimate is an object of class kde which is a list with 4 fields
  • 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
  • deriv.orderderivative order (scalar)
  • deriv.indeach row is a vector of partial derivative indices of the vectorised derivative (contains duplicates)

Details

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

For d = 1, 2, 3, 4, and if eval.points is specified, then the density derivative estimate is computed exactly at eval.points. For d > 4, the kernel density derivative estimate is computed exactly and eval.points must be specified.

For each partial derivative, for grid estimation, the estimate is a list whose elements correspond to the partial derivative indices in the rows of deriv.ind. For points estimation, the estimate is a matrix whose columns correspond to rows of deriv.ind.

The default xmin is min(x) - Hmax*supp and xmax is max(x) + Hmax*supp where Hmax is the maximim of the diagonal elements of H.

The default weights w is a vector of all ones.

References

Wand, M.P. & Jones, M.C. (1995) Kernel Smoothing. Chapman & Hall. London.

See Also

kde

Examples

Run this code
## univariate example
x <- rnorm.mixt(n=100, mus=1, sigmas=1, props=1)
fhat1 <- kdde(x=x, h=hpi(x), deriv.order=1)      ## df/dx 
fhat2 <- kdde(x=x, h=hpi(x), deriv.order=2)      ## d^2 f/dx^2 

## bivariate example
data(unicef)
H.scv <- Hscv(x=unicef)
fhat1 <- kdde(x=unicef, H=H.scv, deriv.order=1)   ## gradient vector
fhat2 <- kdde(x=unicef, H=H.scv, deriv.order=2)   ## vectorised Hessian matrix

Run the code above in your browser using DataLab