# NOT RUN {
### Use the package for data driven bandwidth for use with
### the Gaussian kernel in existing implementations
### generate sample from bimodal Gaussian mixture with varying scale
x <- c(rnorm(100000), rnorm(100000)/4 + 2)
### estimate bandwidth with the package using MLCV and convert
bwml <- h_K_to_Gauss(fk_density(x, h = 'mlcv',
beta = c(.25,.25))$h, c(.25,.25))
bwml_binned <- h_K_to_Gauss(fk_density(x, h = 'mlcv',
beta = c(.25,.25), nbin = 10000)$h, c(.25,.25))
xs <- seq(-3, 4, length = 1000)
plot(xs, dnorm(xs)/2+dnorm(xs,2,1/4)/2, type = 'l',
lwd = 4, col = rgb(.7, .7, .7))
lines(density(x, bw = bwml), lty = 2, lwd = 2)
lines(density(x, bw = bwml_binned), lty = 3, lwd = 2)
# }
Run the code above in your browser using DataCamp Workspace