Created
February 3, 2023 10:03
-
-
Save martinmodrak/593822a2619d7673099580e756a7e268 to your computer and use it in GitHub Desktop.
Simulation to show distribution of estimated tail quantiles from a specific number of draws
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| N_sims <- 1000 | |
| N_draws <- 4000 | |
| sims <- matrix(rnorm(N_sims * N_draws), nrow = N_sims, ncol = N_draws) | |
| q975 <- apply(sims, MARGIN = 1, FUN = quantile, prob = 0.975) | |
| true_q975 <- qnorm(0.975) | |
| ggplot(data.frame(x = q975), aes(x)) + | |
| geom_histogram() + | |
| geom_vline(xintercept = true_q975, size = 2, color = "blue") + | |
| labs(x = "Estimated 97.5 quantile", title = paste("Estimated 97.5 quantile from", N_draws," independent draws"), | |
| subtitle = "Vertical blue line is the true value") + | |
| theme_minimal() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment