Skip to content

Instantly share code, notes, and snippets.

@martinmodrak
Created February 3, 2023 10:03
Show Gist options
  • Select an option

  • Save martinmodrak/593822a2619d7673099580e756a7e268 to your computer and use it in GitHub Desktop.

Select an option

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