Last active
February 22, 2020 17:55
-
-
Save statwonk/40e96dff95700e0e43925bc1de1bcfc4 to your computer and use it in GitHub Desktop.
The essence of bootstrapping: resampling with replacement to estimate a sampling distribution and its statistics of interest.
This file contains 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(tidyverse) | |
library(gganimate) | |
# sample of 100 data points | |
tibble(x = rexp(1e2)) -> d | |
# 20 bootstrap samples, you likely want several orders of magnitude more. | |
tibble(boot_samples = seq_len(2e1)) %>% | |
mutate(data = map(boot_samples, ~ d %>% sample_frac(1, replace = TRUE))) %>% | |
unnest(cols = c(data)) %>% | |
ggplot(aes(x = x, group = boot_samples)) + | |
stat_ecdf(size = 0.25) + | |
xlab("Time to event") + | |
ggtitle("Bootstrap samples from one sample of an\n | |
Exponential distribution r.v. with rate parameter 1") + | |
transition_reveal(boot_samples) -> anim | |
animate(anim, fps = 10, duration = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment