---
title: 'Module 5: Exercises'
author: ""
date: ""
output: html_document
---

## Data

First recreate the same artificial dataset `x` as in the supplementary material
(note the `set.seed()` command):
```{r}
mu_true <- 250
tau_true <- 1/5^2
n <- 30
set.seed(42)
x <- rnorm(n, mean = mu_true, sd = sqrt(1/tau_true))
x_bar <- mean(x)
```

## Exercise 1

Now, assume the researcher a priori (before seeing any data/people) is sure that
she/he is in a land of tiny people, and chooses the following parameters for the
priors for the mean and precision (still product of normal and gamma distribution):

```{r}
tau_prior <- 1/10^2
mu_prior <- 50
alpha_prior <- 10
beta_prior <- .002
```

Rerun the Gibbs sampler from the supplementary material (with the same updating
scheme: first $\mu$ then $\tau$) with these prior parameters and comment on the
marginal distribution of $\mu$ (and $\tau$ if you like).

## Exercise 2

Now rerun the Gibbs sampler from the supplementary material with the opposite
updating scheme -- first $\tau$ then $\mu$ -- and comment on the
marginal distribution of $\mu$ (and $\tau$ if you like).

## Exercise 3

Try to explain the different results you obtained in exercises 1 and 2 by looking
at the posterior we are trying to sample from. **Don't spend too much time on this**
-- it is difficult, and you will probably have to consider the logarithm of the posterior to be able to identify the problem: Instead consult the solution if
you find it too difficult.

## Exercise 4

Now generate additional 70 data points (people) from the population (still
N(`r mu_true`, `r tau_true`)) and rerun the analysis from
exercise 1 with this new dataset of 100 people (**remember** to update the global
variables `n` and `x_bar`). Comment on the results.

## Exercise 5

Based on the posterior simulations in exercise 4 estimate the probability of
$\mu < 249$.
