rDist: Generate Random Numbers from a Gaussian Kernel Density...

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/resampling.R

Description

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

Usage

1
2
3
rDist(x, ...)
## S3 method for class 'rDist'
plot(x, ...)

Arguments

x

the data from which the estimate is to be computed.

...

additional arguments passed to density.

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.

Value

A function of class rDist.

Note

density is actually only used to compute a bandwidth and for its plotting method.

Only a gaussian kernel can be used.

Author(s)

Antoine Filipovic Pierucci

See Also

density, rnorm.

Examples

1
2
3
4
5
6
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

Example output

 [1]  0.7459395 -0.4485749 -0.2217021  4.0934278  2.5096176  2.0857022
 [7] -1.0157183  2.9213888  2.4939764  5.1473008

rmngb documentation built on May 29, 2017, 9:22 p.m.

Related to rDist in rmngb...