Created
June 26, 2017 22:09
-
-
Save GuiMarthe/61ac8d820f3ef164a981bf09b75679ed to your computer and use it in GitHub Desktop.
A small little idea on implementing bootstrap only using purrr, not dplyr based, after reading a google data science blog
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
## http://www.unofficialgoogledatascience.com/2015/08/an-introduction-to-poisson-bootstrap26.html | |
n <- 10000000 | |
data <- rnorm(n, mean = 4, sd = 2) | |
matrix_col_as_vector <- . %>% as.list() %>% purrr::as_vector() | |
boot_delta_mean <- function(id, data){ | |
mean_data <- mean(data) | |
indicator <- | |
rmultinom(n = 1, size = n, prob = rep(1/n, n)) %>% | |
matrix_col_as_vector() | |
as.numeric((indicator %*% data)/n) - mean_data | |
} | |
purrr::map_dbl(1:20, .f = ~ boot_delta_mean(. , data)) %>% | |
quantile(., probs = c(0.1, 0.9)) %>% | |
purrr::map_dbl(~ mean(data) + .) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment