-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlab_week_05.Rmd
71 lines (36 loc) · 1.86 KB
/
lab_week_05.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
71
---
title: "EEEB UN3005/GR5005 \nLab - Week 05 - 24 and 26 February 2020"
author: "USE YOUR NAME HERE"
output: pdf_document
fontsize: 12pt
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(rethinking)
```
# Statistical Distributions and Summary Statistics
## Exercise 1: Grid Approximation, Our Old Friend
Imagine that the globe tossing example from the *Statistical Rethinking* text and class resulted in 8 water observations out of 15 globe tosses.
With this set of data, use grid approximation (with 101 grid points) to construct the posterior for *p* (the probability of water). Assume a flat prior.
Plot the posterior distribution.
```{r}
```
## Exercise 2: Sampling From a Grid-Approximate Posterior
Now generate 10,000 samples from the posterior distribution of *p*. Call these samples `post.samples`. Visualize `post.samples` using the `dens()` function.
For your own understanding, re-run your sampling and plotting code multiple times to observe the effects of sampling variation.
```{r}
```
## Exercise 3: Summarizing Samples
Return the mean, median, and mode (using `chainmode()`) of `post.samples`. Then calculate the 80%, 90%, and 99% highest posterior density intervals of `post.samples`.
```{r}
```
## Exercise 4: Model Predictions
Using `post.samples`, generate 10,000 simulated model predictions (you can call these `preds`) for a binomial trial of size 15. Visualize the model predictions using the `simplehist()` function.
Based on these posterior predictions, what is the probability of observing 8 waters in 15 globe tosses?
```{r}
```
## Exercise 5: More Model Predictions
Using the *same* posterior samples (i.e., `post.samples`), generate 10,000 posterior predictions for a binomial trial of size 9.
Using these new predictions, calculate the posterior probability of observing 8 waters in 9 tosses.
```{r}
```