Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Bayesian Data Analysis

STAT8150 Assignment 3

Question 1 (18 marks)

The data set Battedballs .csv includes the batted ball’s launch speed (mph), and distance traveled (feet) hit by a professional player. We want to learn the relation- ship between launch speed and distance.

(a) Rescale both the explanatory and response variables so each has mean 0 and

standard deviation 1.

(b)  Consider the regression model on the rescaled data:

Yi ∼ Normal(µi(∗),σ),    µi(∗)  = β0 + β1 xi(∗) ,

where y and xi(∗)  are the rescaled distance traveled and rescaled launch speed of the i-th batted ball.

Suppose one has little prior beliefs about the values of the parameters β0 ,β1 and σ .   One assumes that the parameter are independent where β0   and β1 are assigned normal priors with mean 0 and standard deviation 10, and the precision 1/σ2  is Gamma with parameters 0.1 and 0.1.

Use JAGS to obtain a simulated sample of 5000 draws from the posterior distribution of (β0 ,β1 ,σ).

(c) From the simulated output,  construct a density estimate and 90% interval estimate for the slope parameter β1 .

(d) Using the output, obtain simulated draws of the expected standardized dis- tances when the standardized speed is equal to one. Construct a 90% interval estimate for the expected distance.

(e)  Suppose one believes that if the player hits a ball with average speed, the

expected distance is Normal with mean 350 feet and standard deviation 10 feet. In addition, one believes the correlation between launch speed and distance is Normal with mean 0.9 and a standard deviation of 0.02.  Construct a prior distribution on the vector of parameters (β0 ,β1 ) that reflects this information.

(f) Use JAGS with the informative prior to obtain a simulated sample from the

posterior distribution of all parameters. Construct a 90% interval estimate for the slope parameter β1  and compare your answer with the interval estimate constructed in part (d).

 

Question 2 (12 marks)

The Federalist Papers were a collection of articles written in the late 18th century by Alexander Hamilton, James Madison and John Jay to promote the ratification of the United States Constitution. Some of these papers were written by Hamilton, other papers were written by Madison, and the true authorship of some of the remaining papers has been in doubt.

In one of the early significant applied Bayesian papers, Mosteller and Wallace (1963) illustrate the use of Bayesian reasoning in solving the authorship problem.  They focused on the frequencies of word counts.

Consider the counts of the word  there” in the 50 Federalist Papers authored by Hamilton. Suppose the count yi  in the i−th paper is distributed Poisson with mean ni λ/1000 where ni  is the number of words in the paper and λ is the rate of the word "there" per 1000 words.  You can get this count using the following code, where for each paper, the total number of words, the number of occurrences of the word "there" and the rate of this word per 1000 words are recorded.

library (dplyr)

library (ProbBayes)

federalist _ word _ study   %>%

filter(Authorship   ==   " Hamilton " ,  word   ==   " there " )   - >  data . there glimpse( data . there)

 

(a) Assuming a weakly informative prior for λ use JAGS to fit this Poisson sam-

pling model.

(b)  Compute a 90% probability interval for the rate λ .

(c)  Consider a new essay with 1000 words.  By simulating 1000 draws from the posterior predictive distribution, construct a 90% prediction interval for the number of occurrences of the word there in this essay.

(d) Instead of Poisson model, suppose the count of the word yi   "there" in the i−th Federalist paper is distributed Negative Binomial with parameters pi  and α, where pi  = β/(β + ni /1000) where ni  is the number of words in the paper and α/β is the rate of the word  "there" per 1000 words.  With a suitable weakly informative prior for α and β, use JAGS to simulate 1000 draws from the posterior distribution.

(e)  Construct a 90% interval estimate for the rate parameter α/β in the Negative

Binomial model.

 

Question 3 (15 marks)

Consider a three-component mixture distribution, where the density for x has the form

f(x) = 0.45 × ϕ(x,−3, 1/3) + 0.1 × ϕ(x,0, 1/3) + 0.45 × ϕ(x,3, 1/3),

where  ϕ(x,µ,σ) is the Normal density with mean µ and standard deviation σ . Consider the following two ways of simulating from this mixture density.


Monte Carlo: Introduce a mixture component indicator, z, an unobserved latent variable.  The variable z is equal to 1, 2, and 3 with respective probabilities 0.45, 0.1 and 0.45. The density for x conditional on z is normal distribution,

[x|z = 1] ∼ Normal(−3, 1/3), [x|z = 2] ∼ Normal(0, 1/3), [x|z = 3] ∼ Normal(3, 1/3).

One simulates x by first simulating a value of z from its discrete distribution and then simulating a value of x from the corresponding conditional distribution.  By repeating this method, one obtains a Monte Carlo simulated sample from the exact mixture distribution.

Gibbs Sampling: Introduce the latent variable z as in the Monte Carlo way, and consider the two conditional distributions [x|z] and [z|x]. The conditional distribu- tion [x|z] will be a Normal density where the parameters depend on the value of the latent variable.  The conditional distribution [z|x] is discrete on the values 1, 2, 3 where the probabilities are proportional to 0.45 × ϕ(x,−3, 1/3), 0.1 × ϕ(x,0, 1/3), 0.45 × ϕ(x,3, 1/3), respectively.

(a) Write R scripts to use both the Monte Carlo and Gibbs sampling methods to

simulate 1000 draws from this mixture density. To get the reproducible results, in this question, run your simulation with a fixed random seed 123.  [You can set this using set .seed(123) in R].

(b)  Compare the simulated draws from the mixture distribution using the Monte

Carlo and Gibbs sampling algorithms. Using MCMC diagnostic graphs, explore the Gibbs sampling output.  Are there particular features in these diagnostic graphs that would indicate problems in the convergence of the Gibbs sampling algorithm?

(c)  Show that Gibbs sampler is a special case of Metropolis-Hastings algorithm, remember to define your notation and provide sufficient mathematical deriva- tions.  Then discuss how to improve convergence for MCMC type algorithms in general.