STA380H5F: Computational Statistics Assignment # 2
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
STA380H5F: Computational Statistics
Assignment # 2
Instructions
❼ Due Date: Nov. 18, 2022 at 11:59 pm EST (end of the day). Be sure to submit your work before
it is due. Late submissions will not be accepted.
❼ The solution will be submitted through crowdmark, meaning you will need to upload PDF, PNG or JPEG versions of your assignment answers. Upload your solution to crowdmark, one question at a time.
❼ Attempt all questions. However, NOT all questions will be marked. The questions to be marked
are not announced ahead of time.
❼ Solutions must be presented neatly, completely, and with logical flow. Do not skip steps in your
solutions or fail to describe what you are doing.
❼ Theoretical Questions can be hand-written or typed.
❼ Start each question on a new page. Sub-questions should be answered in order: (a), (b), (c), ...
The presentation of the solution will be marked in addition to the statistical aspects .
❼ Computational Questions:
– Use R/RStudio only whenever it is stated in the question“R/RStudio”.
– Only include the relevant output that are asked in each question. Do not include unnecessary code or output in the body of the assignment.
– If in Question 3, part (b), for example, we asked you to compute the sample mean of the generated sample, and in part (c) to plot the relative frequency histogram, then you need to provide the answers of part (b) and part (c) separately. Do not refer us to the code to find the answers.
❼ At the end, include an appendix with ALL your R/RStudio codes and outputs (do not include any
plot).
– Start all your codes with the following information: Question Number, Assignment Number, Your Last Name, First Name, Student Number. For Example,
# Question 2, Assignment 2
# Last Name: Your Last Name, First Name: Your First Name
# St. Number: Your Student Number
– Please do not repeat the previous information in each part of the same question.
– 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. Do not let others see your solutions. Only general discussion is permitted between students. 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). |
Answer all the following questions.
Follow the form of densities given in the formula sheet.
Question 1 Let X be a random variable with the following probability mass function
e −0 .5i (0.5i)i −1
P(X = i) = pi = ,i = 1, 2, . . . .
(a) Show that pi+1 = 0.5e−0 .5 ( )i −1 pi . Show all the steps.
(b) Use part (a) to write an algorithm to generate a sample from X . Be specific.
(c) Using R/RStudio, based on your algorithm in part (b), generate a sample of size 106 from the above density. Report the mean and the variance of the generated sample. Report these values. Hint: The sample mean and the sample variance should be close to 2 and 4 respectively.
Question 2 Let X1 , X2 , X3 , and X4 be a four independent random variables from N(0, 1).
(a) Using R/RStudio and Box-Muller transformation, generate a sample of size 106 from X1 . Plot the
relative frequency histogram with the true density of X1 superimposed for comparison. Use the option breaks= ‘‘Scott" in the histogram and make appropriate titles. Report the mean and the variance of the generated sample of X1 . Hint: You may use
hist (x1 , breaks=‘‘ Scott ”, prob=TRUE, xlab=‘‘X1”, ylab=‘‘ Relative Frequency ”, main= ‘‘( a ) : Box—Muller Transformation ”)
curve (dnorm(x) , xlim=c ( — 3 . 5 ,3 . 5) , add=TRUE, col=‘‘ blue ”,lwd=2)
(b) Let Y = X 1(2) . Using R/RStudio and the generated sample in part (a) plot the relative frequency
histogram of Y with the true density of Y superimposed for comparison. Use the option “breaks= “Scott” ”in the histogram and make appropriate titles. Report the mean and the variance of the generated sample of Y . Hint: You may use
curve ( dchisq (x , df =1),add=TRUE, col=‘‘ blue ”,lwd=2)
(c) Let T = X 1(2) + X2(2) + X3(2) + X4(2) . It is known that T has the chi-square distribution with 4 degrees of freedom. Now, using R/RStudio and Box-Muller transformation, for each of X1 , X2 , X3 , and X4 , generate a sample of size 106 . Use the generated sample to plot the relative frequency histogram with the true density of T superimposed for comparison. Use the option “breaks=”Scott”” in the histogram and make appropriate titles. Report the mean and the variance of the generated sample of T.
Question 3 In this question, we want to use the acceptance-rejection method to generate a sample of a random variable X with the following target probability density function:
f(x) = { 1.5(x 0.5x2 )
0 < x < 2
otherwise .
Let the trial distribution be Uniform(0, 2). That is,
g(x) = {
(a) Find c = max ( ). Show all the steps.
0 < x < 2
otherwise .
(b) Write the acceptance-rejection algorithm to generate a sample from X . Be specific.
(c) Using R/RStudio, based on your algorithm in (b), generate a sample of size 106 from the distribution of X . For the generated sample, plot the relative frequency histogram with the true density of X superimposed for comparison. Use the option “breaks=”Scott”” in the histogram and make appropriate titles.
(d) For the generated sample in (c), report the sample mean and the sample variance.
Question 4 Let
f(x) = c [sin2 (x) + 3cos2 (2x)sin2 (4x) +^2] e −x2 /2 , −∞ < x < ∞
be the probability density function of a random variable X and c is the normalizing constant.
(a) Find a Monte Carlo estimate of c by sampling from the standard normal. You need to write
an explicit expression of the estimator. Show all the steps. Hint: l f(x)dx = 1. (b) Using R/RStudio and based on a sample of size 106 , provide the numerical value of in (a).
Question 5 Consider
θ = \0 1 dx.
Note: This integral cannot be computed analytically. Using
https://www.wolframalpha.com/calculators/integral-calculator/,
\0 1 dx ≈ 0.946083.
(a) Find a Monte Carlo estimate of θ by sampling from Uniform(0, 1). You need to write an
explicit expression of the estimator. Show all the steps.
(b) Using R/RStudio and based on a sample of size 106 , provide the numerical value of the estimator
in (a).
(c) Find another Monte Carlo estimator θ ⋆ of θ by sampling from the exponential distribution with mean 1. You need to write an explicit expression of the estimator. Show all the steps.
(d) Using R/RStudio and based on a sample of size 106 , provide the numerical value of the estimator in (c).
2022-11-19