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
\hat{f_H}(\mathbf{x}) = \sum_{i=1}^n w_i \prod_{j=1}^m
K_{h_j}( x_i - y_{ij})
where w
is a vector of weights such that all w_i \ge 0
and \sum_i w_i = 1
(by default uniform 1/n
weights are used),
K_{h_j}
is univariate kernel K
parametrized by bandwidth h_j
,
where \boldsymbol{y}
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))