Learn R Programming

rmngb (version 0.6-1)

rDist: Generate Random Numbers from a Gaussian Kernel Density Estimation

Description

The function rDist returns a random generation function for a distribution computed through a gaussian kernel density estimate.

Usage

rDist(x, ...) "plot"(x, ...)

Arguments

x
the data from which the estimate is to be computed.
...
additional arguments passed to density.

Value

A function of class rDist.

Details

rDist uses the density function to compute a gaussian kernel density estimation of x. Additional arguments can be passed to density through .... It returns a function that can be used to generate random values from this estimated density.

It is also possible to have a look at the kernel density estimate by calling plot on the returned function.

See Also

density, rnorm.

Examples

Run this code
x <- c(rnorm(100), rnorm(100, 4))

rTest <- rDist(x)
plot(rTest) # look at the estimate
rTest(10) # generate random values from the estimate
hist(rTest(1e3)) # density of randomly generated values

Run the code above in your browser using DataLab