Learn R Programming

ungeviz (version 0.1.0)

bootstrap_summarize: Bootstrapped actions on data frames

Description

Perform bootstrapped actions on data frames (tibbles) respecting any grouping that has been set up. The function bootstrap_summarize() is a drop-in replacement for dplyr::summarize() and the function bootstrap_do() is a drop-in replacement for dplyr::do(). The function bootstrap() simply generates bootstrapped data sets and returns them in a combined table.

Usage

bootstrap_summarize(.data, times, ..., key = ".draw")

bootstrap_summarise(.data, times, ..., key = ".draw")

bootstrap_do(.data, times, ..., key = ".draw")

bootstrap_collect(.data, times, ..., key = ".draw")

Arguments

.data

Data frame on which to operate.

times

Number of independent bootstrap draws to perform.

...

Other arguments handed off to summarize(), do(), or collect().

key

Name of the column that will hold an integer running from 1 to times indicating the bootstrap replicate.

Examples

Run this code
# NOT RUN {
iris %>% group_by(Species) %>%
  bootstrap_summarize(3, mean_sepal_length = mean(Sepal.Length))

data(BlueJays, package = "Stat2Data")
BlueJays %>% group_by(KnownSex) %>%
  bootstrap_do(
    5,
    broom::tidy(lm(BillLength ~ Head, data = .))
  )
library(ggplot2)
library(dplyr)

mtcars %>% bootstrap_collect(20) %>%
  ggplot(aes(hp, mpg)) +
  geom_point(data = mtcars) +
  geom_smooth(aes(group = .draw), method = "lm", se = FALSE)

# }
# NOT RUN {
library(gganimate)
mtcars %>% bootstrap_collect(20) %>%
  ggplot(aes(hp, mpg)) +
  geom_point(data = mtcars) +
  geom_smooth(aes(group = .draw), method = "lm", se = FALSE) +
  transition_states(.draw, 1, 1) +
  shadow_mark(color = "gray60", size = 0.3)
# }

Run the code above in your browser using DataLab