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

STAT3405/STAT4066

Department of Mathematics and Statistics

Important: This assignment is assessed. Your work for this assignment must be submitted

via LMS by 23:59pm on Friday,  16 September 2022.

The expectation for a submission are:

• The questions are answered in complete  sentences.  Marks will be awarded for the cor-

rectness of the answers and that they are given in complete sentences. The answers to the questions should be submitted via LMS.

• That numerical answers are rounded to an appropriate number of digits.

In particular, R code developed for Task 1(a) should be submitted as an attachment in your LMS submission.  But so should be the BUGS or Stan code that you use to solve Task 2

Submission of code must be in plain text format, do not use any binary format. Preferably, the attachment should be a single R Notebook with ending *.Rmd.

Marks will be awarded for

• the correctness of the code, i.e. how easy it is to read it1 ; and

• how easy it is to get the code to run, if necessary.

You may receive comments on the efficiency of your code, but there are no marks for efficiency.

Unless special consideration is granted, any student failing to submit work by the deadline will receive a penalty for late submission (as described in the unit outline).

Plagiarism: You are encouraged to discuss assignments with other students and to solve problems together.   However, the work that you submit must be your sole effort  (i.e. not  copied from anyone else).  If you are found guilty of plagiarism you may be penalised.  You are reminded of the University’s policy on ‘Academic Conduct’ and ‘Academic Misconduct’ (including plagiarism):

http://www.student.uwa.edu.au/learning/resources/ace/conduct

Various material at the following URL might be helpful too:

https://www.uwa.edu.au/students/study-success/studysmarter

Task 1. This task explores the Metropolis-Hastings (MH) algorithm used in the second com- puter lab a bit further. However, for this assignment, we will use the likelihood for the Douglas Firs example discussed in the lectures, i.e. assume that the data was generated by a geometric distribution with parameter p and we will use the prior2

f(p) ∝ pp (1 − p)1 p

for the parameter p.

In the second lab, we used an MH algorithm with a proposal distribution that was inde- pendent of the current location of the chain.  While such MH algorithm can be used, they are typically quite inefficient if the proposal distribution is not “close”to the distribution one wants to sample from.  Another popular way of implementing an MH algorithm is to use a random walk  MH algorithm3. In such an implementation the proposed new state is obtained by adding some random noise (typically using a normal distribution with mean zero) to the current state.  In other words, the proposal distribution is a normal distribution with mean equal to the current state and some variance (which serves can serve as a tuning parameter for the MH algorithm).

An obvious difficulty arises when we try to use a random walk MH algorithm when modelling a probability, which is always between 0 and 1. Adding random noise to the current state could lead to a proposal that is outside the interval (0, 1)! We can circumvent this difficulty by first transforming the current state (a value between 0 and 1) via the logit transformation to the corresponding log-odds (a value between −∞ and ∞).  We can then add some noise to the transformed current state to obtain a proposal on the log-odds scale and then transform this proposal back to the interval (0, 1).

Specifically, the logit transformation is the function logit(p) = log ( ) which is readily

logit  <- function(p) log(p/(1-p))

also easily implemented in R:

invlogit  <- function(lo) 1/(1+exp(-lo))

Finally, it can be shown that the proposal distribution for this process (i.e. (1) transform- ing the current state p(t)  to the log-odds scale to obtain, say, u(t), (2) adding random noise coming from a normal distribution with mean 0 and variance σ 2  to u(t)  to obtain, say, w(t) , and (3) transforming w(t)  back to (0, 1) using the inverse logit transformation to obtain the proposal y(t)) has the following PDF:

q(y|p) = y(1y)exp ( [log ( ) log ( )]2 )   if 0 < y < 1 and 0 < p < 1

‘0                                                                                   otherwise

While this looks impressive, the corrective term for using this particular non-symmetric pro- posal distribution in the MH algorithm is actually quite simple:

q (p(t1)|y(t)) y(t) (1 − y(t))

=

q (y(t) |p(t1))     p(t1) (1 − p(t1))

Now

(a) Implement the random walk MH algorithm as described above. Appropriate code for this

part of the task should be submitted.

(b) What is the acceptance rate of your MH algorithm if you use σ = (i.e σ 2  = )?

How would you describe the Markov chain produced by this setting of σ?

(c) What is the acceptance rate of your MH algorithm if you use σ = 10?  How would you describe the Markov chain produced by this setting of σ?

(d) For what value of σ do you obtain an acceptance rate of around 70%?  How does the corresponding Markov chain look like?

Task 2. In the sixth lecture we discussed data from a survey survey was done of bicycle and other vehicular traffic in the neighbourhood of the campus of the University of California, Berkeley.

For these data:

(a) Fit a model that models yi , i = 1, . . . , 10, as being a realisation from a binomial dis- tributed random variable Yi  with parameters mi  and p.  Regard the mis as fixed and

given, and put your favourite non-informative prior on p.

What is your Bayesian estimate for p?

(b) Fit a model that models yi , i = 1, . . . , 10, as being a realisation from a binomial dis- tributed random variable Yi  with parameters mi  and pi .  Regard the mis as fixed and

given, and put your favourite non-informative prior on the pis.

What are your Bayesian estimate for the pis?

For this model, also look at the ratio of the smallest of the pis to the largest of the pis, i.e. study the parameter

mini=1,...,10 pi

r =

Include a plot of the posterior density of r in your submission.  What is your Bayesian estimate for r? What is the standard deviation of the posterior distribution of r?

(c) Given the results of the previous question, which model do you think is more appropriate for these data? Discuss briefly (i.e. less than a paragraph).