Spring 2009 STATISTICS 580 Assignment No. 2 (40 points) 1. The R function uni(seed,n) (available in the file uni.R in the Downloads folder) implements an MCG with m = 213 − 1 and a = 17. Generate 1000 numbers in a vector x. Obtain a plot of the successive pairs (xi+1 , xi ) as shown in class. A shuffler can be used to break-up serial correlation in sequences generated by a random number generator. Use the R function uni2(seed,n) (uni2.R in the Downloads folder) implementing the Bays-Durham shuffler described in the notes to obtain a sequence of 1000 numbers with the same seed used previously and plot the successive pairs (xi+1 , xi ) as before. Note that uni2() also uses the same MCG with a = 17. Turn in the two plots. 2. Use the inverse cdf method to construct algorithms for generating random variables from each of the following distributions: a) Beta(1,b): f (x) = b(1 − x)b−1 , b) c) α Pareto: f (x) = xαk α α+1 , 1 Cauchy: f (x) = π(1+x 2) , d) Log-Logistic: f (x) = > 0, b > 0, 0≤x≤1 0<k<x<∞ −∞ < x < ∞ α(x/β)α−1 , β[1+(x/β)α ]2 α, β > 0, x>0 e) The trapezoidal distribution defined by: f (x) = 0 (x − c)/ab , x<c , c≤x≤a+c 1/b , a+c≤x≤b+c (a + b + c − x)/ab , b + c ≤ x ≤ a + b + c 0 , quadx > a + b + c Present each algorithm in the simplified form shown in class notes. [Not necessary to write code] 3. To derive an algorithm based on the rejection method for generating random variates from the Gamma(α,1) for the case 0 < α < 1, consider the majorizing function q(x) = 0 , x≤0 xα−1 /Γ(α) , 0 < x ≤ 1 e−x /Γ(α) , x>1 Present the algorithm in the simplified form used in class notes. Write an R function to implement your algorithm to return a single random variate from Gamma(α, β) where 0 < α < 1. You may call runif() to generate the necessary uniforms. Note: The density function of the Gamma distribution with parameters α and β is given by f (x) = 1 xα−1 e−x/β , Γ(α)β α x > 0, α, β > 0 . When the scale parameter β = 1, the distribution is called the Standard Gamma. 4. A random variable X has the density f (x) = 2(x3 + 2x7 ), 1 0 ≤ x ≤ 1, a) Find the CDF of X and explain whether or not it is difficult to generate samples of X using the inverse transform method. b) Develop a composition algorithm to generate a value of X. You must give the algorithm in standard and simplified form. c) Describe an acceptance-rejection algorithm to generate a value of X taking g() to be the uniform density on (0, 1). d) Note that U (0, 1) is a Beta distribution. Describe an acceptance-rejection algorithm to generate a value of X taking g() to be an appropriate Beta density from which it is easy to generate random varibles and provides a better envelope than in part (c). (Be sure to specify the sampling density g(), a method to generate variates from that distribution, and the constant c, that you recommend.) 5. Write an R function discrete(p,mean) using Chen and Asau indexed search method to return a random variate from a specified discrete distribution with a given mean. The function setq(p,m) is called in discrete (with m set to 2 x mean), to set-up the q-table. To use this function, tabulate the cdf of the distribution in a vector p where p[i] = Pr(X ≤ i) for i = 0, 1, . . . , while 1 − Pr(X > i) > .1e − 10. Use the R function runif() to generate the Uniform r.n.’s required. Use discrete() to generate random samples from from Poisson with mean λ as specified below and use these samples to do the following: (a) Recall that the variance of the Poisson distribution λ is the same as the mean. Thus for some statistical analyses, Poisson data may require a transformation that makes the variance independent of the mean. This type of transformation is called a variance stabilizing√transformation. Two such transformations used in practice are the log (x + 1) and the x + 1 transformations. For λ = 1.0, 2.0, . . . , 10.0, compute and tabulate the sample variances of samples of size 20 generated from Poisson distribution using discrete() and transformed using each of the above transformations. (b) To examine the Normal approximation to the Poisson, generate samples of size 100 each of Poisson variates with λ = 5.0, 15.0, 30.0, respectively, and use functions stem(), hist(), and density() to obtain plots. Plot these 9 plots to a page using the mfrow= option. Composition Method Suppose a density f (x) can be partitioned as f (x) = p1 · f1 (x) + p2 · f2 (x) where p1 > 0, p2 > 0, p1 + p2 = 1 and f1 and f2 are density functions (or probability functions). To generate from a distribution with a density that can be partitioned like this we can use: Algorithm: 1. Generate u1 , u2 . 2. If u1 < p1 , generate X from F1 using u2 Else generate X from F2 using u2 3. Return X. This can be generalized to any number of partitions and note that the support of f must be the union of the supports of the component densities. Due Thursday, February 19, 2009 2