PubH 7440: Introduction to Bayesian Analysis Spring 2020, Homework 2
Due: February 25, 2020
1. (Gelman, Chapter 3, Problem 3): An experiment was performed on the effects of magnetic fields on the flow of calcium out of chicken brains. Two groups of chickens were involved: a control group of 32 chickens and an exposed group of 36 chickens. One measurement was taken on each chicken, and the purpose of the experiment was to measure the average flow 𝜇𝜇 in untreated (control) chickens and the average flow of 𝜇𝜇𝑡𝑡 in treated chickens. The 32 𝑐𝑐 measurements on the control group had a sample mean of 1.013 and a sample standard deviation of 0.025. The 36 measurements on the treatment group had a sample mean of 1.173 and a sample standard deviation of 0.20.
a. Assuming the control measurements were taken at random from a normal distribution with mean 𝜇𝜇 and variance 𝜎𝜎2, what is the posterior distribution of 𝜇𝜇 ? Similarly, use
𝑐𝑐𝑐𝑐𝑐𝑐
the treatment group measurements to determine the marginal posterior distribution of 𝜇𝜇.Assumethat𝑝𝑝�𝜇𝜇,𝜎𝜎2�∝ 1.
𝑡𝑡 𝜎𝜎2
b. What is the posterior distribution for the difference: 𝜇𝜇𝑡𝑡 − 𝜇𝜇𝑐𝑐 ? To get this, you may sample from the independent posterior distributions you obtained in part (a). Plot a histogram of your samples and give an approximate 95% posterior interval for 𝜇𝜇 − 𝜇𝜇 .
𝑁𝑁(𝜇𝜇,𝜎𝜎 ),wherethepriordistributionfor(𝜇𝜇,𝜎𝜎 )isdefinedas𝜇𝜇|𝜎𝜎 ∼𝑁𝑁�𝜇𝜇 ,𝜎𝜎2�and𝜎𝜎𝑡𝑡∼ 𝑐𝑐
𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 ( 𝜈𝜈 0 , 𝜎𝜎 02 ) . T h i s i s t h e 𝑁𝑁 − 𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 𝐼𝐼 � 𝜇𝜇 , 𝜎𝜎 2 � 𝜇𝜇 0 , 𝜎𝜎 02 ; 𝜈𝜈 0 , 𝜎𝜎 02 � . S h o w t h a t t h e p o s t e r i o r
2. (Gelman, Chapter 3, Problem 9): Suppose y is an i.i.d. sample of size n from the distribution 2220𝜅𝜅2
𝜅𝜅
takes the same form and write it in terms of the sufficient statistics.
Table 1: Data for Intersections from streets that are bike routes (the left two columns) and not bike routes (the right two columns)
streets that are bike routes
streets that are not bike routes
Intersection
Number of Bicycles
Intersection
Number of Bicycles
1
16
1
12
2
9
2
1
3
10
3
2
4
13
4
4
5
19
5
9
6
20
6
7
7
18
7
9
8
17
8
8
9
35
10
55
3. Consider the data in Table 1, which are on the number of bicycles at intersections for streets that are and are not bike routes. The goal is to analyze the mean rate of bicycles for each intersection (separately for the bike-route and non-bike-route streets) using the following model:
Where: and
𝑝𝑝(𝑦𝑦 |𝜆𝜆 ) = (𝜆𝜆𝑖𝑖)𝑦𝑦𝑖𝑖𝑟𝑟−𝜆𝜆𝑖𝑖 𝑖𝑖𝑖𝑖 𝑦𝑦𝑖𝑖!
𝑌𝑌𝑖𝑖|𝜆𝜆𝑖𝑖 ∼ 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝐼𝐼(𝜆𝜆𝑖𝑖)
𝜆𝜆𝑖𝑖 ∼ 𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼(𝛼𝛼, 𝑟𝑟𝐼𝐼𝑟𝑟𝑟𝑟 = 𝛽𝛽)
𝛼𝛼 ∼ 𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼(0.01, 𝑟𝑟𝐼𝐼𝑟𝑟𝑟𝑟 = 0.01) 𝛽𝛽 ∼ 𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼𝐼(0.01, 𝑟𝑟𝐼𝐼𝑟𝑟𝑟𝑟 = 0.01)
𝑝𝑝(𝜆𝜆 |𝛼𝛼,𝛽𝛽) = 𝜆𝜆𝛼𝛼𝑖𝑖 −1𝛽𝛽𝛼𝛼𝑟𝑟−𝛽𝛽𝜆𝜆𝑖𝑖 𝑖𝑖 Γ(𝛼𝛼)
a. Provide BUGS code to fit the model described above, specifying a separate hierarchical model for the bike-route and non-bike-route intersections.
b. Using the data and initial values provided on the canvas site, run three parallel chains for 4000 iterations each and provide traceplots for the four population-level parameters (i.e. 𝛼𝛼 and 𝛽𝛽 for bikes and non-bikes). Comment on what these plots tell you about the convergence of the chain.
c. Throw out the first 4000 iterations and run the chain for 2000 additional iterations. Provide summary statistics for the four population-level parameters, as well as the intersection-specific rate parameters.
d. Edit your BUGS code to test if the posterior mean of the population-level bike-route intersection rates is larger than the non-bike-route intersection rates.
e. Edit your BUGS code to provide the predictive distribution for the number of bikes observed at a NEW bike-route intersection and provide summary statistics and a plot of the predictive density.
This distribution will have mean 0 and variance 17.67. Write code (in R or your preferred statistical programming language) to approximate the mean and variance of 𝑓𝑓(𝑥𝑥) using importance and rejection sampling, using a normal candidate density in both cases. Approximate the mean and variance using 200 draws from the target density.
4. Consider the following mixture density:
𝑓𝑓(𝑥𝑥) = 13 1 𝑟𝑟−12(𝑥𝑥+5)2 + 13 1 𝑟𝑟−12𝑥𝑥2 + 13 1 𝑟𝑟−12(𝑥𝑥−5)2 √2𝜋𝜋 √2𝜋𝜋 √2𝜋𝜋