Docsity

Practice Homework 2 - Computational Statistics | MATH 758, Assignments of Statistics

Toggle sidebar
bg1
MATH 758 โ€“ HOMEWORK 2
1. Simulation of a beta(5, 2) curve.
(a) Write a R function to simulate n values
of a beta(5, 2) random variable using an
accept/reject algorithm using a uniform
bounding function. One of the output
arguments for the function should be the
acceptance rate of the algorithm.
(b) Write a second R function to simulate n
values of a beta(5, 2) variate using a
triangular bounding function. (As the figure
below indicates, the beta(5, 2) curve is bounded above by the function y = 3.16 x.)
(c) Simulate 1000 values using the two algorithms you programmed in parts (a) and
(b). Confirm in each case that you have simulated 1000 values of a beta(5, 2)
variable. Compare the two algorithms with respect to (1) acceptance rate and (2)
speed.
2. In Example 6.2, ten independent observations (8,3, 4, 3, 1, 7, 2, 6, 2 ,7) are
observed from the model
Xi|๎˜ distributed Poisson(l) and log ๎˜ is distributed normal with mean 4 and standard
deviation 0.5.
(a) Apply rejection sampling using the envelope function suggested in the exercise.
Try out the method and confirm that the acceptance rate is around 30%.
(b) Construct a more efficient envelope using a normal distribution. Demonstrate
that your algorithm is more efficient that the one applied in part (a).
3. Suppose you wish to sample from a standard normal distribution truncated to the
left by 2. Devise an efficient accept/reject algorithm for simulating from this
distribution. Test the algorithm and find the acceptance rate.
0.0 0.2 0. 4 0.6 0. 8 1.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
p

Partial preview of the text

Download Practice Homework 2 - Computational Statistics | MATH 758 and more Assignments Statistics in PDF only on Docsity!

MATH 758 โ€“ HOMEWORK 2

  1. Simulation of a beta(5, 2) curve.

(a) Write a R function to simulate n values of a beta(5, 2) random variable using an accept/reject algorithm using a uniform bounding function. One of the output arguments for the function should be the acceptance rate of the algorithm.

(b) Write a second R function to simulate n values of a beta(5, 2) variate using a triangular bounding function. (As the figure below indicates, the beta(5, 2) curve is bounded above by the function y = 3.16 x.)

(c) Simulate 1000 values using the two algorithms you programmed in parts (a) and (b). Confirm in each case that you have simulated 1000 values of a beta(5, 2) variable. Compare the two algorithms with respect to (1) acceptance rate and (2) speed.

  1. In Example 6.2, ten independent observations (8,3, 4, 3, 1, 7, 2, 6, 2 ,7) are observed from the model Xi| distributed Poisson(l) and log  is distributed normal with mean 4 and standard deviation 0.5.

(a) Apply rejection sampling using the envelope function suggested in the exercise. Try out the method and confirm that the acceptance rate is around 30%.

(b) Construct a more efficient envelope using a normal distribution. Demonstrate that your algorithm is more efficient that the one applied in part (a).

  1. Suppose you wish to sample from a standard normal distribution truncated to the left by 2. Devise an efficient accept/reject algorithm for simulating from this distribution. Test the algorithm and find the acceptance rate.

0.0 0.2 0.4 0.6 0.8 1.

p