Learn R Programming

ks (version 1.8.11)

dkde: Functions for univariate kernel density estimates

Description

Functions for 1-dimensional kernel density estimates.

Usage

pkde(q, fhat)
 qkde(p, fhat)
 dkde(x, fhat)
 rkde(n, fhat, positive=FALSE)

Arguments

x,q
vector of quantiles
p
vector of probabilities
n
number of observations
positive
flag to compute KDE on the positive real line. Default is FALSE.
fhat
kernel density estimate, object of class "kde"

Value

  • For the kernel density estimate fhat, pkde computes the cumulative probability for the quantile q, qkde computes the quantile corresponding to the probability p, dkde computes the density value at x and rkde computes a random sample of size n.

Details

pkde uses Simpson's rule for the numerical integration. rkde uses Silverman (1986)'s method to generate a random sample from a KDE.

References

Silverman, B. (1986) Density Estimation for Statistics and Data Analysis. Chapman & Hall/CRC. London.

Examples

Run this code
x <- rnorm.mixt(n=10000, mus=0, sigmas=1, props=1)
fhat <- kde(x=x, h=hpi(x))
p1 <- pkde(fhat=fhat, q=c(-1, 0, 0.5))
qkde(fhat=fhat, p=p1)    
y <- rkde(fhat=fhat, n=100)

## positive data example
z <- 2^x
fhatz <- kde(x=z, h=hpi(log(z)), positive=TRUE)
z2 <- rkde(fhat=fhatz, n=10000, positive=TRUE)
fhatz2 <- kde(x=z2, h=hpi(log(z2)), positive=TRUE)
plot(fhatz, xlim=c(0,10))
plot(fhatz2, add=TRUE, col=2)

Run the code above in your browser using DataLab