University of Toronto Mississauga
STA312 H5S: Computational Statistics – Winter 2020
Instructor: Dr. Luai Al Labadi
Assignment # 2
Due Date: Wed. February 26th, 2020 at beginning of lecture. Late assignments will not be accepted. If you cannot make it to the lecture, you can submit through a colleague.
Electronic submissions will not be accepted.
Solve all questions. However, not all questions on the assignments are marked. The questions to be marked are not announced.
Instructions:
• In this assignment, you should use R only when it is required.
• Start all your R codes with the following information: Question Number, Assignment 1, Your Last Name, First Name, Student Number. For Example,
# Question 1, Assignment 1
# Last Name: ABCD, First Name: XYZW
# St. #: 0123456789
• You may not alter the output (by typing or handwriting anything). Output should be directly copied and pasted to the assignment where needed. If you do not follow these rules, your assignment will not be accepted.
• Assignments should presently neatly. Use the following format:
– Theoretical questions can be hand-written or typed.
– Attach the cover page (provided) at the front of your assignment. (Be sure to include an appropriate title for your assignment and fill in/circle all the information required).
– For marking purposes, include the question numbers/part letters (1a,b,c, etc.) in your answers.
– Do not simply hand in pages of R output without further explanation. Only include the relevant tables or plots that are asked in each question. Make sure to interpret the results in plain English in terms of the problem, quote relevant numbers from the output, and give justifications as a part of your solutions.
– Do not include unnecessary code or output in the body of the assignment. At the end, include an appendix with ALL your R code and output.
– The appendix will be checked to make sure the work was completed individually by the student and that the instructions were followed.
Assignments are individual work. Only general discussion is permitted between students. You must hand in solutions in your own words. Do not let others see your solutions or your selected article. It is plagiarism (a serious academic offence) to submit solutions in other people’s words (including but not limited to other students, the instructor’s, solutions from previous years or courses, websites, etc). You are responsible for knowing and adhering to the University of Toronto’s Code of Behaviour on Academic Matters (see course outline).
STA312- Instructor: Dr. Luai Al Labadi Page 1 of 3
Answer All the following questions.
Follow the form of densities given in the formula sheet.
Question 1 Let X be a random variable from Poisson(λ), where λ > 0. That is, P(X = i) = p = e−λλi , i i!
i = 0,1,2,….
(a) Showthatp = λ p.
i+1 i+1 i
(b) Use part (a) to write an algorithm to generate a sample from X.
(c) Based on your algorithm in part (b), write an R code to generate a sample of size 1000 from P oisson(λ = 2). Check that the mean and the variance are of the generated sample is close to the theoretical value λ = 2. Report the values.
Question 2 Let X1,X2,…,Xn be an independent sample, where each Xi has a cdf FXi . Let Y = max(X1,…,Xn).
(a) Show that FY (x) = ni=1 FXi (x).
(b) Suppose it is easy to generate a random variable from any of FXi . How can we generate a sample
from FY (x) = ni=1 FXi (x)?
(c) Now assume that n = 20 and FXi(x) = 1−e−x, x > 0 (i.e. Xi ∼ Exponential (1)). Based on part (b), write an R code to generate a sample of size 1000 from FY (x) = ni=1 FXi (x). In your code, you may use the built-in R function ”rexp” to sample Xi. For the generated sample, plot the relative frequency histogram. Make appropriate titles. Report the mean and the variance for the generated sample.
Question 3 In class, we have discussed Acceptance-Rejection algorithm and Box-Muller approach to generate a sample form Z ∼ N (0, 1). The following algorithm can also be used to generate Z ∼ N (0, 1):
• Generate U1,…,U12 from Uniform[−0.5,0.5]. •SetZ=12 Ui.
i=1
(a) Show that E(Z) = 0 and V ar(Z) = 1. Here you need to find the exact values.
(b) Write an R code to generate a sample of size 1000 from Z ∼ N(0,1) based on the new algorithm. For the generated sample, plot the relative frequency histogram. Make appropriate titles. Report the mean and the variance for the generated sample.
Question 4 The Acceptance-Rejection (AR) algorithm may applies to densities known up to normalizing ̃ ̃∞ ̃ ̃
costants. Specifically, let f ∝ f. That is, f(x) = f(x)/ −∞ f(x)dx = f/k. Let g(x) be the candidate density. Then
̃ ̃ ̃
f(x) ≤c ⇐⇒ f(x) ≤c ⇐⇒ f(x) ≤ck ⇐⇒ f(x)