Description Usage Arguments Details References See Also Examples

Random generation from univariate kernel density

1 2 3 |

`n` |
number of observations. If |

`y` |
numeric vector. |

`bw` |
the smoothing bandwidth to be used. The kernels are scaled
such that this is the standard deviation of the smoothing
kernel (see |

`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 |

Univariate kernel density estimator is defined as

*
f(x) = sum[i](w[i] * Kh(x-y[i]))
*

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),
*Kh = K(x/h)/h* is kernel *K* parametrized by bandwidth
*h* and *y* is a vector of data points used for estimating the kernel density.

For estimating kernel densities use the `density`

function.

The random generation algorithm is described in the documentation of
`kernelboot`

function.

Deng, H. and Wickham, H. (2011). Density estimation in R. http://vita.had.co.nz/papers/density-estimation.pdf

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ```
# ruvk() produces samples from kernel densities as estimated using
# density() function from base R
hist(ruvk(1e5, mtcars$mpg), 100, freq = FALSE, xlim = c(5, 40))
lines(density(mtcars$mpg, bw = bw.nrd0(mtcars$mpg)), col = "red")
# when using 'shrinked = TRUE', the samples differ from density() estimates
# since they are shrinked to have the same variance as the underlying data
hist(ruvk(1e5, mtcars$mpg, shrinked = TRUE), 100, freq = FALSE, xlim = c(5, 40))
lines(density(mtcars$mpg, bw = bw.nrd0(mtcars$mpg)), col = "red")
# Comparison of different univariate kernels under standard parametrization
kernels <- c("gaussian", "epanechnikov", "rectangular", "triangular",
"biweight", "cosine", "optcosine")
partmp <- par(mfrow = c(2, 4), mar = c(3, 3, 3, 3))
for (k in kernels) {
hist(ruvk(1e5, 0, 1, kernel = k), 25, freq = FALSE, main = k)
lines(density(0, 1, kernel = k), col = "red")
}
par(partmp)
``` |

twolodzko/kernelboot documentation built on July 5, 2018, 10:47 p.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.