powered by
This function draws random samples given data and a density estimate (or just providing the correct bandwidth bw).
data
density
bw
rdensity(n = 100, data = NULL, fhat = NULL, bw = fhat$bw, weights = NULL, kernel = "Gaussian")
number of samples
an object of class 'density' for bandwidth selection (if bw is not explicitly provided as argument)
'density'
vector of weights. Same length as data. Default weights=NULL - in this case equal weights for each point
weights=NULL
underlying sample of fhat
fhat
kernel choice for fhat. Default: kernel='Gaussian'. See density for other options.
kernel='Gaussian'
choice of bandwidth. Default: bw=fhat$bw. Again see density for other options.
bw=fhat$bw
# NOT RUN { set.seed(1923) xx <- c(rnorm(100, mean = 2), runif(100)) aa <- density(xx) plot(aa) xx_sample <- rdensity(n = 1000, fhat = aa, data = xx) lines(density(xx_sample), col = 2) # }
Run the code above in your browser using DataLab