Homework 2 Dr. Purna Gamage 9/8/2020 set.seed(225) Problem 1 (5 points each X 4 =total 20 points) Consider the random variable defined by counting the number of failures until the first success, for independent trials with success probability p. Given p between 0 and 1, the R commands myattempts(p) and rgeom(1,p) both simulate this random variable. Find a way of demonstrating that the two commands indeed give the same results, for five different values of p. You may find the table() function useful. Choose five p’s of your choice, e.g. p ∈ {.1, .3, .5, .7, .9}. Run myattempts and rgeom each 10000 times. Answer any 4 from the following 5 parts (a)-(e) a. For the first p, Store the fraction of outcomes in the simulation in the columns of a suitable data frame and compare (Hint: use 3 columns to compare rgeom(),myattempts() and dgeom() ) b. For the second p, Compare distribution by computing statistics such as mean and standard deviation. c. For the third p, plot both distributions as histograms in the same plot. d. For the fourth p, make side-by-side box plots. e. For the fifth p, plot the two empirical distribution functions in the same plot. Problem 2 (7 points each X 2 =total 14 points) Consider the following random experiment: draw a uniformly distributed random number X1 from the interval (0, 1). Next, draw a uniformly distributed random number X2 from the interval (0, 1 + X1), a uniformly distributed random number X3 from the interval (0, 1 +X2) and so on until X10. Use a monte carlo simulation to give an approximate answer to What is the mean value of X10? and use a histogram to identify the distribution of X10. X1 ∼ unif(0, 1) X2 ∼ unif(0, 1 +X1) X3 ∼ unif(0, 1 +X2) . . . X10 ∼ unif(0, 1 +X9) The R command for drawing a uniformly distributed random number from the interval (0, b) is runif(1,min = 0, max = b). Problem 3 (4 points each X 4 =total 16 points) Suppose X has a Gamma distribution with shape parameter r = 2.5 and scale parameter ρ = 5. Use R to compute the following quantities: \ a. Prob(X ≤ 10) 1 b. Prob(X > 5) c. Prob(|X − 8| < 1, and d. z such that Prob(X < z) = .95. (Hint:|X − 8| < 1 is equivalent to 7 < X < 9) Problem 4 (5 points each X 3 =total 15 points) Probability theory says that a binomial distribution, B(n, p) is close to that of a normal distribution with mean np and standard deviation √ np(1− p), if np and n(1− p) are both sufficiently large, e.g. at least 10. Check this by plotting both cumulative distribution functions in the same figure, using a staircase plot for the binomial distribution and a line plot for the normal distribution, for three different cases: a case where both np and n(1− p) are large, a case where np is large and n(1− p) < 10, and a case where np < 10 and n(1− p) < 10. Describe what happens in all three cases. In what sense are the cdf’s not close in cases 2 and 3? (Hint: Compare with a cdf of the normal distribution) Problem 5 (4 points each X 5 =total 20 points) A graphical technique for checking whether a sample has an approximate normal distribution is a “quantile- quantile” plot. The R command is qqnorm(x), where x is the vector of sample values. If the plot is approximately a straight line, then this suggests that the sample comes from a normal distribution. Explore this by making qqnorm plots of samples of size 10, 20, 40, 100, 400 from a standard normal distribution. How close to straight lines are the plots in each case? How do the plots differ from straight lines? Problem 6 (5 points each X 3 =total 15 points) If X has a continuous distribution with cumulative distribution function F , then the new random variable U = F (X) has a uniform U(0, 1) distribution. Verify this with simulations for three different continuous distributions of your choice, by making a random sample of sufficient size, sorting it, plugging it into the cdf F , and plotting the result. Bonus Problem (10 points) Suppose for X = X1 + X2 is the sum of two exponentially distributed random variables with the same parameter λ. Then Xα is very nearly normally distributed for a suitable choice of α. Determine an approximate value for α (within 0.05), using a simulation and qqnorm plots. 2
欢迎咨询51作业君