-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsec-CLT.qmd
65 lines (48 loc) · 1.31 KB
/
sec-CLT.qmd
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
## The Central Limit Theorem
The sum of many independent or nearly-independent random variables with
small variances (relative to the number of RVs being summed)
produces bell-shaped distributions.
For example, consider the sum of five dice (@fig-clt-5d6).
```{r}
#| label: fig-clt-5d6
#| fig-cap: "Distribution of the sum of five dice"
library(dplyr)
dist =
expand.grid(1:6, 1:6, 1:6, 1:6, 1:6) |>
rowwise() |>
mutate(total = sum(c_across(everything()))) |>
ungroup() |>
count(total) |>
mutate(`p(X=x)` = n/sum(n))
library(ggplot2)
dist |>
ggplot() +
aes(x = total, y = `p(X=x)`) +
geom_col() +
xlab("sum of dice (x)") +
ylab("Probability of outcome, Pr(X=x)") +
expand_limits(y = 0)
```
In comparison, the outcome of just one die is not bell-shaped (@fig-clt-1d6).
```{r}
#| label: fig-clt-1d6
#| fig-cap: "Distribution of the outcome of one die"
library(dplyr)
dist =
expand.grid(1:6) |>
rowwise() |>
mutate(total = sum(c_across(everything()))) |>
ungroup() |>
count(total) |>
mutate(`p(X=x)` = n/sum(n))
library(ggplot2)
dist |>
ggplot() +
aes(x = total, y = `p(X=x)`) +
geom_col() +
xlab("sum of dice (x)") +
ylab("Probability of outcome, Pr(X=x)") +
expand_limits(y = 0)
```
What distribution does a single die have?
Answer: discrete uniform on 1:6.