
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

(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.
(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).
0.0 0.2 0.4 0.6 0.8 1.
p