-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-sampling-dsn.Rmd
70 lines (51 loc) · 996 Bytes
/
04-sampling-dsn.Rmd
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
---
title: "Chapter 4: Sampling Distributions"
output: html_document
---
## Introduction
```{r}
library(purrr)
```
## Example 4.2
```{r}
my_means <- 1000 %>%
rerun(rexp(100, rate = 1/15)) %>%
map_dbl(~mean(.)) %>%
data.frame(means = .)
my_means %>%
ggplot(aes(x = means)) +
geom_histogram(bins = 20)
```
## Example 4.3
```{r}
my_max <- 1000 %>%
rerun(runif(12)) %>%
map_dbl(~max(.)) %>%
data.frame(max = .)
my_max %>%
ggplot(aes(x = max)) +
geom_histogram(bins = 20)
```
## Example 4.7
```{r}
my_means <- 1000 %>%
rerun(rgamma(30, shape = 5, rate = 2)) %>%
map_dbl(~mean(.)) %>%
data.frame(means = .)
my_means %>%
ggplot(aes(x = means)) +
geom_histogram(bins = 20)
mean(my_means$means)
sd(my_means$means)
mean(my_means$means > 3)
```
## Example 4.8
```{r}
my_means <- 1000 %>%
rerun(rgamma(17, shape = 100, rate = 5)) %>%
map_dbl(~mean(.)) %>%
data.frame(means = .)
my_means %>%
ggplot(aes(x = means)) +
geom_histogram(bins = 20)
```