I am trying to solve exercise 5.13 in Gelman et. al. Bayesian Data Analysis (third edition). The exercise says:

Hierarchical binomial model: Exercise 3.8 described a survey of bicycle traffic in Berkeley, California, with data displayed in Table 3.3. For this problem, restrict your attention to the first two rows of the table: residential streets labeled as ‘bike routes,’ which we will use to illustrate this computational exercise.

The data are y=[16 9 10 13 19 20 18 17 35 55] and n=[ 74 99 58 70 122 77 104 129 308 119].

(a) Set up a hierarchical model for the observed number of bicycles on streets $ j =1, \cdots , 10$ that is binomial with unknown probability $\theta_j$ and sample size equal to the total number of vehicles (bicycles included) in that block. Assign a beta population distribution for the parameter $\theta_j$ and a non-informative hyperprior distribution. Write down the joint posterior distribution.

(b) Compute the marginal posterior density of the hyperparameters and draw simulations from the joint posterior distribution of the parameters and hyperparameters.

(c) Compare the posterior distributions of the parameters $\theta_j$ to the raw proportions in location j.

(d) Give a 95% CI for the average underlying proportion of traffic that is bicycles.

(e) A location on a new residential street with a bicycle route is sampled at random during which time 100 vehicles of all kinds go by. Give a 95% CI for the Number of those vehicles that are bicycles. Discuss how much you trust this interval in application.

I have managed to solve (a), (b) and (c). I would like to ask if you could help me with (d) and (e). For question (d) I thought to do the following: For each variable $\theta_j$ I have computed the 95% CI. So the mean of these lower(upper) bounds will be the lower(upper) bound for the wanted CI. Is this correct?

For question (e) I thought the following: Let [a,b] be the 95%CI from (d) question. The meaning of this CI is (correct me please if I am wrong) :[a,b] is the interval where with 95% probability the observed vehicle is bicycle. So, from the 100 new observed vehicles I predict that 95 of them will lie among a and b will be bicycle. But, I don't understant if I can trust this interval. Could you please give me a hint.

Please, I don't want you to solve the excercise for me, just give me hints to continue.


(d) You should have many samples from the posterior distribution of $\{\theta_j\}$ for $j=1,\cdots,10$ and also $\alpha$ and $\beta$ the parameters of a Beta distribution from which the $\theta_j$ were drawn. What you want is the 95% confidence interval for the expected value of these beta distributions. The expected value of a beta distribution with parameters $\alpha$ and $\beta$ is $\frac{\alpha}{\alpha+\beta}$. Thus, what you need to do is calculate $\frac{\alpha}{\alpha+\beta}$ for each of your posterior samples, and then take your 95% confidence intervals from the distribution of these vales.

(e) Given each of the beta distributions discussed in part (d), you can sample it to get a new value $\theta$ for an unknown new street. You can then generate a binomial variable with this $\theta$ and $N=100$. This wil give you a sample from the posterior predictive distribution for a new measurement in a street with 100 vehicles. Again, the distribution of all these samples is what you are interested in. Use this to create a 95% CI.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.