Generate random sample from density() or wKDE
This function draws random samples given data
and
a density
estimate (or just
providing the correct bandwidth bw
).
rdensity(n = 100, data = NULL, fhat = NULL, bw = fhat$bw, weights = NULL, kernel = "Gaussian")
n |
number of samples |
fhat |
an object of class
|
weights |
vector of weights. Same length as
|
data |
underlying sample of |
kernel |
kernel choice for |
bw |
choice of bandwidth. Default:
|
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)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.