knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of strapgod is to create virtual groups on top of a tibble
or grouped_df
as a way of resampling the original data frame. You can then efficiently perform various dplyr operations on this resampled_df
, like: summarise()
, do()
, group_map()
, and more, to easily compute bootstrapped and resampled statistics.
You can install the released version of strapgod from CRAN with:
install.packages("strapgod")
Install the development version from GitHub with:
devtools::install_github("DavisVaughan/strapgod")
If you aren't already on the pkgdown site, I would encourage starting there. From there, you will be able to click on these two vignettes to learn about working with resampled tibbles.
vignette("virtual-bootstraps", "strapgod")
vignette("dplyr-support", "strapgod")
Create resampled data frames with bootstrapify()
or samplify()
. Notice how we grouped by the virtual column, .bootstrap
and there are still only 150 rows even though we bootstrapped this dataset 10 times.
library(strapgod) library(dplyr) set.seed(123) bootstrapify(iris, 10)
You can feed a resampled_df
into summarise()
or group_modify()
to perform
efficient bootstrapped computations.
iris %>% bootstrapify(10) %>% summarise(per_strap_mean = mean(Petal.Width))
The original data can be grouped as well, and the bootstraps will be created for each group.
iris %>% group_by(Species) %>% bootstrapify(10) %>% summarise(per_strap_per_species_mean = mean(Petal.Width))
A fun example of using strapgod is to create bootstrapped visualizations quickly and easily for hypothetical outcome plots.
set.seed(123) library(ggplot2) # without bootstrap mtcars %>% ggplot(aes(hp, mpg)) + geom_smooth(se = FALSE) + ylim(y = c(0, 40))
# with bootstrap mtcars %>% bootstrapify(10) %>% collect() %>% ggplot(aes(hp, mpg, group = .bootstrap)) + geom_smooth(se = FALSE) + ylim(y = c(0, 40))
Claus Wilke has used strapgod to power some pieces of his ungeviz package for visualizing uncertainty.
You can watch Claus's rstudio::conf 2019 talk to see ungeviz and strapgod in action.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.