rmvg {kernelboot} | R Documentation |
Random generation from multivariate Gaussian kernel density
Description
Random generation from multivariate Gaussian kernel density
Usage
rmvg(n, y, bw = bw.silv(y), weights = NULL, adjust = 1)
Arguments
n |
number of observations. If |
y |
numeric matrix or data.frame. |
bw |
numeric matrix with number of rows and columns equal to
|
weights |
numeric vector of length equal to |
adjust |
scalar; the bandwidth used is actually |
Details
Multivariate kernel density estimator with multivariate Gaussian (normal) kernels
is defined as
where is a vector of weights such that all
and
(by default uniform
weights are used),
is kernel
parametrized by bandwidth matrix
and
is a matrix of data points used for estimating the kernel density.
Random generation from multivariate normal distribution is possible by taking
where is a vector of
i.i.d. standard normal deviates,
is a vector of means and
is a
matrix such that
(
is a Cholesky
factor of
). In the case of multivariate Gaussian kernel
density,
, is the
-th row of
,
where
is drawn randomly with replacement with probability
proportional to
, and
is the bandwidth
matrix
.
For functions estimating kernel densities please check KernSmooth, ks, or other packages reviewed by Deng and Wickham (2011).
References
Deng, H. and Wickham, H. (2011). Density estimation in R. http://vita.had.co.nz/papers/density-estimation.pdf
See Also
Examples
set.seed(1)
dat <- mtcars[, c(1,3)]
bw <- bw.silv(dat)
X <- rmvg(5000, dat, bw = bw)
if (requireNamespace("ks", quietly = TRUE)) {
pal <- colorRampPalette(c("chartreuse4", "yellow", "orange", "brown"))
col <- pal(10)[cut(ks::kde(dat, H = bw, eval.points = X)$estimate, breaks = 10)]
plot(X, col = col, pch = 19, axes = FALSE,
main = "Multivariate Gaussian Kernel")
points(dat, pch = 2, col = "blue")
axis(1); axis(2)
} else {
plot(X, pch = 16, axes = FALSE, col = "#458B004D",
main = "Multivariate Gaussian Kernel")
points(dat, pch = 2, col = "red", lwd = 2)
axis(1); axis(2)
}