fkde: Fast Kernel Density Estimation

Description Usage Arguments Examples

View source: R/FKDE_R_FUNCTIONS.R

Description

Evaluates a kernel based estimate of a density function from a univariate sample. The default is to evaluate the density at all of the sample points. Optional evaluation on a grid is also available by setting argument ngrid to non-zero value.

Usage

1
fkde(x, h, ord, ngrid, nbin, m, M, hnorm)

Arguments

x

vector of (univariate) sample observations.

h

(optional) bandwidth used in density estimate. If omitted then Silverman's rule of thumb is used.

ord

(optional) degree of polynomial part of the kernel function.

ngrid

(optional) number of evaluation points if evaluation on a grid is desired.

nbin

(optional) number of bins to use if approximate density estimate is desired instead of exact.

m

(optional) minimum evaluation point if grid evaluation or binned approximation required. Defaults to min(x)-6*h

M

(optional) maxmimum evaluation point if grid evaluation or binned approximation required. Defaults to max(x)+6*h

hnorm

(optional) to make implementation compatible with existing R functions for bandwidth selection, which usually by default provide the bandwidth value for the Gaussian kernel. If hnorm is provided then fkde will convert this to the corresponding value for the kernel being used, based on the AMISE value relative to that of the Gaussian.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# generate a sample of size 1000000 from heavily skewed density
x <- dataGen(1000000, 5)

# obtain exact kernel estimate and a binned approximation on a grid of 1000 points
system.time(f_exact <- fkde(x, ngrid = 1000))
system.time(f_binned <- fkde(x, nbin = 1000))

# estimate the MISE
MISE(5, f_exact$x, f_exact$y)
MISE(5, f_binned$x, f_binned$y)

DavidHofmeyr/fkde documentation built on June 5, 2018, 5:45 p.m.