Skip to content

Instantly share code, notes, and snippets.

@GuiMarthe
Created June 26, 2017 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuiMarthe/61ac8d820f3ef164a981bf09b75679ed to your computer and use it in GitHub Desktop.
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
## 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