## Drawing two random empirical sample Y from the LogNormal distribution
## rounded to closest 0.5 (discrete)
set.seed(6020)
Y <- rlnorm(500L, meanlog = 1.5, sdlog = log(1.5))
Y <- round(Y * 2) / 2
bk <- seq(-0.25, 18.25, by = 1L)
hist(Y, freq = FALSE, breaks = bk, main = "Sample histogram")
x <- seq(0, 15, by = 0.5) # Quantiles
density <- dempirical(x, Y)
plot(density ~ x, type = "h", main = "Empirical density")
probability <- pempirical(x, Y)
plot(probability ~ x, type = "s", main = "Empirical distribution")
probs <- seq(0.01, 0.99, by = 0.01)
quantiles <- qempirical(probs, Y)
plot(probs ~ quantiles, type = "S", col = 2,
main = "Empirical quantile function")
## Drawing random numbers (sampling with replacement)
set.seed(6020)
r <- rempirical(500L, Y)
hist(Y, freq = FALSE, breaks = bk, main = "Sample histogram")
hist(r, freq = FALSE, breaks = bk, main = "Random sample histogram")
Run the code above in your browser using DataLab