Assignment 1
These problems are for credit and to be handed in on September 23rd at 23:59 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*}\] This distribution 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 give explicit expressions for its shape parameters.
- 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 formula 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)\).
- Generate 10K samples from the marginal distribution of \(Y\) if \(\alpha_1=4.5\) and \(\alpha_2=1.5\). Plot the resulting marginal distribution using a bar plot and use the samples to verify the formulas for the expected value and variance derived previously using Monte Carlo integration.
Forward sampling: generate data from the marginal of \(Y\) as follows:
- Simulating first from \(P_i\sim \mathsf{beta}(4.5, 1.5)\),
- Next, generate \(Y_i \mid P_i\) for \(i=1, \ldots, 10 000\).
- Discard the values of \(P_i\) and keep only those for \(Y_i\)’s.
Problem 1.2
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.1
- Give the values of the corresponding shape and rate parameters of the prior.
- Plot an histogram of \(1000\) 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.
- Perform a prior sensitivity analysis.
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 \(\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. For each posterior draw, generate a sample of size \(n=62\).
- For each, compute the sample mean, ( the sample std. deviation and 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
waitingsample. Hence comment on the adequacy (or lack thereof) of the two models.
References
Footnotes
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.↩︎