require(graphics)
set.seed(123)
n <- 1000
x <- rweibull(n, shape = 10)
bw1 <- opt_lin_bw(x = x, method="nrd")
bw2 <- opt_lin_bw(x = x, method="cv")
dens1 <- fit_steplength(x = x, parametric = FALSE, bandwidth = bw1)
dens2 <- fit_steplength(x = x, parametric = FALSE, bandwidth = bw2)
true_dens <- dweibull(seq(0,max(x),length.out = 200), shape = 10)
plot(seq(0,max(x),length.out = 200), true_dens, type = "l")
lines(dens1$x, dens1$y, col = "red")
lines(dens2$x, dens2$y, col = "green")
Run the code above in your browser using DataLab