Random generation from product kernel density
Random generation from product kernel density
rmvk( n, y, bw = sqrt(diag(bw.silv(y))), kernel = c("gaussian", "epanechnikov", "rectangular", "triangular", "biweight", "cosine", "optcosine"), weights = NULL, adjust = 1, shrinked = FALSE )
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 |
Product kernel density is defined in terms of independent univariate kernels
f(x) = sum[i](w[i] * prod[j]( Khj(x[i]-y[i,j]) ))
where w is a vector of weights such that all w[i] ≥ 0 and sum(w) = 1 (by default uniform 1/n weights are used), Khj is univariate kernel K parametrized by bandwidth h[j], where 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.
Deng, H. and Wickham, H. (2011). Density estimation in R. http://vita.had.co.nz/papers/density-estimation.pdf
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))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.