slipper_: Bootstrap a function that returns a single number

Description Usage Arguments Value Examples

Description

Takes a data frame, a function that returns a single number, and a number of replicates and returns a data frame with the function calculated on the observed sample and on B bootstrap samples.

Usage

1
slipper_(df, expr, B = 100)

Arguments

df

A data frame

expr

A an expression with a function that operates on one or more variables from the data frame.

B

the number of bootstrap samples to draw

Value

out A data frame with the values, whether they come from the observed data or the bootstrapped data.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Boostrap the mean of the mpg variable in the mtcars data set
slipper(mtcars,mean(mpg),B=100)

# Bootstrap the mean of the mpg variable with piping
mtcars %>% slipper(mean(mpg),B=100)

# Calculate a confidence interval using the quantiles method
mtcars %>% slipper(mean(mpg),B=100) %>%
 filter(type=="bootstrap") %>%
 summarize(ci_low = quantile(value,0.025),
           ci_high = quantile(value,0.975))

jtleek/slipper documentation built on May 20, 2019, 3:14 a.m.