You are on page 1of 1

Advanced Statistical Programming Using R

STA 531 HOMEWORK 4 Fall, 2012

Due Thursday, October 11th. Include all RELEVANT code (well commented). I do NOT want to see printouts of large matrices or vectors.

Exercises:
1. Let X1 , . . . , Xn U nif (0, 1). Furthermore, suppose that n is odd. (a) Write a function in R for the density of any order statistic. In other words, your function will read in an x, j, and n from the forumla in class and return the density. Use the factorial( ) function. (b) Suppose that n = 3. Plot the density of the median (middle order statistic). (c) Find the probability that the median is between .2 and .8. In R, you nd approximate areas under a curve using the integrate( ) function. (d) Shade the region under the curve between .2 and .8. (e) It turns out that when X1 , . . . , Xn U nif (0, 1), the j-th order statistic is Beta(j, nj +1). Verify that your probability above is correct. 2. Suppose that X 2 . 3 (a) Draw a single random x from X and nd P (X x). (b) Repeat the previous step 5,000 times using the replicate( ) function. Plot the histogram of these 5,000 values (make sure to set freq=FALSE). (c) What distribution does your histogram look like? What are we verifying through simulations? 3. Let X be a random variable with density: fX (x; ) = 1 1 exp (x 5) , x > 5
iid iid

(a) Write code that will return cumulative probabilities for any x and (ie. P (X x)). You can either calculate the cumulative distribution function or use the density. (b) Generate 5,000 random values from a uniform distribution with bounds 0 and 1. Put these in a vector called u. (c) Suppose that = 2. For each element of u, nd the value, qi such that P (X qi ) = u[i]. (d) Plot the histogram of the qi s. This should look like an exponential distribution thats been shifted to the right.

You might also like