Assignment 1
These problems are for credit and to be handed in on February 2nd at the latest.
Problem 1.1
Consider the geometric distribution \(\mathsf{geom}(p)\) with mass function \[\begin{align*} f(y; p) = p(1-p)^{y}, \qquad y = 0, 1, 2, \ldots; \end{align*}\] the latter is used to model the number of failures \(Y\) from independent trials until a first success, which occurs with probability \(p\).
- If \(Y \mid P=p \sim \mathsf{geom}(p)\) and \(P \sim \mathsf{beta}(\alpha_1, \alpha_2)\), show that \(P \mid Y=y\) is beta distributed and obtain the parameters of the latter.
- Obtain the marginal distribution of \(Y\) and show that it is a special case of the beta-negative binomial distribution.
- Using the tower property, compute the unconditional mean and variance of \(Y\). Hint: the formulae will depend on the reciprocal moments of a beta distribution, \(\mathsf{E}_P(P^{-1})\) and \(\mathsf{E}_P(P^{-2})\). Complete the kernel to obtain these using the property \(\Gamma(\alpha+1) = \alpha \Gamma(\alpha)\).
- Forward sampling: generate data from the marginal of \(Y\) as follows
- Pick values for \((\alpha_1, \alpha_2)\).1
- Draw 10 000 observations from \(Y\) by first simulating from \(P\), then from \(Y \mid P\).
- Discard the values of \(P\) and keep only those for \(Y\).
- Plot the marginal distribution of \(Y\) using a bar plot.
- Verify the formulas for the expected value and variance derived previously using Monte Carlo integration.
Problem 1.2
The sweden
dataset contains the number of accidents \(Y\) per day in Sweden for 1961–1962. Some days, a speed limit
was in place on specified days (day
) of each year. We write the mean model as \[\begin{align*}
\mathsf{E}(Y_i; \lambda_0, \lambda_1) &= \exp(\beta_0 + \beta_1\texttt{limit}_i)
\\&= \begin{cases} \lambda_0 & \texttt{limit}_i=0 \\ \lambda_1 & \texttt{limit}_i=1.\end{cases}
\end{align*}\]
Assume each of the 184 observations are independent from two Poisson populations with mean \(\lambda_0\) and \(\lambda_1\), when limit=0
and limit=1
, respectively. Check Example 3.5 (Should you phrase your headline as a question?) of the course notes
- Use a noninformative conjugate prior and obtain posterior samples for \(\lambda_0\) and \(\lambda_1\). Use these to obtain \(B=10 000\) posterior samples for the mean ratio \(\lambda_1/\lambda_0\) and plot a histogram or density estimator of the latter.
- Calculate the posterior probability that the speed limit enforcement reduces the average number of accidents.
Problem 1.3
The waiting
dataset contains waiting times (in seconds) from 17:59 until the departure of the next metro at the Universite de Montreal station during week-days over three consecutive months.
- Assume first that the waiting time are independent and identically distributed as exponential.
- Use a conjugate gamma prior such that the average waiting time \(1/\lambda\) has mean 30 seconds and std. deviation 30 seconds.2 Give the values of the corresponding shape and rate parameters of the prior.
- Plot an histogram of prior predictive draws.
- Derive the posterior distribution and report its parameter values.
- Calculate the posterior probability of waiting more than 30 seconds analytically and verify the result via Monte Carlo integration.
- The
post_waiting_weibull
contains 10K random samples from the posterior of a Weibull model \(\mathsf{Weibull}(\lambda, \alpha)\) with a penalized-complexity prior for the shape parameter with \(\alpha \sim \mathsf{PC}(\theta=0.5)\) (Niekerk et al., 2021) and \(\lambda \sim \mathsf{inv. gamma}(\gamma, \omega)\) with scale \(\gamma=90\) and shape \(\omega=4\).- Draw \(B=1000\) posterior predictive samples of size \(n=62\) from the Weibull and exponential models. Each draw should use different parameter values.
- For each, compute (i) the sample mean, (ii) the sample std. deviation and (iii) the empirical proportion of samples exceeding 30 seconds. Plot an histogram for each of the three summary and each model (Weibull and exponential). Superimpose a vertical line indicating the corresponding function for the original
waiting
sample. Hence comment on the adequacy (or lack thereof) of the two models.
References
Footnotes
Take \(\alpha_1 > 3\) for part e.↩︎
Hint: if \(\Lambda \sim \mathsf{gamma}(\alpha, \beta)\), then the reciprocal rate follows \(1/\Lambda \sim \mathsf{inv. gamma}(\alpha, \beta)\) with \(\mathsf{E}(\Lambda^{-1}) = \beta/(\alpha-1)\) for \(\alpha>1\) and \(\mathsf{Va}(\Lambda^{-1}) = \beta^2/\{(\alpha-1)^2(\alpha-2)\}\). Solve to find the values of the parameters and check numerically by generating data from the inverse gamma distribution.↩︎