Introduction

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.

Installation

You can install the released version of strapgod from CRAN with:

install.packages("strapgod")

Install the development version from GitHub with:

Learning about 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.

Example

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.

You can feed a resampled_df into summarise() or group_map() to perform efficient bootstrapped computations.

The original data can be grouped as well, and the bootstraps will be created for each group.

Plotting bootstrapped results

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

In the wild

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