You are on page 1of 1

MAS472/6004: Assessed Exercises 2

Richard Wilkinson
24 April 2018

This is the second set of assessed exercises for MAS6004/472.


• It is worth 5% of the module mark.
• The deadline for submission is 12pm (noon) on 8 May.
• All work should be submitted through MOLE.
• Requests for extensions will require a medical note.
• An integer mark will be awarded out of 5 for each piece of coursework.
• Solutions will be provided.
• Please use Rmarkdownhttp://rmarkdown.rstudio.com/authoring_quick_tour.html to produce your
solutions (pdf, html or word is acceptable as a submission format). This will ensure that your work is
reproducible, help you to avoid errors in your coding, and will ensure I can see all the steps you took in
producing your solution.
• Please use a filename of the form StudentNumber_Name.pdf. So if your student number is 12345 and
your name Aloysius, you would name your file 12345\_Aloysius.pdf.
Present your work in exam format: you must include all your working and present your solutions clearly, but
otherwise, no marks will be awarded for presentation or commentary.
Your submitted solutions must be entirely your own work: do not work with anyone else on your exercises.

Question 1

Consider the distribution F with probability density function



bx
 for 0 ≤ x ≤ 2,
f (x) = c − bx for 2 ≤ x ≤ 4,

0 otherwise.

i) If f (x) is a continuous function of x, determine the value of b and c.


ii) A sequence U1 , U2 , . . . of independent uniform random variables distributed on [0, 1] is available. Explain
carefully how to use the inversion method to generate random variables from distribution F . Implement
your algorithm in R: generate 10000 values from the required distribution and plot a histogram. Verify
that the sample has been generated correctly by drawing the pdf f (x) on top of the histogram.
iii) As an alternative to the inversion method, we will now generate random variables from F using rejection
sampling, using a N (µ, σ 2 ) distribution as the proposal density. Describe the algorithm you would use.
iv) Calculate the optimal values of µ and σ 2 . Optimal here means the values that lead to the highest
possible acceptance rate.
v) Implement your algorithm in R and use it to generate 10000 random values from F . Check your answer
again by plotting a histogram. If you were unable to calculate the optimal values in part iv), you may
instead use µ = 2 and σ 2 = 1. Report the acceptance rate of your algorithm.

You might also like