rmvk {kernelboot} | R Documentation |
Random generation from product kernel density
Description
Random generation from product kernel density
Usage
rmvk(
n,
y,
bw = sqrt(diag(bw.silv(y))),
kernel = c("gaussian", "epanechnikov", "rectangular", "triangular", "biweight",
"cosine", "optcosine"),
weights = NULL,
adjust = 1,
shrinked = FALSE
)
Arguments
n |
number of observations. If |
y |
numeric matrix or data.frame. |
bw |
numeric vector of length equal to |
kernel |
a character string giving the smoothing kernel to be used. This must partially match one of "gaussian", "rectangular", "triangular", "epanechnikov", "biweight", "cosine" or "optcosine", with default "gaussian", and may be abbreviated. |
weights |
numeric vector of length equal to |
adjust |
scalar; the bandwidth used is actually |
shrinked |
if |
Details
Product kernel density is defined in terms of independent univariate kernels
where is a vector of weights such that all
and
(by default uniform
weights are used),
is univariate kernel
parametrized by bandwidth
,
where
is a matrix of data points used for estimating the
kernel density.
For functions estimating kernel densities please check KernSmooth, ks, or other packages reviewed by Deng and Wickham (2011).
For random generation the algorithm described in kernelboot
is used.
When using shrinked = TRUE
, random noise is drawn from independent, shrinked
univariate kernels.
References
Deng, H. and Wickham, H. (2011). Density estimation in R. http://vita.had.co.nz/papers/density-estimation.pdf
See Also
Examples
dat <- mtcars[, c("mpg", "disp")]
partmp <- par(mfrow = c(1, 2), mar = c(3, 3, 3, 3))
plot(rmvk(5000, dat, shrinked = FALSE), col = "#458B004D", pch = 16,
xlim = c(0, 45), ylim = c(-200, 800),
main = "Product kernel", axes = FALSE)
points(dat, pch = 2, lwd = 2, col = "red")
axis(1); axis(2)
plot(rmvk(5000, dat, shrinked = TRUE), col = "#458B004D", pch = 16,
xlim = c(0, 45), ylim = c(-200, 800),
main = "Product kernel (shrinked)", axes = FALSE)
points(dat, pch = 2, lwd = 2, col = "red")
axis(1); axis(2)
par(partmp)
cov(dat)
cov(rmvk(5000, dat, shrinked = FALSE))
cov(rmvk(5000, dat, shrinked = TRUE))