-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.Rmd
More file actions
74 lines (55 loc) · 2.25 KB
/
README.Rmd
File metadata and controls
74 lines (55 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-",
message = FALSE,
warning = FALSE
)
```
<!-- badges: start -->
[](https://github.com/langcog/tidyboot/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
# tidyboot
`tidyboot` let's you compute arbitrary non-parametric bootstrap statistics on data in tidy data frames.
## Installation
You can install tidyboot from CRAN with:
```{r, eval = FALSE}
install.packages("tidyboot")
```
You can install tidyboot from github with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("langcog/tidyboot")
```
## Examples
For the simplest use case of bootstrapping the mean and getting the mean and confidence interval of that estimate, use the convenience function `tidyboot_mean()`, specifying which column has the relevant values to compute the mean over:
```{r}
library(dplyr)
library(tidyboot)
gauss1 <- data_frame(value = rnorm(500, mean = 0, sd = 1), condition = 1)
gauss2 <- data_frame(value = rnorm(500, mean = 2, sd = 3), condition = 2)
df <- bind_rows(gauss1, gauss2)
df %>%
group_by(condition) %>%
tidyboot_mean(column = value)
```
For bootstrapping any statistic and any properties of its sampling distribution, use `tidyboot()`.
You can provide the statistic to be estimated either as a function and a column to compute it over, or as function that takes the whole dataframe and computes the relevant value.
Similarly, you can provide the properties of the sampling distribution to be computed either as a named list of functions and a column to compute them over, or a function that takes the whole dataframe and returns the relevant values.
```{r}
df %>%
group_by(condition) %>%
tidyboot(column = value, summary_function = median,
statistics_functions = list("mean" = mean, "sd" = sd))
```
```{r}
df %>%
group_by(condition) %>%
tidyboot(summary_function = function(x) x %>% summarise(median = median(value)),
statistics_functions = function(x) x %>% summarise_at(vars(median), funs(mean, sd)))
```