text
stringlengths
270
6.81k
1 2 3 2 X0 2 X2 2 X0 2 1 1 2 high, low, high 1 3, low 2 3, and pi j 1 4 3 4 1 6 5 6. Compute the following quantities. (a) P X0 (b) P X0 (c) P X1 (d) P X3 (e) P X1 11.2.3 Consider a Markov chain with S high low high X0 high X2 high high low 0 1, and pi a) Compute Pi X2 (b) Compute P0 X3 1. 11.2.4 Consider again the Markov chain with S for all four combinations of i 0 1 and j S. pi a) Compute a stationary distribution (b) Compute limn (c) Compute limn P0 Xn P1 Xn 0. 0. for this chain. i Chapter 11: Advanced Topic — Stochastic Processes 639 11.2.5 Consider the Markov chain of Example 11.2.5, with S and pi j 1 1 2 0 0 1 10 10. Compute the following quantities. 1 (a) P2 X1 2 (b) P2 X1 3 (c) P2 X1 1 (d) P2 X2 2 (e) P2 X2 3 (f) P2 X2 3 (g) P2 X3 1 (h) P2 X3 7 (i) P2 X1 7 (j) P2 X2 (k) P2 X3 7 (l) maxn P2 Xn steps, for any n) (m) Is this Markov chain irreducible? 11.2.6 For each of the following transition probability matrices, determine (with ex­ planation) whether it is irreducible, and whether it is aperiodic. (a) 7 (i.e., the largest probability of going from state 2 to state 7 in n (b) (c) (d) (e) pi pi pi j pi j pi 640 (f) Section 11.2: Markov Chains pi 11.2.7 Compute a stationary distribution for the Markov chain of Example 11.2.4. (Hint: Do not forget Example 11.2.15.) 11.2.8 Show that the random walk on the circle process (see Example 11.2.6) is (a) ir
reducible. (b) aperiodic. (c) reversible with respect to its stationary distribution. 11.2.9 Show that the Ehrenfest’s Urn process (see Example 11.2.7) is (a) irreducible. (b) not aperiodic. (c) reversible with respect to its stationary distribution. 11.2.10 Consider the Markov chain with S 1 2 3, and pi a) Determine (with explanation) whether or not the chain is irreducible. (b) Determine (with explanation) whether or not the chain is aperiodic. (c) Compute a stationary distribution for the chain. (d) Compute (with explanation) a good approximation to P1 X500 11.2.11 Repeat all four parts of Exercise 11.2.10 if S 1 2 3 and 2. pi 11.2.12 Consider a Markov chain with S 1 2 3 and pi Hint: Do not forget (a) Is this Markov chain irreducible and aperiodic? Explain. Theorem 11.2.7.) (b) Compute P1 X1 (c) Compute P1 X2 (d) Compute P1 X3 (e) Compute limn 11.2.13 For the Markov chain of the previous exercise, compute P1 X1 11.2.14 Consider a Markov chain with S 3. 3. 3. P1 Xn 1 2 3 and 3. (Hint: find a stationary distribution for the chain.) X2 5. pi. Chapter 11: Advanced Topic — Stochastic Processes 641 (a) Compute the period of each state. (b) Is this Markov chain aperiodic? Explain. 11.2.15 Consider a Markov chain with S 1 2 3 and pi a) Is this Markov chain irreducible? Explain. (b) Is this Markov chain aperiodic? Explain. PROBLEMS 11.2.16 Consider a Markov chain with S 1 2 3 4 5, and pi for this chain. (Hint: Use reversibility, as in Compute a stationary distribution Example 11.2.19.) 11.2.17 Suppose 100 lily pads are arranged in a circle, numbered 0 1 99 (with pad 99 next to pad 0). Suppose a frog begins at pad 0 and each second
either jumps one pad clockwise, or jumps one pad counterclockwise, or stays where it is — each with probability 1 3. After doing this for a month, what is the approximate probability that the frog will be at pad 55? (Hint: The frog is doing random walk on the circle, as in Example 11.2.6. Also, the results of Example 11.2.17 and Theorem 11.2.8 may help.) 11.2.18 Prove Theorem 11.2.4. (Hint: Proceed as in the proof of Theorem 11.2.3, and use induction.) 11.2.19 In Example 11.2.18, prove that j 0 and when j when j i pi j i S d. DISCUSSION TOPICS 11.2.20 With a group, create the “human Markov chain” of Example 11.2.9. Make as many observations as you can about the long­term behavior of the resulting Markov chain. 11.3 Markov Chain Monte Carlo In Section 4.5, we saw that it is possible to estimate various quantities (such as prop­ erties of real objects through experimentation, or the value of complicated sums or integrals) by using Monte Carlo techniques, namely, by generating appropriate random 642 Section 11.3: Markov Chain Monte Carlo variables on a computer. Furthermore, we have seen in Section 2.10 that it is quite easy to generate random variables having certain special distributions. The Monte Carlo method was used several times in Chapters 6, 7, 9, and 10 to assist in the implementa­ tion of various statistical methods. However, for many (in fact, most!) probability distributions, there is no simple, direct way to simulate (on a computer) random variables having such a distribution. We illustrate this with an example. EXAMPLE 11.3.1 Let Z be a random variable taking values on the set of all integers, with P Z j C j 1 2 4e 3 j cos2 j (11.3.1) for j Now suppose that we want to compute the quantity A 1 0 1 2 3, where C 2 1 j j E Z Well, if we could generate i.i.d. random variables Y1 Y2 given by (11.3.1), for very large M, then we could estimate A by A A 1 M M i 1 Yi 20 2. 1 2 4e 3 j
cos2 j 20 2. YM with distribution Then A would be a Monte Carlo estimate of A. The problem, of course, is that it is not easy to generate random variables Yi with this distribution. In fact, it is not even easy to compute the value of C. Surprisingly, the difficulties described in Example 11.3.1 can sometimes be solved using Markov chains. We illustrate this idea as follows. EXAMPLE 11.3.2 In the context of Example 11.3.1, suppose we could find a Markov chain on the state of all integers, which was irreducible and aperi­ space S 1 2 4e 3 j cos2 j C j odic and which had a stationary distribution given by for j 1 0 1 2 2 S j If we did, then we could run the Markov chain for a long time N, to get random X N. For large enough N, by Theorem 11.2.8, we would have values X0 X1 X2 P X N j j C j 1 2 4e 3 j cos2 j. Hence, if we set Y1 j approximately equal to (11.3.1), for all integers j. That is, the value of X N would be approximately as good as a true random variable Y1 with this distribution. X N, then we would have P Y1 Once the value of Y1 was generated, then we could repeat the process by again running the Markov chain, this time to generate new random values 0 X [2] X [2] 1 X [2] 2 X [2] N (say). We would then have P X [2] N j j C j 1 2 4e 3 j cos2 j. Chapter 11: Advanced Topic — Stochastic Processes 643 X [2] Hence, if we set Y2 (11.3.1), for all integers j. N, then we would have P Y2 j approximately equal to Continuing in this way, we could generate values Y1 Y2 Y3 YM, such that these are approximately i.i.d. from the distribution given by (11.3.1). We could then, as before, estimate A by A A 1 M M i 1 Yi 20 2. This time, the approximation has two sources of error. First, there is Monte Carlo error because M might not be large enough. Second, there is
Markov chain error, because N might not be large enough. However, if M and N are both very large, then A will be a good approximation to A. We summarize the method of the preceding example in the following theorem. Theorem 11.3.1 (The Markov chain Monte Carlo method) Suppose we wish to estimate the expected value A S, with j for j j M, we can generate values P Z 1 X [i] X [i] X [i] 0 X [i] N from some Markov chain that is irreducible, aperiodic, and j as a stationary distribution. Let has S. Suppose for i where P Z E h Z 0 for i] N. If M and N are sufficiently large, then A A. It is somewhat inefficient to run M different Markov chains. Instead, practitioners often just run a single Markov chain, and average over the different values of the chain. For an irreducible Markov chain run long enough, this will again converge to the right answer, as the following theorem states. Theorem 11.3.2 (The single­chain Markov chain Monte Carlo method) Suppose we wish to estimate the expected value A for j X0 X1 X2 has where P Z E h Z j S. Suppose we can generate values X N from some Markov chain that is irreducible, aperiodic, and j as a stationary distribution. For some integer B S, with P Z 0 for j 0, let Xi. If N B is sufficiently large, then A A. Here, B is the burn­in time, designed to remove the inuence of the chain’s starting value X0. The best choice of B remains controversial among statisticians. However, if the starting value X0 is “reasonable,” then it is okay to take B 0, provided that N is sufficiently large. This is what was done, for instance, in Example 7.3.2. 644 Section 11.3: Markov Chain Monte Carlo These theorems indicate that, if we can construct a Markov chain that has i as a stationary distribution, then we can use that Markov chain to estimate quantities associated with i. This is a very helpful trick, and it has made the Markov chain Monte Carlo method into one of the
most popular techniques in the entire subject of computational statistics. However, for this technique to be useful, we need to be able to construct a Markov i as a stationary distribution. This sounds like a difficult problem! i were very simple, then we would not need to use Markov chain Monte is complicated, then how can we possibly construct a Markov chain that has Indeed, if Carlo at all. But if chain that has that particular stationary distribution? i Remarkably, this problem turns out to be much easier to solve than one might expect. We now discuss one of the best solutions, the Metropolis–Hastings algorithm. 11.3.1 The Metropolis–Hastings Algorithm Suppose we are given a probability distribution construct a Markov chain on S that has i as a stationary distribution? i on a state space S. How can we One answer is given by the Metropolis–Hastings algorithm. It designs a Markov chain that proceeds in two stages. In the first stage, a new point is proposed from some proposal distribution. In the second stage, the proposed point is either accepted or rejected. If the proposed point is accepted, then the Markov chain moves there. If it is rejected, then the Markov chain stays where it is. By choosing the probability of accepting to be just right, we end up creating a Markov chain that has i as a stationary distribution. The details of the algorithm are as follows. We start with a state space S, and i on S. We then choose some (simple) Markov chain S called the proposal distribution. Thus, we : i j S. However, we do not assume 1 for each i j S qi j is a stationary distribution for the chain qi j ; indeed, the chain qi j might a probability distribution transition probabilities qi j require that qi j that i not even have a stationary distribution. 0, and Given Xn i, the Metropolis–Hastings algorithm computes the value Xn 1 as follows. 1. Choose Yn 1 j according to the Markov chain qi j. 2. Set i j min 1 j q ji i qi j (the acceptance probability). 3. With probability i j, let Xn 1 Otherwise, with probability 1 proposal Yn 1). Yn 1 i j, let Xn 1 j (i.e., accepting the proposal Yn 1). i (
i.e., rejecting the Xn The reason for this unusual algorithm is given by the following theorem. Theorem 11.3.3 The preceding Metropolis–Hastings algorithm results in a Markov chain X0 X1 X2 i as a stationary distribution. which has Chapter 11: Advanced Topic — Stochastic Processes 645 PROOF See Section 11.7 for the proof. We consider some applications of this algorithm. EXAMPLE 11.3.3 As in Example 11.3.1, suppose S 2 1 0 1 2 and j C j 1 2 4e 3 j cos2 j, for j S. We shall construct a Markov chain having i as a stationary distribution. We first need to choose some simple Markov chain qi j. We let qi j be simple 0 1 2, so that qi j 1, and qi j 1 2 if j 1 or j i i random walk with p otherwise. We then compute that if j i 1 or j i 1, then i j min 1 min 1 q ji qi j j i j min 1 i 1 2 4e 3 j cos2 j 1 2 4e3i cos2 4e 3 j cos2 j 1 2 4e3i cos2 i. (11.3.2) Note that C has cancelled out, so that always be the case.) Hence, we see that for a computer to calculate. i j does not depend on C. (In fact, this will i j, while somewhat messy, is still very easy Given Xn i, the Metropolis–Hastings algorithm computes the value Xn 1 as follows. 1. Let Yn 1 Xn 1 or Yn 1 Xn 1, with probability 1 2 each. 2. Let j Yn 1, and compute i j as in (11.3.2). 3. With probability i j, let Xn 1 Xn let Xn 1 i. Yn 1 j. Otherwise, with probability 1 i j, These steps can all be easily performed on a computer. If we repeat this for n j N 1 for some large number N of iterations, then we will obtain a random 0 1 2 variable X N, where P X N EXAMPLE 11.3.4 Again, let S Let the proposal distribution qi j correspond to a simple random walk with p so that Yn 1 1 with probability 1 4, and Yn 1 1
2 4e 3 j cos2 j S. 1 4, 1 with probability 3 4., and this time let 1 0 1 2 K e j 4 for all j for j C j Xn Xn S. 2 j j In this case, we compute that if j i j min 1 q j i qi j j i min 1 i 1, then If instead j i 1, then min 1 3e j 4 i 4. (11.3.3) i j min 1 q j i qi j j i min min 11.3.4) 646 Section 11.3: Markov Chain Monte Carlo (Note that the constant K has again cancelled out, as expected.) Hence, again i j is very easy for a computer to calculate. Given Xn i, the Metropolis–Hastings algorithm computes the value Xn 1 as follows. 1. Let Yn 1 3 4. Xn 1 with probability 1 4, or Yn 1 Xn 1 with probability 2. Let j Yn 1, and compute i j using (11.3.3) and (11.3.4). 3. With probability i j, let Xn 1 Xn let Xn 1 i. Yn 1 j. Otherwise, with probability 1 i j, Once again, these steps can all be easily performed on a computer; if repeated for some large number N of iterations, then P X N j K e j 4 for j S. j The Metropolis–Hastings algorithm can also be used for continuous random vari­ ables by using densities, as follows. EXAMPLE 11.3.5 Suppose we want to generate a sample from the distribution with density proportional to f y e y4 1 y 3. f y dy How can we generate a random So the density is C f y, where C variable Y such that Y has approximately this distribution, i.e., has probability density approximately equal to C f y? 1 Let us use a proposal distribution given by an N x 1 distribution, namely, a nor­ x, we choose Yn 1 y x 2 2 mal distribution with mean x and variance 1. That is, given Xn by Yn 1 this corresponds to a proposal density of q x y N x 1. Because the N x 1 distribution has density 2 y x 2 2. 1 2 e 1 2 e 2 As for the acceptance probability x y, we again use densities, so that x y min
min 1 min Ce y4 2 Ce x 4 2 3 e y4 x4. 11.3.5) Given Xn x, the Metropolis–Hastings algorithm computes the value Xn 1 as follows. 1. Generate Yn 1 N Xn 1. 2. Let y Yn 1, and compute x y as before. 3. With probability 1 x y, let Xn 1 x y, let Xn 1 Xn x. Yn 1 y. Otherwise, with probability Chapter 11: Advanced Topic — Stochastic Processes 647 Once again, these steps can all be easily performed on a computer; if repeated for some large number N of iterations, then the random variable X N will approximately have density given by C f y. 11.3.2 The Gibbs Sampler In Section 7.3.3 we discussed the Gibbs sampler and its application in a Bayesian statistics problem. As we will now demonstrate, the Gibbs sampler is a specialized version of the Metropolis–Hastings algorithm, designed for multivariate distributions. It chooses the proposal probabilities qi j just right so that we always have i j 1, i.e., so that no rejections are ever required. Suppose that S 2 1 0 1 2 the set of all ordered pairs of integers i etc.) Suppose that some distribution q 1 i j i as follows. j Let V i S : j2 i2. That is, V i and j agree in their second coordinate. Thus, V i through the point i. In terms of this definition of V i, define q 1 i j in their second coordinate. If j then define 2 i.e., S is S, is defined on S. Define a proposal distribution i1 i2. (Thus, 2 3 1 0 1 2 S, and 6 14 is the set of all states j S such that i is a vertical line in S, which passes V i, i.e., if i and j differ V i, i.e., if i and j agree in their second coordinate, 0 if One interpretation is that, if Xn i, and P Yn 1 distribution of Yn 1 is the conditional distribution of the second coordinate must be equal to i2., what is In terms of this choice of q 1 i j V i. Hence, also V j q 1 i j j
S, then the i, conditional on knowing that for j i j? Well, if j V i, then i V j, and i j min 1 min 1 j q 1 ji i q 1 i j j i i j min min 1 1 1. That is, this algorithm accepts the proposal Yn 1 with probability 1, and never rejects at all! Now, this algorithm by itself is not very useful because it proposes only states in V i, so it never changes the value of the second coordinate at all. However, we can i1, so that H i similarly define a horizontal line through i by H i is the set of all states j such that i and j agree in their first coordinate. That is, H i is a horizontal line in S that passes through the point i. S : j1 j 648 Section 11.3: Markov Chain Monte Carlo We can then define q 2 i j (i.e., if i and j agree in their first coordinate), then 0 if j H i (i.e., if i and j differ in their first coordi­ nate), while if As before, we compute that for this proposal, we will always have i j 1, i.e., the Metropolis–Hastings algorithm with this proposal will never reject. The Gibbs sampler works by combining these two different Metropolis–Hastings i, it produces a algorithms, by alternating between them. That is, given a value Xn value Xn 1 as follows. 1. Propose a value Yn 1 V i according to the proposal distribution q 1 i j. 2. Always accept Yn 1 and set j Yn 1 thus moving vertically. 3. Propose a value Zn 1 H j according to the proposal distribution q 2 i j. 4. Always accept Zn 1 thus moving horizontally. 5. Set Xn 1 Zn 1. In this way, the Gibbs sampler does a “zigzag” through the state space S, alternately moving in the vertical and in the horizontal direction. In light of Theorem 11.3.2, we immediately obtain the following. Theorem 11.3.4 The preceding Gibbs sampler algorithm results in a Markov chain i as a stationary distribution. X0 X1 X2 that has The Gibbs sampler thus provides a particular way of implementing the Metropolis– Hastings
algorithm in multidimensional problems, which never rejects the proposed values. Summary of Section 11.3 In cases that are too complicated for ordinary Monte Carlo techniques, it is pos­ sible to use Markov chain Monte Carlo techniques instead, by averaging values arising from a Markov chain. The Metropolis–Hastings algorithm provides a simple way to create a Markov chain with stationary distribution i. Given Xn, it generates a proposal Yn 1 from a proposal distribution qi j, and then either accepts this proposal (and sets Xn 1 Xn) with probability 1 Alternatively, the Gibbs sampler updates the coordinates one at a time from their conditional distribution, such that we always have i j Yn 1) with probability i j, or rejects this proposal (and sets Xn 1 i j. 1. Chapter 11: Advanced Topic — Stochastic Processes 649 EXERCISES i i i Ce i 13 4 for i i e i 13 4 11.3.1 Suppose 1 which uses simple random walk with p 11.3.2 Suppose C 1 i i. Describe in detail a Metropolis–Hastings algorithm for i, S 2 1 0 1 2, where C 1 2 for the proposals. 6 5 8 for i C i, where 6 5 8. Describe in detail a Metropolis–Hastings algorithm for 1 0 1 2 S 2 i, which uses simple random walk with p 5 8 for the proposals. 11.3.3 Suppose for i, where. Describe in detail a Metropolis–Hastings algorithm for 1 0 1 2 S 2 i, which uses simple random walk with p 7 9 for the proposals. R1. Let K e x 4 x 6 x8 1 for x dx 11.3.4 Suppose f x Describe in detail a Metropolis–Hastings algorithm for the distribution having density K f x, which uses the proposal distribution N x 1, i.e., a normal distribution with mean x and variance 1. dx. 11.3.5 Let Describe in detail a Metropolis–Hastings algorithm for the distribution having density K f x, which uses the proposal distribution N x 10, i.e., a normal distribution with mean x and variance 10. R1, and let K e x4 x 6 x 8 e x 4 x6 x 8 for COMPUTER EXERCISES 11.3.6 Run the algorithm of Exercise 11.3.1. Discuss the
output. 11.3.7 Run the algorithm of Exercise 11.3.2. Discuss the output. PROBLEMS 11.3.8 Suppose S integers. For i C. Describe in detail a Gibbs sampler algorithm for this distribution, i.e., S is the set of all pairs of positive i2 for appropriate positive constant S, suppose C 2i1 1 2 3 1 2 3 i1 i2 i i. COMPUTER PROBLEMS 11.3.9 Run the algorithm of Exercise 11.3.4. Discuss the output. 11.3.10 Run the algorithm of Exercise 11.3.5. Discuss the output. DISCUSSION TOPICS 11.3.11 Why do you think Markov chain Monte Carlo algorithms have become so popular in so many branches of science? (List as many reasons as you can.) 11.3.12 Suppose you will be using a Markov chain Monte Carlo estimate of the form A 1 M M i 1 h X [i] N. 650 Section 11.4: Martingales Suppose also that, due to time constraints, your total number of iterations cannot be more than one million. That is, you must have N M 1,000,000. Discuss the advan­ tages and disadvantages of the following choices of N and M. (a) N 1,000,000 M 1 1, M 1,000,000 (b) N (c) N 100, M 10,000 (d) N 10,000, M 100 1000, M 1000 (e) N (f) Which choice do you think would be best, under what circumstances? Why? 11.4 Martingales In this section, we study a special class of stochastic processes called martingales. We shall see that these processes are characterized by “staying the same on average.” As motivation, consider again a simple random walk in the case of a fair game, i.e., 1 2. Suppose, as in the gambler’s ruin setup, that you start at a and keep c. Let Z be the value that you end up 0. We know from Theorem 11.1.2 1 with p going until you hit either c or 0, where 0 with, so that we always have either Z c that in fact P Z a c, so that P Z Let us now consider the expected value of Z. We have that a c or Z 0 a
c 0P Z 0 c a c a. z R1 That is, the average value of where you end up is a. But a is also the value at which you started! This is not a coincidence. Indeed, because p 1 2 (i.e., the game was fair), this means that “on average” you always stayed at a. That is, Xn is a martingale. 11.4.1 Definition of a Martingale We begin with the definition of a martingale. For simplicity, we assume that the mar­ tingale is a Markov chain, though this is not really necessary. be a Markov chain. The chain is a martingale Definition 11.4.1 Let X0 X1 X2 if for all n 0. That is, on average the 0 1 2 chain’s value does not change, regardless of what the current value Xn actually is., we have E Xn 1 Xn Xn EXAMPLE 11.4.1 Let Xn be simple random walk with p 1, with probability 1 2 each. Hence, or 1 2. Then Xn 1 Xn is equal to either 1 E Xn 1 Xn Xn 1 1 2 1 1 2 0, so Xn stays the same on average and is a martingale. (Note that we will never actually 0. However, on average we will have Xn 1 have Xn 1 Xn Xn 0.) Chapter 11: Advanced Topic — Stochastic Processes 651 EXAMPLE 11.4.2 Let Xn be simple random walk with p or 2 3. Then Xn 1 1, with probabilities 2 3 and 1 3 respectively. Hence, Xn is equal to either 1 E Xn 1 Xn Xn 1 2 3 1 1 3 1 3 0. Thus, Xn is not a martingale in this case. EXAMPLE 11.4.3 Suppose we start with the number 5 and then repeatedly do the following. We either add 3 to the number (with probability 1 4), or subtract 1 from the number (with probability 3 4). Let Xn be the number obtained after repeating this procedure n times. Then, given the value of Xn, we see that Xn 1 Xn Xn 3 with probability 1 4, while Xn 1 1 with probability 3 4. Hence, E
Xn 1 Xn Xn and Xn is a martingale. It is sometimes possible to create martingales in subtle ways, as follows. EXAMPLE 11.4.4 Let Xn again be simple random walk, but this time for general p. Then Xn 1 p. Hence, is equal to 1 with probability p, and to 1 with probability q 1 Xn E Xn 1 Xn Xn 1 p 1 q p q 2 p 1. 1 2, then this is not equal to 0. Hence, Xn does not stay the same on average, If p so Xn is not a martingale. On the other hand, let Zn 1 p p X n, i.e., Zn equals the constant 1 1 corresponds to multiplying Zn by 1 to dividing Zn by 1 probability p, while Xn 1 that, given the value of Zn, we have Xn p p raised to the power of Xn. Then increasing Xn by p p, while decreasing Xn by 1 corresponds 1 with p. But Xn 1 Xn p. Therefore, we see 1 with probability q 1 p p, i.e., multiplying by p 1 E Zn 1 Zn Zn 1 1 p p Zn Zn p p Zn pZn p 1 pZn Zn p Zn 1 p 1 p Zn 0. Accordingly, E Zn 1 Zn Zn is a martingale. 0, so that Zn stays the same on average, i.e., Zn 11.4.2 Expected Values Because martingales stay the same on average, we immediately have the following. 652 Section 11.4: Martingales Theorem 11.4.1 Let Xn be a martingale with X0 n. a. Then E Xn a for all This theorem sometimes provides very useful information, as the following exam­ ples demonstrate. EXAMPLE 11.4.5 Let Xn again be simple random walk with p Xn is a martingale. Hence, if X0 is, for a fair game (i.e., for p your average fortune will always be equal to your initial fortune a. 1 2. Then we have already seen that a for all n. That 1 2), no matter how long you have been gambling, a, then we will have E Xn EXAMPLE 11.4.6 Suppose we start with the number
10 and then repeatedly do the following. We either add 2 to the number (with probability 1 3), or subtract 1 from the number (with proba­ bility 2 3). Suppose we repeat this process 25 times. What is the expected value of the number we end up with? Without martingale theory, this problem appears to be difficult, requiring lengthy computations of various possibilities for what could happen on each of the 25 steps. However, with martingale theory, it is very easy. Indeed, let Xn be the number after n steps, so that X0 10 X1 probability 1 3) or X1 equals either 2 (with probability 1 3) or 9 (with probability 2 3), etc. Then, because Xn 1 1 (with probability 2 3), we have 12 (with Xn E Xn 1 Xn Xn. Hence, Xn is a martingale. It then follows that E Xn X0 10, for any n. In particular, E X25 10. That is, after 25 steps, on average the number will be equal to 10. 11.4.3 Stopping Times a If Xn is a martingale with X0 for all n. However, it is sometimes even more helpful to know that E X T a, where T is a random time. Now, this is not always true; however, it is often true, as we shall see. We begin with another definition. a, then it is very helpful to know that E Xn Definition 11.4.2 Let Xn be a stochastic process, and let T be a random variable taking values in 0 1 2, 0 1 2. That is, when the event T m (i.e., whether or not to “stop” at time m), we are deciding whether or not T. not allowed to look at the future values Xm 1 Xm 2 m is independent of the values Xm 1 Xm 2. Then T is a stopping time if for all m EXAMPLE 11.4.7 Let Xn be simple random walk, let b be any integer, and let b be the first time we hit the value b. Then b is a stopping time because the event b min n 0 : Xn b n depends only on X0 Xn, not on Xn 1 Xn 2. Chapter 11: Advanced
Topic — Stochastic Processes 653 On the other hand, let T 1, so that T corresponds to stopping just before we hit b. Then T is not a stopping time because it must look at the future value Xm 1 to decide whether or not to stop at time m. b A key result about martingales and stopping times is the optional stopping theorem, as follows. Theorem 11.4.2 (Optional stopping theorem) Suppose Xn X0 a, and T is a stopping time. Suppose further that either (a) the martingale is bounded up to time T, i.e., for some M 0 we have Xn for all n (b) the stopping time is bounded, i.e., for some M 0 we have T M. Then E X T equal to the starting value a. a i.e., on average the value of the process at the random time T is is a martingale with T ; or M PROOF For a proof and further discussion, see, e.g., page 273 of Probability: The­ ory and Examples, 2nd ed., by R. Durrett (Duxbury Press, New York, 1996). Consider a simple application of this. EXAMPLE 11.4.8 Let Xn be simple random walk with initial value a and with p be integers. Let T r s for n We conclude that E X T a. s s be the first time the process hits either r or s. Then min r T, so that condition (a) of the optional stopping theorem applies. a, i.e., that at time T, the walk will on average be equal to 1 2. Let r Xn a We shall see that the optional stopping theorem is useful in many ways. EXAMPLE 11.4.9 We can use the optional stopping theorem to find the probability that the simple random walk with p 1 2 will hit r before hitting another value s. Indeed, again let Xn be simple random walk with initial value a and p 1 2, a. We can s Then as earlier, E X T r, i.e., for the probability that the walk hits r before min r a s integers and T with r use this to solve for P X T hitting s. Clearly, we always have either X T r or X T s. Let h h s. Because E X T a, we must have a P X T
hr r. Then h s. 1 E X T hr Solving for h, we see that 1 P X T r a r s s. We conclude that the probability that the process will hit r before it hits s is equal s. Note that absolutely no difficult computations were required to r to a s obtain this result. A special case of the previous example is particularly noteworthy. 654 Section 11.4: Martingales EXAMPLE 11.4.10 In the previous example, suppose r r c and s is precisely the same as the probability of success in the gambler’s ruin problem. The previous example shows that h a c. This gives the same answer r as Theorem 11.1.2, but with far less effort. 0. Then the value h P X T a s s It is impressive that, in the preceding example, martingale theory can solve the gambler’s ruin problem so easily in the case p 1 2. Our previous solution, without using martingale theory, was much more difficult (see Section 11.7). Even more sur­ 1 2, as prising, martingale theory can also solve the gambler’s ruin problem when p follows. EXAMPLE 11.4.11 Let Xn be simple random walk with initial value a and with p be integers. Let T solve the gambler’s ruin problem in this case, we are interested in g We can use the optional stopping theorem to solve for the gambler’s ruin probability g, as follows. c 0 be the first time the process hits either c or 0. To 1 2. Let 0 P X T min a c c Now, Xn is not a martingale, so we cannot apply martingale theory to it. However, let Zn 1 p p Xn. Then Zn has initial value Z0 that Zn is a martingale. Furthermore, 1 p p a. Also, we know from Example 11.4.4 0 Zn max 1 p c 1 p c p p T, so that condition (a) of the optional stopping theorem applies. We conclude 1 p a. E ZT Z0 Now, clearly, we always have either X T (with probability 1 case, ZT p 1. Hence, E ZT p a, we must have 1 g). In the former case, ZT
with probability g) or X T 0 p p c, while in the latter g 1. Because E ZT. Solving for g, we see that 1 1 This again gives the same answer as Theorem 11.1.2, this time for, but again with far less effort. Martingale theory can also tell us other surprising facts. for n that Chapter 11: Advanced Topic — Stochastic Processes 655 EXAMPLE 11.4.12 Let Xn be simple random walk with p the walk hit the value not for sure. Furthermore, conditional on not hitting large, as we now discuss. Let T min 106 takes more than one million steps, in which case T 106. 0. Will 1 some time during the first million steps? Probably yes, but 1, it will probably be extremely 1 2 and with initial value a 1 That is, T is the first time the process hits 1, unless that Now, Xn is a martingale. Also T is a stopping time (because it does not look into the future when deciding whether or not to stop). Furthermore, we always have 106, so condition (b) of the optional stopping theorem applies. We conclude that T E X T 0. a On the other hand, by the law of total expectation, we have. Also, clearly E X T X T 1 1 1 u. Then we conclude that 0 1. Let, so that P X T 1 1 u so that Now, clearly, u will be very close to 1, i.e., it is very likely that within 106 steps the process will have hit 1. Hence, E X T X T 1 is extremely large. We may summarize this discussion as follows. Nearly always we have X T However, very occasionally we will have X T of X T when X T and the case X T martingale)! 1. 1. Furthermore, the average value 1 is so large that overall (i.e., counting both the case X T 1 1), the average value of X T is 0 (as it must be because Xn is a If one is not careful, then it is possible to be tricked by martingale theory, as follows. EXAMPLE 11.4.13 Suppose again that Xn is simple random walk with p a that takes). 1, i.e., T is the first time the process hits 0. Let T 1 2 and with initial value 1 (no matter
how long Because the process will always wait until it hits Because this is true with probability 1, we also have E X T 1, we always have X T 1. 1. On the other hand, again Xn is a martingale, so again it appears that we should have E X T 0. What is going on? The answer, of course, is that neither condition (a) nor condition (b) of the optional stopping theorem is satisfied in this case. That is, there is no limit to how large T might T. Hence, the optional stopping have to be or how large Xn might get for some n theorem does not apply in this case, and we cannot conclude that E X T 0. Instead, E X T 1 here. Summary of Section 11.4 A Markov chain Xn E Xn 1 Xn Xn is a martingale if it stays the same on average, i.e., if 0 for all n. There are many examples. 656 Section 11.4: Martingales A stopping time T for the chain is a nonnegative integer­valued random variable that does not look into the future of Xn. For example, perhaps T b is the first time the chain hits some state b. If Xn bounded, then E X T gambler’s ruin. is a martingale with stopping time T, and if either T or Xn n T is X0. This can be used to solve many problems, e.g., EXERCISES 3 8 Xn Xn Xn P Xn 8 p we let Xn 1 p we let Xn 1 0 1. Compute P Xn 7, while with probability 1 2Xn, while with probability 1 14. Suppose for some n, we 1, i.e., Xn is always either 8, 14. 11.4.1 Suppose we define a process Xn as follows. Given Xn, with probability 3 8 we let Xn 1 Xn C. What value 4, while with probability 5 8 we let Xn 1 of C will make Xn be a martingale? 11.4.2 Suppose we define a process Xn as follows. Given Xn, with probability p we let Xn 1 2. What value of p will make Xn be a martingale? 11.4.3 Suppose we defi
ne a process Xn as follows. Given Xn, with probability p we Xn 2. What value of p let Xn 1 will make Xn be a martingale? 11.4.4 Let Xn be a martingale, with initial value X0 know that P Xn 17 12 P Xn 12, or 17. Suppose further that P Xn 11.4.5 Let Xn be a martingale, with initial value X0 P X8 4 Suppose further that P X8 11.4.6 Suppose you start with 175 pennies. You repeatedly ip a fair coin. Each time the coin comes up heads, you win a penny; each time the coin comes up tails, you lose a penny. (a) After repeating this procedure 20 times, how many pennies will you have on aver­ age? (b) Suppose you continue until you have either 100 or 200 pennies, and then you stop. What is the probability you will have 200 pennies when you stop? 11.4.7 Define a process Xn by X0 Xn 1 hits either 1 or 81. (a) Show that Xn is a martingale. (b) Show that T is a stopping time. (c) Compute E X T. (d) Compute the probability P X T 5. Suppose we know that 1, i.e., X8 is always either 3, 4, or 6. 6. Compute P X8 3Xn with probability 1 4, or 81 be the first time the process Xn 3 with probability 3 4. Let T min 1 that the process hits 1 before hitting 81. 27, and Xn 1 1 6 2 P X8 P X8 P X8 4. 3 PROBLEMS 11.4.8 Let Xn be a stochastic process, and let T1 be a stopping time. Let T2 and T3 stopping time, and which is not? (Explain your reasoning.) i i, for some positive integer i. Which of T2 and T3 is necessarily a T1 T1 Chapter 11: Advanced Topic — Stochastic Processes 657 11.4.9 Let Xn be a stochastic process, and let T1 and T2 be two different stopping times. Let T3 min T1 T2, and T4 max T1 T2. (a) Is T
3 necessarily a stopping time? (Explain your reasoning.) (b) Is T4 necessarily a stopping time? (Explain your reasoning.) 11.5 Brownian Motion The simple random walk model of Section 11.1.2 (with p 1 2) can be extended to an interesting continuous­time model, called Brownian motion, as follows. Roughly, the idea is to speed up time faster and faster by a factor of M (for very large M), while simultaneously shrinking space smaller and smaller by a factor of 1 M. The factors of M and 1 M are chosen just right so that, using the central limit theorem, we can derive properties of Brownian motion. Indeed, using the central limit theorem, we shall see that various distributions related to Brownian motion are in fact normal distributions. Historically, Brownian motion gets its name from Robert Brown, a botanist, who in 1828 observed the motions of tiny particles in solution, under a microscope, as they were bombarded from random directions by many unseen molecules. Brownian motion was proposed as a model for the observed chaotic, random movement of such particles. In fact, Brownian motion turns out not to be a very good model for such movement (for example, Brownian motion has infinite derivative, which would only make sense if the particles moved infinitely quickly!). However, Brownian motion has many useful mathematical properties and is also very important in the theory of finance because it is often used as a model of stock price uctuations. A proper mathematical theory of Brownian motion was developed in 1923 by Norbert Wiener2; as a result, Brownian motion is also sometimes called the Wiener process. We shall construct Brownian motion in two steps. First, we construct faster and where M is large. Then, we take the limit as faster random walks, to be called Y M M to get Brownian motion. t 11.5.1 Faster and Faster Random Walks To begin, we let Z1 Z2 each M 1 2, define a discrete­time random process be i.i.d. with P Zi 1 P Zi 1 1 2 For by Y M 0 0, and for i 0 1 2 so that Zi 1, Y M i M 1 M Z1 Z2 Zi. 2Wiener was such an absent­minded professor that he once got lost and could not find his house. In his
confusion, he asked a young girl for directions, without recognizing the girl as his daughter! 658 Section 11.5: Brownian Motion Intuitively, then, Y M i M is like an ordinary (discrete­time) random walk (with p 1 2), except that time has been sped up by a factor of M and space has been shrunk by a factor of M (each step in the new walk moves a distance 1 M. That is, this process takes lots and lots of very small steps. To make Y M i M into a continuous­time process, we can then “fill in” the missing 1 M]. In this way, values by making the function linear on the intervals [i M i we obtain a continuous­time process Y M t : t 0 which agrees with Y M i M whenever t 1 M. In Figure 11.5.1, we have plotted Y 10 i 10 : i 0 1 20 (the dots) and the corresponding values of Y 10 t : 0 t 20 (the solid line), arising from the realization Z1 Z20 1 1 1 1 1 1, where we have taken 1 10 0 316 Y 0.949 0.949 0.632 0.632 0.632 0.632 0.632 0.316 0.316 0.316 0.316 0.316 0.316 0.000 0.000 0.000 0.000 0.000 ­0.316 ­0.316 ­0.632 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 1.0 t Figure 11.5.1: Plot of some values of Y 10 i 10 and Y 10 t The collection of variables Y M indexed by the continuous time parameter t time stochastic process. : t t 0 is then a stochastic process but is now 0. This is an example of a continuous­ Now, the factors M and M have been chosen carefully, as the following theorem illustrates. Chapter 11: Advanced Topic — Stochastic Processes 659 Theorem 11.5.1 Let Y M (a) For t distributed with mean t. (b) For s t 0, the covariance t 0, the distribution of Y M
t : t 0 be as defined earlier. Then for large M: is approximately N 0 t, i.e., normally Cov Y M t Y M t is approximately equal to min s t. (c) For t s mately N 0 t is approximately independent of Y M. (d) Y M is a continuous function of t. t s 0, the distribution of the increment Y M s, i.e., normally distributed with mean 0 and variance t Y M s t is approxi­ s, and PROOF See Section 11.7 for the proof of this result. We shall use this limit theorem to construct Brownian motion. 11.5.2 Brownian Motion as a Limit We have now developed the faster and faster processes Y M of their properties. Brownian motion is then defined as the limit as M processes Y M that the distribution of Bt : t of Y M t 0. That is, we define Brownian motion Bt : t 0 is equal to the limit as, and some of the 0 by saying of the distribution 0. A graph of a typical run of Brownian motion is in Figure 11.5.2. 2 1 0 ­1 B 0.0 0.5 1.0 1.5 2.0 2.5 t Figure 11.5.2: A typical outcome from Brownian motion. In this way, all the properties of Y M will apply to Brownian motion, as follows. t for large M, as developed in Theorem 11.5.1, 660 Section 11.5: Brownian Motion Theorem 11.5.2 Let Bt : t (a) Bt is normally distributed: Bt (b) Cov Bs Bt (c) if 0 N 0 t (d) the function Bt s s, and furthermore Bt E Bs Bt min s t t, then the increment Bt t 0 is a continuous function. 0 be Brownian motion. Then N 0 t for any t 0; for s t 0; Bs is independent of Bs; Bs is normally distributed: Bt Bs This theorem can be used to compute many things about Brownian motion. EXAMPLE 11.5.1 Let Bt be Brownian motion. What is P B5 N 0 5. Hence, B5 We know that B5 3? 5 N 0 1. We conclude that P
B5 3 P B5 5 3 5 3 5 0 910, where x x 1 2 e s2 2 ds is the cdf of a standard normal distribution, and we have found the numerical value from Table D.2. Thus, about 91% of the time, Brownian motion will be less than 3 at time 5. EXAMPLE 11.5.2 Let Bt be Brownian motion. What is P B7 N 0 7. Hence, B7 We know that B7 4? 7 N 0 1. We conclude that P B7 4 1 1 P B7 4 4 7 1 1 P B7 0 065 7 0 935. 4 7 Thus, over 93% of the time, Brownian motion will be at least 4 at time 7. EXAMPLE 11.5.3 Let Bt be Brownian motion. What is P B8 B6 1 5? We know that B8 B6 N 0 8 6 N 0 2. Hence, B8 B6 2 N 0 1. We conclude that P B8 B6 1 5 P B8 B6 2 1 5 2 1 5 2 0 144. Thus, about 14% of the time, Brownian motion will decrease by at least 1.5 between time 6 and time 8. EXAMPLE 11.5.4 Let Bt be Brownian motion. What is P B2 By Theorem 11.5.2, we see that B5 0 5 B5 B2 1 5? B2 and B2 are independent. Hence, P B2 0 5 B5 B2 1 5 P B2 0 5 P B5 B2 1 5. Now, we know that B2 N 0 2. Hence, B2 2 N 0 1, and P B2 0 5 P B2 2 0 5 2 0 5 2. Chapter 11: Advanced Topic — Stochastic Processes 661 Similarly, B5 B2 N 0 3, so B5 P B5 B2 1 5 We conclude that B2 B2 3 3 B2 N 0 1, and B5 1 P B5 P B2 0 5 B5 B2 1 5 P B2 0 5 0 5 P B5 1 5 2 B2 3 1 5 0 292. Thus, about 29% of the time, Brownian motion will be no more than and will then increase by at least 1.5 between time 2 and time 5. 1 2 at time 2 We note also that
, because Brownian motion was created from simple random 1 2, it follows that Brownian motion is a martingale. This implies walks with p that E Bt N 0 t. 0 for all t, but of course, we already knew that because Bt On the other hand, we can now use the optional stopping theorem (Theorem 11.4.2) to conclude that E BT 0 where T is a stopping time (provided, as usual, that either T is bounded). This allows us to compute certain probabilities, as T or Bt : t follows. EXAMPLE 11.5.5 Let Bt be Brownian motion. Let c hit c before it hits b? 0 b. What is the probability the process will To solve this problem, we let first time the process hits b. We then let T min either hits c or hits b. The question becomes, what is P c is P BT c? c c be the first time the process hits c, and b be the b be the first time the process b? Equivalently, what To solve this, we note that we must have E BT c with probability h, and BT b with probability 1 B0 0. But if h c, P BT h. Hence, we must then BT have 0 E BT hc 1 h b so that h b b c. We conclude that P BT c P c b b b. c (Recall that c 0, so that b c b c here.) Finally, we note that although Brownian motion is a continuous function, it turns out that, with probability one, Brownian motion is not differentiable anywhere at all! This is part of the reason that Brownian motion is not a good model for the movement of real particles. (See Challenge 11.5.15 for a result related to this.) However, Brownian motion has many other uses, including as a model for stock prices, which we now describe. 11.5.3 Diffusions and Stock Prices Brownian motion is used to construct various diffusion processes, as follows. Given Brownian motion Bt, we can let Xt a t Bt, 662 Section 11.5: Brownian Motion where a and are any real numbers, and 0. Then Xt is a diffusion. Here, a is the initial value, (called the drift) is the average rate of increase, and Intuitively, Xt is approximately equal
to the linear function a (called the volatility parameter) represents the amount of randomness of the diffusion. t, but due to the randomness of Brownian motion, Xt takes on random values around this linear function. The precise distribution of Xt can be computed, as follows. Theorem 11.5.3 Let Bt be Brownian motion, and let Xt diffusion. Then (a) E Xt a (b) Var Xt (c) Xt t, 2t, t 2t. N a a t Bt be a PROOF We know Bt not random (i.e., is a constant from the point of view of random variables). Hence, N 0 1, so E Bt 0 and Var Bt t. Also, a t is E Xt E a proving part (a). Similarly, Var Xt Var a proving part (b). t t Bt a t E Bt a t, Bt Var Bt 2Var Bt 2t, Finally, because Xt is a linear function of the normally distributed random variable Bt, Xt must be normally distributed by Theorem 4.6.1. This proves part (c). Diffusions are often used as models for stock prices. That is, it is often assumed Bt for appropriate that the price Xt of a stock at time t is given by Xt values of a,, and. a t EXAMPLE 11.5.6 Suppose a stock has initial price $20, drift of $3 per year, and volatility parameter 1 4. What is the probability that the stock price will be over $30 after two and a half years? 1 4Bt and is thus a Here, the stock price after t years is given by Xt 20 3t diffusion. So, after 2 5 years, we have X2 5 20 7 5 1 4B2 5 27 5 1 4B2 5 Hence, P X2 5 30 P 27 5 P B2 5 1 4B2 5 1 79. 30 P B2 5 30 27 5 1 4 But like before, P B2 5 1 79 1 1 P B2 5 1 79 1 79 2 5 P B2 5 1 0 129. 2 5 1 79 2 5 We conclude that P X2 5 30 0 129. Chapter 11: Advanced Topic — Stochastic Processes 663 Hence, there is just under a 13% chance that the stock will be worth more than $30 after
two and a half years. EXAMPLE 11.5.7 Suppose a stock has initial price $100, drift of $2 per year, and volatility parameter 5 5. What is the probability that the stock price will be under $90 after just half a year? 5 5Bt and is again 5 5B0 5 Here, the stock price after t years is given by Xt 100 2t 5 5B0 5 100 1 0 a diffusion. So, after 0 5 years, we have X0 5 Hence, 99 P X0 5 90 P 99 P B0 5 5 5B0 5 1 64 0 5 1 64 90 P B0 5 0 5 P B0 5 2 32 0 010. 90 99 5 5 0 5 1 64 Therefore, there is about a 1% chance that the stock will be worth less than $90 after half a year. More generally, the drift and volatility leading to more complicated diffusions Xt, though we do not pursue this here. could be functions of the value Xt, Summary of Section 11.5 t 0 is created from simple random walk with p Brownian motion Bt speeding up time by a large factor M, and shrinking space by a factor 1 M. Hence, B0 Bt a continuous function. Diffusions (often used to model stock prices) are of the form Xt N 0 t, and Bt has independent normal increments with is s for 0 min s t, and Bt t, and Cov Bs Bt 0 Bt N 0 t 1 2, by Bt. Bs a s t EXERCISES i M used to construct Brownian motion. 1 1 1 2 (Hint: Don’t forget that 2.) 1 for M 1, M 2, M 3, and M 4 11.5.1 Consider the speeded­up processes Y M Compute the following quantities. (a) P Y 1 1 (b) P Y 2 1 (c) P Y 2 1 (d) P Y M 11.5.2 Let Bt be Brownian motion. Compute P B1 11.5.3 Let Bt be Brownian motion. Compute each of the following quantities. (a) P B2 (b) P B3 (c) P B9 (d) P B26 (e) P B26 3 (f) P B26 3 4 B5 B11 664 Section 11.5: Brownian Motion 2 5
5. 3t B5 B2 0 9 B14 14. 1 B5 E B2 N 0 3. 4 B8 4 2 E B17 B14 2 in two ways. (Hint: Do not forget 2 B13 3 2 B18 6 2Bt be a diffusion (so that a 5 before it hits 15. 15 before it hits 5. 11.5.4 Let Bt be Brownian motion. Compute each of the following quantities. (a) P B2 (b) P B5 (c) P B8 4 11.5.5 Let Bt be Brownian motion. Compute E B13 B8. part (b) of Theorem 11.5.2.) 11.5.6 Let Bt be Brownian motion. Compute E B17 (a) Use the fact that B17 B14 (b) Square it out, and compute E B2 17 11.5.7 Let Bt be Brownian motion. (a) Compute the probability that the process hits (b) Compute the probability that the process hits (c) Which of the answers to Part (a) or (b) is larger? Why is this so? (d) Compute the probability that the process hits 15 before it hits (e) What is the sum of the answers to parts (a) and (d)? Why is this so? 11.5.8 Let Xt Compute each of the following quantities. (a) E X7 (b) Var X8 1 (c) P X2 5 (d) P X17 11.5.9 Let Xt 4Bt. Compute E X3 X5. 11.5.10 Suppose a stock has initial price $400 and has volatility parameter equal to 9. Compute the probability that the stock price will be over $500 after 8 years, if the drift per year is equal to (a) $0. (b) $5. (c) $10. (d) $20. 11.5.11 Suppose a stock has initial price $200 and drift of $3 per year. Compute the probability that the stock price will be over $250 after 10 years, if the volatility parameter is equal to (a) 1. (b) 4. (c) 10. (d) 100. 3, and 12 50 1 5 t 2). 10 5, PROBLEMS 11.5.12 Let B
t be Brownian motion, and let X and variance of X. 11.5.13 Prove that P Bt P Bt x x for any t 0 and any x R1. 2B3 7B5. Compute the mean Chapter 11: Advanced Topic — Stochastic Processes 665 CHALLENGES 11.5.14 Compute P Bs will need to use conditional densities.) 11.5.15 (a) Let f : R1 such that exists K x Bt f y f x R1 be a Lipschitz function, i.e., a function for which there y for all x y R1. Compute K x y, where 0 s t, and x y R1. (Hint: You f t h f t 2 h lim 0 h for any t (b) Let Bt be Brownian motion. Compute R1. E lim 0 h Bt h 2 Bt h 0. for any t (c) What do parts (a) and (b) seem to imply about Brownian motion? (d) It is a known fact that all functions that are continuously differentiable on a closed interval are Lipschitz. In light of this, what does part (c) seem to imply about Brownian motion? DISCUSSION TOPICS 11.5.16 Diffusions such as those discussed here (and more complicated, varying co­ efficient versions) are very often used by major investors and stock traders to model stock prices. (a) Do you think that diffusions provide good models for stock prices? (b) Even if diffusions did not provide good models for stock prices, why might in­ vestors still need to know about them? 11.6 Poisson Processes Finally, we turn our attention to Poisson processes. These processes are models for events that happen at random times Tn. For example, Tn could be the time of the nth fire in a city, or the detection of the nth particle by a Geiger counter, or the nth car passing a checkpoint on a road. Poisson processes provide a model for the probabilities for when these events might take place. More formally, we let a 0, and let R1 R2 having the Exponential a distribution. We let T0 be i.i.d. random variables, each 0, and for n 1, Tn R1 R2
Rn. The value Tn thus corresponds to the (random) time of the nth event. We also define a collection of counting variables Nt, as follows. For t 0, we let Nt max n : Tn t 666 Section 11.6: Poisson Processes That is, Nt counts the number of events that have happened by time t. (In particular, N0 T1, i.e., before the first event occurs.) 0. Furthermore, Nt 0 for all t We can think of the collection of variables Nt for t 0 as being a stochastic process, indexed by the continuous time parameter t 0 is thus another example, like Brownian motion, of a continuous­time stochastic process. 0 is called a Poisson process (with intensity a). This name comes 0. The process Nt : t In fact, Nt : t from the following. Theorem 11.6.1 For any t 0, the distribution of Nt is Poisson at. PROOF See Section 11.7 for the proof of this result. In fact, even more is true. Theorem 11.6.2 Let 0 the distribution of Nti Nti 1 variables Nti t1 t0 Nti 1 is Poisson a ti t2 t3 td. Then for i d,. Furthermore, the random 1 2 ti 1 for i 1 d are independent. PROOF See Section 11.7 for the proof of this result. EXAMPLE 11.6.1 Let Nt be a Poisson process with intensity a Poisson 3a Here, N3 5. What is P N3 Poisson 15. Hence, from the definition of the Poisson 12? distribution, we have P N3 12 e 15 15 12 12! 0 083, which is a little more than 8%. EXAMPLE 11.6.2 Let Nt be a Poisson process with intensity a 2. What is P N6 11? Here N6 Poisson 6a Poisson 12. Hence, P N6 11 e 12 12 11 11! 0 114, or just over 11%. EXAMPLE 11.6.3 Let Nt be a Poisson process with intensity a 4. What is P N2 (Recall that here the comma means “and” in probability statements.) 3 N5 We begin by writing P N2 1 This is just
rewriting the question. However, it puts it into a context where we can use Theorem 11.6.2. 3 N5 4? 3 N5 P N2 N2 4 Indeed, by that theorem, N2 and N5 N2 are independent, with N2 Poisson 8 and N5 N2 Poisson 12. Hence, P N2 3 N5 4 We thus see that the event N2 1 3 N5 N2 3 P N5 N2 e 12 121 1! P N2 P N2 e 8 83 3! 4 is very unlikely in this case. 0 0000021. 1 3 N5 Chapter 11: Advanced Topic — Stochastic Processes 667 Summary of Section 11.6 Poisson processes are models of events that happen at random times Tn. It is assumed that the time Rn Exponential a for some a by time t. It follows that Nt increments, with Nt Tn 1 between consecutive events in 0. Then Nt represents the total number of events t 0 has independent t. Poisson at, and in fact the process Nt Poisson a t for 0 Ns Tn s s EXERCISES t 0 be a Poisson process with intensity a t 0 be a Poisson process with intensity a 5. t 0 be a Poisson process with intensity a 20 3. 20 3 N6 13 3 20. 340 13 N5 13 N6 13 N5 11.6.1 Let N t ing probabilities. (a) P N2 (b) P N5 (c) P N6 (d) P N50 (e) P N2 (f) P N2 (g) P N2 11.6.2 Let N t 6 and P N0 3 11.6.3 Let N t 6 and P N3 11.6.4 Let N t 6 N3 11.6.5 Let N t nation) the conditional probability P N2 6 11.6.6 Let N t explanation) the following conditional probabilities. (a) P N6 (b) P N6 (c) P N9 (d) P N9 (e) P N9 5 N9 5 N9 5 N6 7 N6 12 N6 5. Explain your answer be a Poisson process with intensity a t 0 be a Poisson process with intensity a 2 2 N2 9 t 0 be a Poisson process with intensity a 7. Compute the follow­ 3
. Compute P N1 2 1 3. Compute P N2 3. Compute P N2 0. Compute (with expla­ 1 3. Compute (with PROBLEMS 0 be a Poisson process with intensity a 11.6.7 Let Nt : t let j be a positive integer. (a) Compute (with explanation) the conditional probability P Ns (b) Does the answer in part (a) depend on the value of the intensity a? Intuitively, why or why not? 11.6.8 Let Nt : t of the first event, as usual. Let 0 0 be a Poisson process with intensity a t. 0. Let T1 be the time 0. Let 0 t, and j Nt s s j 668 Section 11.7: Further Proofs 1.) 1 Nt 1 (If you wish, you may use the previous problem, (a) Compute P Ns with j (b) Suppose t is fixed, but s is allowed to vary in the interval 0 t. What does the an­ swer to part (b) say about the “conditional distribution” of T1, conditional on knowing that Nt 1? 11.7 Further Proofs Proof of Theorem 11.1.1 We want to prove that when Xn is a simple random walk, n is a positive integer, and n and n if k is an integer such that k is even, then n k P Xn a k n n k 2 p n k 2q n k 2. For all other values of k, we have P Xn a k 0. Furthermore, E Xn a n 2 p 1. Of the first n bets, let Wn be the number won, and let Ln be the number lost. Then n Wn Ln. Also, Xn a Wn Adding these two equations together, we conclude that n Ln. 2Wn Solving for Wn, we see that Wn a Ln Wn Wn must be an integer, it follows that n k is even. P Xn 0 unless n a k Xn Xn Wn Ln a 2. Because a must be even. We conclude that Xn a n On the other hand, solving for Xn, we see that Xn a 2Wn a a P Xn n. Because 0 W
n 0 if k k Suppose now that k a n P Wn k We conclude that n, it follows that n or k n. n is even, and k 2. But the distribution of Wn is clearly Binomial n p. n. Then from the above, P Xn Xn n n k 2Wn a n, or Xn n, i.e., that P Xn a k n n k 2 p n k 2q n k 2, provided that k n is even and Finally, because Wn a 2Wn n, therefore E Xn k n n. Binomial n p, therefore E Wn a 2E Wn n np. Hence, because a n 2 p 1, a 2np n Xn as claimed. Proof of Theorem 11.1.2 We want to prove that when Xn is a simple random walk, with some initial fortune a and probability p of winning each bet, and 0 0 c, then the probability P c a Chapter 11: Advanced Topic — Stochastic Processes 669 of hitting c before 0 is given by. To begin, let us write s b for the probability P c fortune b, for any 0 out to be easier to solve for all of the values s 0 s 1 s 2 and this is the trick we use. 0 when starting at the initial c. We are interested in computing s a. However, it turns s c simultaneously, b We have by definition that s 0 0 (i.e., if we start with $0, then we can never 1 (i.e., if we start with $c, then we have already won). So, those two 1 are not obtained as win) and s c cases are easy. However, the values of s b for 1 easily. b c Our trick will be to develop equations that relate the values s b for different values of b. Indeed, suppose 1 1. It is difficult to compute s b directly. However, it is easy to understand what will happen on the first bet — we will either lose $1 with probability p, or win $1 with probability q. That leads to the following result. b c Lemma 11.7.1 For 1 b c 1, we have s b ps b 1 qs b 1. (11.7.1) PROOF Suppose first that we win the first
bet, i.e., that Z1 bet, we will have fortune b before reaching 0, except this time starting with fortune b winning this first bet, our chance of reaching c before reaching 0 is now s b still do not know what s b s b and s b 1. After this first 1. We then get to “start over” in our quest to reach c 1 instead of b. Hence, after 1. (We 1 is, but at least we are making a connection between 1.) Suppose instead that we lose this first bet, i.e., that Z1 1. After this first bet, 1 instead of b. 1. we will have fortune b Hence, after this first bet, our chance of reaching c before reaching 0 is now s b 1. We then get to “start over” with fortune b We can combine all of the preceding information, as follows. s b P c P Z1 ps b 0 1 1 0 c qs b 1 P Z1 1 c 0 That is, as claimed. So, where are we? We had c 1 unknowns, s 0 s 1 s c. We now know the two equations s 0 p s b in c q s b 1 1 unknowns, so we can now solve our problem! 1 for b 1, plus the c c 0 and s c 1 2 1 equations of the form s b 1. In other words, we have c 1 equations The solution still requires several algebraic steps, as follows. 670 Section 11.7: Further Proofs Lemma 11.7.2 For 1 b c 1, we have. PROOF Recalling that p q 1 we rearrange (11.7.1) as follows And finally, which gives the result, Lemma 11.7.3 For 0 b c, we have 11.7.2) PROOF Applying the equation of Lemma 11.7.2 with b 1, we obtain because s 0 0). Applying it again with b 2, we obtain By induction, we see that for b 0 1 2 c 1. Hence, we compute that for b 0 1 2 c. This gives the result. Chapter 11: Advanced Topic — Stochastic Processes 671 We are now able to finish the proof of Theorem 11.1.2. If p
1 2, then q p 1, so (11.7.2) becomes s b 1 c. Then s b bs 1 1, i.e., s 1 bs 1. But s c b c. Hence, s a 1, so we a c must have cs 1 in this case. If p 1 2, then q p 1, so (11.7.2) is a geometric series, and becomes. Because s c 1, we must have so Then Hence in this case. Proof of Theorem 11.1.3 We want to prove that when Xn is a simple random walk, with initial fortune a and probability p of winning each bet, then the probability P 0 will ever hit 0 is given by 0 that the walk. By continuity of probabilities, we see that P 0 lim c P 0 c lim c 1 P c 0. Hence, if p Now, if p 1 2, then P 0 1 2, then limc 1 a c 1. P 0 lim. If p then q p 1 2 then q p 1, so limc 1, so limc q p c q p c 0, and P 0, and P 0 q p a. 1 If p 1 2 672 Section 11.7: Further Proofs Proof of Theorem 11.3.3 We want to prove that the Metropolis–Hastings algorithm results in a Markov chain X0 X1 X2 i as a stationary distribution. which has We shall prove that the resulting Markov chain is reversible with respect to i, i.e., that i P Xn 1 j Xn i j P Xn 1 i Xn j, (11.7.3) j for i tion for the chain. S It will then follow from Theorem 11.2.6 that is a stationary distribu­ i We thus have to prove (11.7.3). Now, (11.7.3) is clearly true if i j, so we can assume that i But if i j. j, and Xn j (i.e., we propose the state j, which we will do with probability pi j ). Also we accept this proposal (which we will do with probability i j ). Hence, i, then the only way we can have Xn 1 j is if Yn 1 P Xn 1 j Xn i qi j i j qi j min 1 j q ji i qi j min qi
j j q j i i. It follows that i P Xn 1 j Xn Similarly, we compute that follows that (11.7.3) is true. min i j P Xn 1 i qi j i Xn j q ji j min j q ji i qi j It Proof of Theorem 11.5.1 We want to prove that when Y M (a) For t tributed with mean t. (b) For s t 0, the covariance t 0, the distribution of Y M : t t 0 is as defined earlier, then for large M: is approximately N 0 t, i.e., normally dis­ Cov Y M t Y M t is approximately equal to min s t. (c) For t 0, the distribution of the increment.e., normally distributed with mean 0 and variance t is approximately N 0 t and is approximately independent of Y M (d) Y M t Write r for the greatest integer not exceeding r, so that, e.g., 7 6 s is a continuous function of t.. s, 7. Then we is very close (formally, see that for large M, t is very close to t M M, so that Y M within O 1 M in probability) to t A Y M t M M 1 M Z1 Z2 Z t M. Chapter 11: Advanced Topic — Stochastic Processes 673 Now, A is equal to 1 M times the sum of t M different i.i.d. random variables, each having mean 0 and variance 1. It follows from the central limit theorem that A. This proves part (a). converges in distribution to the distribution N 0 t as M For part (b), note that also Y M s is very close to B Y M s M M 1 M Z1 Z2 Z s M. Because E Zi 0, we must have E A For simplicity, assume s t the case s E B 0, so that Cov A B t is similar. Then we have E AB. Cov A B E AB 1 M E Z1 Z2 Z s M Z1 Z2 Zi Zi Z j. Now, we have E Zi Z j 0 unless i be precisely s M terms in the sum for which i (since t s). Hence, Cov A B s M M, j, in which case E Zi Z j 1. There will j, namely, one for each value of i which converges
to s as M. This proves part (b). Part (c) follows very similarly to part (a). Finally, part (d) follows because the was constructed in a continuous manner (as in Figure 11.5.1). function Y M t Proof of Theorem 11.6.1 We want to prove that for any t 0, the distribution of Nt is Poisson at. We first require a technical lemma. Lemma 11.7.4 Let gn t Gamma n a distribution. Then for n e at ant n 1 n 1, 1! be the density of the t 0 gn s ds e at at i i!. (11.7.4) i n 0, then both sides are 0. For other t, differentiating with respect to PROOF If t t, we see (setting j e at ai t i 1 i 1! e at a n 1 1t n 1 n t we see that (11.7.4) is satisfied for any n 1) that gn at at i i! i! e at ai 1t i j n 1 e at a j 1t j t 0 gn s ds. Because this is true for all t 0. ae at at i j! i n i! 0, Recall (see Example 2.4.16) that the Exponential distribution is the same as the Gamma 1 and Y distribution. Furthermore, (see Problem 2.9.15) if X Gamma 2 are independent, then X Y Gamma 1 Gamma. 2 1 674 Section 11.7: Further Proofs Now, in our case, we have Tn Exponential a R2 Gamma 1 a. It follows that Tn Gamma n a. Hence, the density of Tn is gn t e at ant n 1 n Rn, where Ri 1!. R1 Now, the event that Nt the same as the event that Tn n (i.e., that the number of events by time t is at least n) is t (i.e., that the nth event occurs before time n). Hence, P Nt n P Tn t t 0 gn s ds Then by Lemma 11.7.4, P Nt n e at at i i! i n (11.7.5) for any n 1. If n Using this, we see that 0 then both sides are 1, so in fact (
11.7.5) holds for any n 0. P Nt j P Nt j P Nt j 1 e at at i i! e at at i i! e at at j j!. i j i j 1 It follows that Nt Poisson at, as claimed. Proof of Theorem 11.6.2 We want to prove that when 0 the distribution of Nti variables Nti Nti 1 for i t0 t1 Nti 1 is Poisson a ti t2 t3 td, then for i d,. Furthermore, the random 1 2 ti 1 1 d are independent. From the memoryless property of the exponential distributions (see Problem 2.4.14), ti 1, this will have no effect on it follows that regardless of the values of Ns for s the distribution of the increments Nt ti 1. That is, the process Nt Nti 1 for t starts fresh at each time ti 1, except from a different initial value Nti 1 instead of from N0 0. Hence, the distribution of Nti 1 u Nti 1 for u Nu and is independent of the values of Ns for s of Nu N0 already know that Nu as well. In particular, Nti independent of Ns : s Poisson au, it follows that Nti 1 u Poisson a ti ti 1. The result follows. Nti 1 ti 1 0 is identical to the distribution ti 1. Because we Poisson au Nti 1 Nti 1 as well, with Nti Appendix A Mathematical Background To understand this book, it is necessary to know certain mathematical subjects listed below. Because it is assumed the student has already taken a course in calculus, topics such as derivatives, integrals, and infinite series are treated quite briey here. Multi­ variable integrals are treated in somewhat more detail. A.1 Derivatives From calculus, we know that the derivative of a function f is its instantaneous rate of change: f x d dx f x f x lim 0 h h h f x In particular, the reader should recall from calculus that d dx 5 0 d dx x 3 3x 2 d dx x n nx n 1 d dx ex ex d dx sin x cos x d dx cos x sin x etc. Hence, if f x x 3, then f x 3x 2 and, e.g., f 7 3 72 147. Derivatives respect addition and scalar multiplication, so if
f and g are functions and C is a constant, then Thus, etc. d dx dx 5x 3 3x 2 7x 12 15x 2 6x 7 675 676 Appendix A: Mathematical Background Finally, derivatives satisfy a chain rule; if a function can be written as a composition of two other functions, as in f x g h x, then f x g h x h x. Thus, 5e5x 2x cos x 2 d dx e5x d dx sin x 2 d dx 2x 3x 2 etc. Higher­order derivatives are defined by f x d dx f x f x d dx f x etc. In general, the r th­order derivative f r x can be defined inductively by f 0 x f x and f r x f r 1 x d dx for r 24x, f 4 x 1. Thus, if f x 24, etc. x 4, then f x 4x 3, f x f 2 x 12x 2, f 3 x Derivatives are used often in this text. A.2 Integrals If f is a function, and a [a b], written b are constants, then the integral of f over the interval b a f x dx represents adding up the values f x, multiplied by the widths of small intervals around b x. That is, and where xi b a f x dx xi 1 where a xi 1 is small. d i 1 f xi xd x1 x0 xi More formally, we can set xi a i d b a and let d, to get a formal definition of integral as b a f x dx lim To compute b a f x dx in this manner each time would be tedious. Fortunately, the fundamental theorem of calculus provides a much easier way to compute integrals. It says that if F x is any function with F x Hence, f x, then b a f x dx F a F b b a 3x 2 dx b a x 2 dx b a x n dx b3 a3 a3 1 3 b3 1 n 1 bn 1 an 1 Appendix A.3: Infinite Series 677 and b a cos x dx b a sin x dx b a e5x dx sin b sin a cos b cos a 1 5 e5b e5a A.3 Infinite Series If a1 a2
a3 (or series) is an infinite sequence of numbers, we can consider the infinite sum ai a1 a2 a3 i 1 i 1 1 1 4 1 8 Formally, i 1 ai For example, clearly limN because we see that 1 2 1 4 1 8 1 2 1 16 N i 1 ai. This sum may be finite or infinite. 1 1 1 1 On the other hand, 1 16 1 2i i 1 1 2n 2n 1 2n lim N N i 1 1 2i lim N 2N 1 2N 1 More generally, we compute that ai i 1 a 1 a whenever a 1 One particularly important kind of infinite series is a Taylor series. If f is a func­ tion, then its Taylor series is given by f 0 x f 0 1 2! x 2 f 0 1 3! x 3 f 3 0 1 i! i 0 x i f i 0 (Here i! 3! thus, 6, 4! i i 1 i 2, 2 1 stands for i factorial, with 0! 24, etc.) Usually, f x will be exactly equal to its Taylor series expansion, 1, 2! 1! 2 sin x cos x ex e5x 5x! x 3 3! 5x 2 2! x 4 4! 5x 3 3! 5x 4 4! 3x 2 etc. If f x is a polynomial (e.g., f x of f x is precisely the same function as f x itself. x 3 2x 6), then the Taylor series 678 Appendix A: Mathematical Background A.4 Matrix Multiplication A matrix is any r s collection of numbers, e.g., 17 9 etc. Matrices can be multiplied, as follows. If A is an r trix, then the product AB is an r a sum of products. For example, with A and B as above, if M AB, then j entry is given by u matrix whose i s matrix, and B is an s u ma­ s k 1 Ai k Bk 18 84 16 1 42 10 as, for example, the 2 1 entry of M equals 5 3 2 7 1 Matrix multiplication turns out to be surprisingly useful, and it is used in various places in this book. A.5 Partial Derivatives Suppose f is a function of two variables, as in f
x y partial derivative of f with respect to x, writing 3x 2 y3 Then we can take a by varying x while keeping y fixed. That is, f x y x f x y x lim This can be computed simply by regarding y as a constant value. For the example above, Similarly, by regarding x as constant and varying y, we see that 3x 2 y3 6x y3 x Other examples include 3x 2 y3 9x 2 y2 y 18ex y x 6 y8 sin y3 18yex y 6x 5 y8 18ex y x 6 y8 sin y3 18xex y 8x 6 y7 3y2 sin y3 x y Appendix A.6: Multivariable Integrals 679 etc. If f is a function of three or more variables, then partial derivatives may similarly be taken. Thus, x 2 y4z6 2x y4z6 x 2 y4z6 4x 2 y3z6 y x 2 y4z6 6x 2 y4z5 z x etc. A.6 Multivariable Integrals If f is a function of two or more variables, we can still compute integrals of f. How­ ever, instead of taking integrals over an interval [a b], we must take integrals over higher­dimensional regions. f x y 7 y x 2 y3, and let R be the rectangular region given by [0 1] For example, let x [5 7] What is 1 5 R 0 f x y dx dy R the integral of f over the region R? In geometrical terms, it is the volume under the graph of f (and this is a surface) over the region R But how do we compute this? Well, if y is constant, we know that 1 0 f x y dx 1 0 x 2 y3 dx y3 1 3 (A.6.1) This corresponds to adding up the values of f along one “strip” of the region R, where y is constant. In Figure A.6.1, we show the region on integration R [5 7] The value of (A.6.1), when y 79 443 this is the area under the curve x 2 6 2 3 over the line [0 1] 6 2 is 6 2 3 3 6 2 [0 1] y 7 5 y = 6.2 1 x Figure A.6.1: Plot of
the region of integration (shaded) R line at y 6 2. [0 1] [5 7] together with the 680 Appendix A: Mathematical Background If we then add up the values of the areas over these strips along all different possible y values, then we obtain the overall integral or volume, as follows: f x y dx dy dx dy 7 1 5 0 x 2 y3 dx dy y3 dy 1 3 1 3 1 4 74 54 148 So the volume under the the graph of f and over the region R is given by 148. Note that we can also compute this integral by integrating first y and then x, and we get the same answer: f x y dx dy R 7 5 f x y dy dx x 2 74 54 dx y3 dy dx 5 74 54 148 0 1 4 1 3 Nonrectangular Regions If the region R is not a rectangle, then the computation is more complicated. The idea is that, for each value of x, we integrate y over only those values for which the point x y is inside R. For example, suppose that R is the triangle given by R 6 In Figure A.6.2, we have plotted this region together with the slices at x 3 x and y 3 2 We use the x­slices to determine the limits on y for fixed x when we integrate out y first; we use the y­slices to determine the limits on x for fixed y when we integrate out x first. x y : 0 2y y y = 3/2 2y = x x = 3 x = 6 x Figure A.6.2: The integration region (shaded) R the slices at x 3 and y 3 2. x y : 0 2y x 6 together with Appendix A.6: Multivariable Integrals 681 Then x can take any value between 0 and 6. However, once we know x, then y can only take values between 0 and x 2. Hence, if f x y x y x 6 y8, then f x y dx dy R x 2 f x y dy dx 6 x 2 0 0 x y x 6 y8 dy dx x 2 2 02 x 6 1 9 x 2 9 09 dx 4608 x 15 dx 1 4608 1 16 616 016 04 107 64 0 1 1 8 4 3 8264 Once again, we can compute the same integral in
the opposite order, by integrating first x and then y. In this case, y can take any value between 0 and 3. Then, for a given value of y, we see that x can take values between 0 and 2y. Hence, f x y dx dy R 3 0 6 2y f x y dx dy 3 0 6 2y x y x 6 y8 dx dy We leave it as an exercise for the reader to finish this integral, and see that the same answer as above is obtained. Functions of three or more variables can also be integrated over regions of the corresponding dimension three or higher. For simplicity, we do not emphasize such higher­order integrals in this book. Appendix B Computations We briey describe two computer packages that can be used for all the computations carried out in the text. We recommend that students familiarize themselves with at least one of these. The description of R is quite complete, at least for the computations based on material in this text, whereas another reference is required to learn Minitab. B.1 Using R R is a free statistical software package that can be downloaded and installed on your computer (see http://cran.r­project.org/). A free manual is also available at this site. Once you have R installed on your system, you can invoke it by clicking on the relevant icon (or, on Unix systems, simply typing “R”). You then see a window, called ’ after which you type com­ the R Console that contains some text and a prompt ‘ mands. Commands are separated by new lines or ‘ ; ’. Output from commands is also displayed in this window, unless it is purposefully directed elsewhere. To quit R, type q() after the prompt. To learn about anything in R, a convenient resource is to use Help on the menu bar available at the top of the R window. Alternatively, type?name after the prompt (and press enter) to display information about name, e.g.,?q brings up a page with information about the terminate command q. Basic Operations and Functions A basic command evaluates an expression, such as 2+3 [1] 5 which adds 2 and 3 and produces the answer 5. Alternatively, we could assign the value of the expression to a variable such as a ­ 2 where ­ (less than followed by minus) assigns the value 2 to a variable called a. Alternatively,
= can be used for assignment as in a = 2, but we will use ­. We 683 684 Appendix B: Computations can then verify this assignment by simply typing a and hitting return, which causes the value of a to be printed. a [1] 2 Note that R is case sensitive, so A would be a different variable than a. There are some restrictions in choosing names for variables and vectors, but you won’t go wrong if you always start the name with a letter. We can assign the values in a vector using the concatenate function c() such as ­ c(1,1,1,3,4,5) b b [1] 1 1 1 3 4 5 which creates a vector called b with six values in it. We can access the ith entry in a vector b by referring to it as b[i]. For example, b[3] [1] 1 prints the third entry in b, namely, 1. Alternatively, we can use the scan command to input data. For example, b ­ scan() 1: 1 1 1 3 4 5 7: Read 6 items b [1] 1 1 1 3 4 5 accomplishes the same assignment. Note that with the scan command, we simply type in the data and terminate data input by entering a blank line. We can also use scan to read data in from a file, and we refer the reader to?scan for this. Sometimes we want vectors whose entries are in some pattern. We can often use the rep function for this. For example, x ­ rep(1,20) creates a vector of 20 ones. More complicated patterns can be obtained, and we refer the reader to?rep for this. Basic arithmetic can be carried out on variables and vectors using + (addition), ­ (subtraction), * (multiplication), / (division), and ^ (exponentiation). These operations are carried out componentwise. For example, we could multiply each component of b by itself via b*b [1] 1 1 1 9 16 25 or multiply each element of b by 2 as in 2*b [1] 2 2 2 6 8 10 which accomplishes this. Appendix B.1: Using R 685 There are various functions available in R, such as abs(x) (calculates the absolute value of x), log(x) (calculates the natural logarithm of x), exp(x) (calcul
ates e raised to the power x), sin(x), cos(x), tan(x) (which calculate the trigonomet­ ric functions), sqrt(x) (which calculates the square root of x), ceiling(x), and floor(x) (calculate the ceiling and oor of x). When such a function is applied to a vector x, it returns a vector of the same length, with the function applied to each element of the original vector. There are numerous special functions available in R, but two important ones are gamma(x), which returns the gamma function applied to x, and lgamma(x), which returns the natural logarithm of the gamma function. There are also functions that return a single value when applied to a vector. For example, min(x) and max(x) return, respectively, the smallest and largest elements in x; length(x) gives the number of elements in x; and sum(x) gives the sum of the values in x. R also operates on logical quantities TRUE (or T for true) and FALSE (or F for false). Logical values are generated by conditions that are either true or false. For example, ­ c(­3,4,2,­1,­5) ­ a 0 a b b [1] FALSE TRUE TRUE FALSE FALSE compares each element of the vector a with 0, returning TRUE when it is greater than 0 and FALSE otherwise, and these logical values are stored in the vector b. The follow­ ing logical operators can be used:, == (for equality),!= (for inequality) as well as & (for conjunction), (for disjunction) and! (for negation). For example, if we create a logical vector c as follows:, =, =, ­ c(T,T,T,T,T) c b&c [1] FALSE TRUE TRUE FALSE FALSE b c [1] TRUE TRUE TRUE TRUE TRUE then an element of b&c is TRUE when both corresponding elements of b and c are TRUE, while an element of b c is TRUE when at least one of the corresponding ele­ ments of b and c is TRUE. Sometimes we may have variables that take character values. While it is always possible to code these values as numbers, there is no need to do this, as R can also handle character­valued variables. For example, the commands ­ c(’a’,�
�b’) A A [1] "a" "b" create a character vector A, containing two values a and b, and then we print out this vector. Note that we included the character values in single quotes when doing the assignment. 686 Appendix B: Computations Sometimes data values are missing and so are listed as NA (not available). Opera­ tions on missing values create missing values. Also, an impossible operation, such as 0/0, produces NaN (not a number). Various objects can be created during an R session. To see those created so far in your session, use the command ls(). You can remove any objects in your workspace using the rm command. For example, rm(x) removes the vector x. Probability Functions R has a number of built­in functions for evaluation of the cdf, the inverse cdf, the density or probability function, and generating random samples for the common dis­ tributions we encounter in probability and statistics. These are distinguished by prefix and base distribution names. Some of the distribution names are given in the following table. Distribution R name and arguments beta binomial chi­squared exponential F gamma geometric beta(,a,b) binom(,n,p) chisq(,df) exp(,lambda) f(,df1,df2) gamma(,alpha,lambda) geom(,p) Distribution hypergeometric negative binomial normal Poisson t uniform R name and arguments hyper(,N,M,n) nbinom(,k,p) norm(,mu,sigma) pois(,lambda) t(,df) unif(,min,max) As usual, one has to be careful with the gamma distribution. The safest path is to include another argument with the distribution to indicate whether or not lambda x or a scale parameter (density is a rate parameter (density is is So gamma(,alpha,rate=lambda) indicates that lambda is a rate parameter, and gamma(,alpha,scale=lambda) indicates that it is a scale parameter. 1e x 1e x x 1 1 The argument given by is specified according to what purpose the command using the distribution name has. To obtain the cdf of a distribution, precede the name by p, and then is the value at which you want to evaluate the cdf. To obtain the inverse cdf of a distribution, preced
e the name by q, and then is the value at which you want to evaluate the inverse cdf. To obtain the density or probability function, precede the name by d, and then is the value at which you want to evaluate the density or probability function. To obtain random samples, precede the name by r, and then is the size of the random sample you want to generate. For example, ­ rnorm(4,1,2) x x [1] ­0.2462307 2.7992913 4.7541085 3.3169241 generates a sample of 4 from the N 1 22 distribution and assigns this to the vector x. The command Appendix B.1: Using R 687 dnorm(3.2,2,.5) [1] 0.04478906 evaluates the N 2 25 pdf at 3.2, while pnorm(3.2,2,.5) [1] 0.9918025 evaluates the N 2 0 25 cdf at 3.2, and qnorm(.025,2,.5) [1] 1.020018 gives the 0 025 quantile of the N 2 0 25 distribution. If we have data stored in a vector x, then we can sample values from x, with or without replacement, using the sample function. For example, sample(x,n,T) will generate a sample of n from x with replacement, while sample(x,n,F) will generate a sample of n from x without replacement (note n must be no greater than length(x) in the latter case). Sometimes it is convenient to be able to repeat a simulation so the same random values are generated. For this, you can use the set.seed command. For example, set.seed(12345) establishes the seed as 12345. Tabulating Data The table command is available for tabulating data. For example, table(x) re­ turns a table containing a list of the unique values found in x and their frequency of occurrence in x. This table can be assigned to a variable via y ­ table(x) for further analysis (see The Chi­Squared Test section on the next page). If x and y are vectors of the same length, then table(x,y) produces a cross­ tabulation, i.e., counts the number of times each possible value of x y is obtained, where x can be any of the values taken in x and y
can be any of the values taken in y. Plotting Data R has a number of commands available for plotting data. For example, suppose we have a sample of size n stored in the vector x. The command hist(x) will provide a frequency histogram of the data where the cutpoints are chosen automatically by R. We can add optional arguments to hist. The following are some of the arguments available. breaks — A vector containing the cutpoints. freq — A logical variable; when freq=T (the default), a frequency histogram is obtained, and when freq=F, a density histogram is obtained. For example, hist(x,breaks=c(­10,­5,­2,0,2,5,10),freq=F) will plot a density histogram with cutpoints 10 2 0 2 5 10 where we have been care­ 5 ful to ensure that min(x) 10 and max(x) 10. 688 Appendix B: Computations If y is another vector of the same length as x, then we can produce a scatter plot of y against x via the command plot(x,y). The command plot(x,y,type="l") provides a scatter plot of y against x, but now the points are joined by lines. The command plot(x) plots the values in x against their index. The plot(ecdf(x)) command plots the empirical cdf of the data in x. A boxplot of the data in x is obtained via the boxplot(x) command. Side­by­ side boxplots of the data in x, y, z, etc., can be obtained via boxplot(x,y,z). A normal probability plot of the values in x can be obtained using the command qqnorm(x). A barplot can be obtained using the barplot command. For example, ­ c(1,2,3) h barplot(h) produces a barplot with 3 bars of heights 1, 2, and 3. There are many other aspects to plotting in R that allow the user considerable con­ trol over the look of plots. We refer the reader to the manual for more discussion of these. Statistical Inference R has a powerful approach to fitting and making inference about models. Models are specified by the symbol ~. We do not discuss this fully here but only indicate how to use this to handle the
simple and multiple linear regression models (where the response and the predictors are all quantitative), the one­ and two­factor models (where the response is quantitative but the predictors are categorical), and the logistic regression model (where the response is categorical but the predictors are quantitative). Suppose, then, that we have a vector y containing the response values. Basic Statistics The function mean(y) returns the mean of the values in y, var(y) returns the sample variance of the values in y, and sd(y) gives the sample standard devia­ tion. The command median(y)returns the median of y, while quantile(y,p) returns the sample quantiles as specified in the vector of probabilities p. For example, quantile(y,c(.25,.5,.75)) returns the median and the first and third quan­ tiles. The function sort(y) returns a vector with the values in y sorted from smallest to largest, and rank(y) gives the ranks of the values in y. The ­Test For the data in y, we can use the command t.test(y,mu=1,alternative="two.sided",conf.level=.95) to carry out a t­test. This computes the P­value for testing H0 : 0 95­confidence interval for 1 and forms a The Chi­Squared Test Suppose y contains a vector of counts for k cells and prob contains hypothesized probabilities for these cells. Then the command Appendix B.1: Using R 689 chisq.test(y,p=prob) carries out the chi­squared test to assess this hypothesis. Note that y could also corre­ spond to a one­dimensional table. If x and y are two vectors of the same length, then chisq.test(x,y) carries out a chi­squared test for independence on the table formed by cross­tabulating the entries in x and y. If we first create this cross­tabulation in the table t using the table function, then chisq.test(t) carries out this test. Simple Linear Regression Suppose we have a single predictor with values in the vector x. The simple linear regression model E y x 2x is then specified in R by y~x. We refer to
y~x as a model formula, and read this as “y is modelled as a linear model involving x.” To carry out the fitting (which we have done here for a specific set of data), we use the fitting linear models command lm, as follows. The command 1 regexamp ­ lm(y~x) carries out the computations for fitting and inference about this model and assigns the result to a structure called regexamp. Any other valid name could have been used for this structure. We can now use various R functions to pick off various items of interest. For example, summary(regexamp) Call: lm(formula = y~x) Residuals: Min 1Q Median 3Q Max ­4.2211 ­2.1163 0.3248 1.7255 4.3323 Coefficients: Estimate Std. Error t value Pr( t ) (Intercept) 6.5228 1.7531 x 1.2176 0.1016 5.357 17.248 4.31e­05 *** 1.22e­12 *** ­­ Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.621 on 18 degrees of freedom Multiple R­squared: 0.9429, Adjusted R­squared: 0.9398 F­statistic: 297.5 on 1 and 18 DF, p­value: 1.219e­12 uses the summary function to give us all the information we need. For example, the fitted line is given by 6 5228 0 has a P­value of 1 7531x The test of H0 : 10 12 so we have strong evidence against H0 Furthermore, the R2 is given 1 22 by 94.29%. Individual items can be accessed via various R functions and we refer the reader to?lm for this. 2 690 Appendix B: Computations Multiple Linear Regression If we have two quantitative predictors in the vectors x1 and x2, then we can proceed just as with simple linear regression to fit the linear regression model E y x1 x2 1 2x1 2x2. For example, the commands regex summary
(regex) ­ lm(y~x1+x2) fit the above linear model, assign the results of this to the structure regex, and then the summary function prints out (suppressed here) all the relevant quantities. We read y~x1+x2 as, “y is modelled as a linear model involving x1 and x2.” In particular, the F­statistic, and its associated P­value, is obtained for testing H0 : 0 2 3 xl for l This generalizes immediately to linear regression models with k quantitative pre­ xk. Furthermore, suppose we want to test that the model only involves dictors x1 x1 k We use lm to fit the model for all k predictors, assign this to regex, and also use lm to fit the model that only involves l predictors and assign this to regex1. Then the command anova(regex,regex1) will output the F­ statistics, and its P­value, for testing H0 : 0 l 1 k One­ and Two­Factor ANOVA Suppose now that A denotes a categorical predictor taking two levels a1 and a2. Note that the values of A may be character in value rather than numeric, e.g., x is a character vector containing the values a1 and a2, used to denote at which level the correspond­ ing value of y was observed. In either case, we need to make this into a factor A, via the command A ­ factor(x) so that A can be used in the analysis. Then the command aov(y~A) produces the one­way ANOVA table. Of course, aov also handles factors with more than two levels. To produce the cell means, use the command tapply(y,A,mean). b5 If this is the factor B Suppose there is a second factor B taking 5 levels b1 in R, then the command aov(y~A+B+A:B) produces the two­way ANOVA for testing for interactions between factors A and B. To produce the cell means, use the command tapply(y,list(A,B),mean). The command aov(y~A+B) produces the ANOVA table, assuming that there are no inter­ actions. Logistic Regression Suppose we have binary data stored in the vector y, and x contains the
corresponding values of a quantitative predictor. Then we can use the generalized linear model com­ mand glm to fit the logistic regression model P Y The commands exp 1 exp 1 1 x 2x 2x 1 Appendix B.1: Using R 691 logreg summary(logreg) ­ glm(y~x,family=binomial) fit the logistic regression model, assign the results to logreg, and then the summary their standard command outputs this material. This gives us the estimates of the errors, and P­values for testing that the i 0 i Control Statements and R Programs A basic control statement is of the form if (expr1) expr2 else expr3, where expr1 takes a logical value, expr2 is executed if expr1 is T, and expr3 is executed if expr1 is F. For example, if x is a variable taking value 2, then if (x 0) {y ­ ­1} else {y ­ 1} results in y being assigned the value be dropped. 1. Note that the else part of the statement can The command for (name in expr) expr2 executes expr2 for each value of name in expr1. For example, for (i in 1:10) print(i) prints the value of the variable i as i is sequentially assigned values in 1 2 Note that m:n is a shorthand for the sequence m m 1 example, n in R. As another 10 for (i in 1:20) y[i] ­ 2^i creates a vector y with 20 entries, where the ith element of y equals 2i The break terminates a loop, perhaps based on some condition holding, while next halts the processing of the current iteration and advances the looping index. Both break and next apply only to the innermost of nested loops. Commands in R can be grouped by placing them within braces {expr1; expr2;...}. The commands within the braces are executed as a unit. For example, for (i in 1:20) {print(i); y[i] ­ 2^i}; print(y[i])} causes i to be printed, y[i] to be assigned, and y[i] to be printed, all within a for loop. Often when a computation is complicated, such as one that involves looping, it is better to put all the R commands in a single file
and then execute the file in batch mode. For example, suppose you have a file prog.R containing R code. Then the command source("pathname/prog.R") causes all the commands in the file to be executed. It is often convenient to put comments in R programs to explain what the lines of code are doing. A comment line is preceded by # and of course it is not executed. User­Defined Functions R also allows user­defined functions. The syntax of a function definition is as follows. 692 Appendix B: Computations function name ­ function(arguments) { function body; return(return value); } For example, the following function computes the sample coefficient of variation of the data x. coef_var ­ function(x) { result return(result); ­ sd(x)/mean(x); } Then if we want to subsequently compute the coefficient of variation of data y, we simply type coef_var(y). Arrays and Lists A vector of length m can also be thought of as a one­dimensional array of length m. p arrays, etc. If a is a R can handle multidimensional arrays, e.g., m n m n three­dimensional array, then a[i,j,k] refers to the entry in the i j k ­th position of the array. There are various operations that can be carried out on arrays and we refer the reader to the manual for these. Later in this manual, we will discuss the special case of two­dimensional arrays, which are also known as matrices. For now, we just think of arrays as objects in which we store data. A very general data structure in R is given by a list. A list is similar to an array, with several important differences. 1. Any entry in an array is referred to by its index. But any entry in a list may be referred to by a character name. For example, the fitted regression coeffi­ cients are referred to by regex$coefficients after fitting the linear model x1 + x2). The dollar mark ($) is the entry reference regex operator, that is, varname$entname indicates the “entname” entry in the list “varname.
” ­ lm(y 2. While an array stores only the same type of data, a list can store any R objects. For example, the coefficients entry in a linear regression object is a nu­ meric vector, and the model entry is a list. 3. The reference operators are different: arr[i] refers to the ith entry in the array arr, and lst[[i]] refers to the i th entry in the list lst. Note that i can be the entry name, i.e., lst$entname and lst[[’entname’]] refer to the same data. Examples We now consider some examples relevant to particular sections or examples in the main text. To run any of these codes, you first have to define the functions. To do this, load Appendix B.1: Using R 693 the code using the source command. Arguments to the functions then need to be specified. Note that lines in the listings may be broken unnaturally and continue on the following line. EXAMPLE B.1.1 Bootstrapping in Example 6.4.2 The following R code generates bootstrap samples and calculates the median of each of these samples. To run this code, type y ­ bootstrap_median(m,x), where m is the number of bootstrap samples, x contains the original sample, and the medians of the resamples are stored in y. The statistic to be bootstrapped can be changed by substituting for median in the code. # # # # # # # # Example B.1.1 function name: bootstrap_median parameters: m x resample size original data return value: a vector of resampled medians description: resamples and stores its median bootstrap_median ­ function(m,x) { ­ length(x); n result for(i in 1:m) result[i] ­ rep(0,m); ­ median(sample(x,n,T)); return(result); } EXAMPLE B.1.2 Sampling from the Posterior in Example 7.3.1 The following R code generates a sample of from the joint posterior in Example 7.3.1. To run a simulation, type post ­ post_normal(m,x,alpha0,beta0,mu0,tau0square
) where m is the Monte Carlo sample size and the remaining arguments are the hyperpa­ rameters of the prior. The result is a list called (in this case) post, where post$mu 2 respectively. For and post$sigmasq contain the generated values of example, and x ­ c(11.6714, 1.8957, 2.1228, 2.1286, 1.0751, 8.1631, 1.8236, 4.0362, 6.8513, 7.6461, 1.9020, 7.4899, 4.9233, 8.3223, 7.9486); post z ­ post_normal(10**4,x,2,1,4,2) ­ sqrt(post$sigmasq)/post$mu runs a simulation as in Example 7.3.1, with N 104 # # # # Example B.1.2 function name: post_normal parameters: m sample size 694 Appendix B: Computations data returned values: mu sampled mu sigmasq sampled sigmasquare rate parameter for 1/sigma^2 location parameter for mu description: samples from the posterior distribution in Example 7.3.1 x alpha0 shape parameter for 1/sigma^2 beta0 mu0 tau0square variance ratio parameter for mu # # # # # # # # # # # post_normal ­function(m,x,alpha0,beta0,mu0,tau0square){ # set the length of the data n # the shape and rate parameters of the posterior dist. # alpha_x = first parameter of the gamma dist. # alpha_x # beta_x = the rate parameter of the gamma dist. beta_x = (alpha0 + n/2) ­ alpha0 + n/2 ­ beta0 + (n­1)/2 * var(x) + n*(mean(x)­mu0)**2/ ­ length(x); 2/(1+n*tau0square); distribution = the mean parameter of the normal dist. ­ (mu0/tau0square+n*mean(x))/(n+1/tau0square); # mu_x mu_x # tausq_x = the variance ratio parameter of the normal # tausq_x # initialize the result result result$s
igmasq result$mu ­ 1/rgamma(m,alpha_x,rate=beta_x); ­ rnorm(m,mu_x,sqrt(tausq_x * result$sigmasq)); ­ 1/(n+1/tau0square); ­ list(); return(result); } EXAMPLE B.1.3 Calculating the Estimates and Standard Errors in Example 7.3.1 Once we have a sample of values from the posterior distribution of stored in psi, we can calculate the interval given by the mean value of psi plus or minus 3 standard deviations as a measure of the accuracy of the estimation. # Example B.1.3 # set the data x ­ c(11.6714, 1.8957, 2.1228, 2.1286, 1.0751, 8.1631, 1.8236, 4.0362, 6.8513, 7.6461, 1.9020, 7.4899, 4.9233, 8.3223, 7.9486); post ­ post_normal(10**4,x,2,1,4,2); # compute the coefficient of variation Appendix B.1: Using R 695 ­ mean(psi ­ sqrt(psi_hat * (1­psi_hat))/sqrt(length(psi)); =.5); ­ sqrt(post$sigmasq)/post$mu; psi psi_hat psi_se # the interval cq cat("The three times s.e. interval is ", ­ 3 "[",psi_hat­cq*psi_se, ", ", psi_hat+cq*psi_se,"] n"); EXAMPLE B.1.4 Using the Gibbs Sampler in Example 7.3.2 To run this function, type post ­gibbs_normal(m,x,alpha0,beta0,lambda,mu0, tau0sq,burnin=0) as this creates a list called post, where post$mu and post$sigmasq contain the and 2 respectively. Note that the burnin argument is set to generated values of a nonnegative integer and indicates that we wish to discard the first burnin values of and 2 and
retain the last m. The default value is burnin=0. m x alpha0 beta0 lambda mu0 tau0sq burnin # Example B.1.4 # # # # # # # # # # # # # # # # gibbs_normal function name: gibbs_normal parameters the size of posterior sample data shape parameter for 1/sigma^2 rate parameter for 1/sigma^2 degree of freedom of Student’s t­dist. location parameter for mu scale parameter for mu size of burn in. the default value is 0. returnrd values mu sigmasq sampled sigma^2’s sampled mu’s description: samples from the posterior in Ex. 7.3.2 ­ function(m,x,alpha0,beta0,lambda,mu0, tau0sq,burnin=0) { ­ list(); # initialize the result result result$sigmasq ­ result$mu # set the initial parameter ­ mean(x); mu ­ var(x); sigmasq ­ length(x); n # set parameters ­ rep(0,m); 696 Appendix B: Computations ­ n/2 + alpha0 + 1/2; alpha_x # loop for(i in (1­burnin):m) { # update v_i’s v ­ rgamma(n,(lambda+1)/2,rate=((x­mu)**2/ # update sigma­square beta_x ­(sum(v*(x­mu)**2)/lambda+(mu­mu0)**2/ sigmasq/lambda+1)/2); tau0sq)/2+beta0; sigmasq ­ 1/rgamma(1,alpha_x,rate=beta_x); # update mu r mu ­ 1/(sum(v)/lambda+1/tau0sq); ­ rnorm(1,r*(sum(v*x)/lambda+mu0/tau0sq), sqrt(r*sigmasq)); # burnin check if(i result$mu[i] result$sigmasq[i] 1) next; ­ mu; ­ sigmasq; } result$psi return(result); ­ sqrt(result$s
igmasq)/result$mu; } EXAMPLE B.1.5 Batching in Example 7.3.2 The following R code divides a series of data into batches and calculates the batch means. To run the code, type y ­batching(k,x) to place the consecutive batch means of size k, of the data in the vector x, in the vector y. k x size of each batch data return value: Example B.1.5 function name: batching parameters: # # # # # # # # # # batching m result for(i in 1:m) result[i] return(result); ­ floor(length(x)/k); ­ rep(0,m); ­ function(k,x) { } an array of the averages of each batch description: this function separates the data x into floor(length(x)/k) batches and returns the array of the averages of each batch ­ mean(x[(i­1)*k+(1:k)]); Appendix B.1: Using R 697 EXAMPLE B.1.6 Simulating a Sample from the Distribution of the Discrepancy Sta­ tistic in Example 9.1.2 The following R code generates a sample from the discrepancy statistic specified in Example 9.1.2. To generate the sample, type y ­discrepancy(m,n) to place a sample of size m in y, where n is the size of the original data set. This code can be easily modified to generate samples from other discrepancy statistics. Example B.1.6 function name: discrepancy parameters: resample size size of data return value: an array of m discrepancies m n # # # # # # # # # discrepancy ­ function(m,n) { description: this function generates m discrepancies when the data size is n result for(i in 1:m) { ­ rep(0,m); x xbar r result[i] ­ rnorm(n); ­ mean(x); ­ (x­xbar)/sqrt((sum((x­xbar)**2))); ­ ­sum(log(r**2)); } return(result/n); } EXAMPLE B.1.7 Generating from a Dirichlet Distribution in Example 10.2.
3 The following R code generates a sample from a Dirichlet( 1 4) distribution. To generate from this distribution, first assign values to the vector alpha and then type ddirichlet(n,alpha), where n is the sample size. 3 2 n alpha vector(alpha1,...,alphak) sample size return value: Example B.1.7 function name: ddirichlet parameters: # # # # # # # # # ddirichlet k ­ matrix(0,n,k); result for(i in 1:k) result[,i] for(i in 1:n) result[i,] ­ length(alpha); a (n x k) matrix. rows are i.i.d. samples description: this function generates n random samples from Dirichlet(alpha1,...,alphak) distribution ­ function(n,alpha) { ­ rgamma(n,alpha[i]); ­ result[i,] / sum(result[i,]); Appendix B: Computations 698 } return(result); Matrices A matrix can be thought of as a collection of data values with two subscripts or as a rectangular array of data. So if a is a matrix, then a[i,j] is the i j ­th element in a. Note that a[i,] refers to the ith row of a and a[,j] refers to the j th column of a. If a matrix has m rows and n columns, then it is an m n matrix, and m and n are referred to as the dimensions of the matrix. Perhaps the simplest way to create matrices is with cbind and rbind commands. For example, x ­c(1,2,3) y ­c(4,5,6) a ­cbind(x,y) a x y [1,] 1 4 [2,] 2 5 [3,] 3 6 creates the vectors x and y, and the cbind command takes x as the first column and y as the second column of the newly created 3 2 matrix a. Note that in the printout of a, the columns are still labelled x and y, although we can still refer to these as a[,1] and a[,2]. We can remove these column names via the command colnames(a) ­NULL. Similarly, the
rbind command will treat vector arguments as the rows of a matrix. To determine the number of rows and columns of a matrix a, we can use the nrow(a) and ncol(a) commands. We can also create a diagonal matrix using the diag command. If x is an n­dimensional vector, then diag(x) is an n n matrix with the entries in x along the diagonal and 0’s elsewhere. If a is an m n matrix, then diag(a) is the vector with entries taken from the main diagonal of a. To create an n n identity matrix, use diag(n). There are a number of operations that can be carried out on matrices. If matrices a and b are m n then a+b is the m n matrix formed by adding the matrices componentwise. The transpose of a is the n m matrix t(a), with i th row equal to the ith column of a. If c is a number, then c*a is the m n matrix formed by multiplying each element of a by c. If a is m n and b is n p then a%*%b is the p matrix product (Appendix A.4) of a and b. A numeric vector is treated as a m column vector in matrix multiplication. Note that a*b is also defined when a and b are of the same dimension, but this is the componentwise product of the two matrices, which is quite different from the matrix product. If a is an m m matrix, then the inverse of a is obtained as solve(a). The solve command will return an error if the matrix does not have an inverse. If a is a square matrix, then det(a) computes the determinant of a. We now consider an important application. Appendix B.2: Using Minitab 699 EXAMPLE B.1.8 Fitting Regression Models Suppose the n­dimensional vector y corresponds to the response vector and the n k matrix V corresponds to the design matrix when we are fitting a linear regression model is given by b as computed in given by E y V The least­squares estimate of V b ­solve(t(V)%*%V)%*%t(V)%*%y with the vector of predicted values p and residuals r given by p ­V%*%b r ­y­p with
squared lengths slp ­t(p)%*%p slr ­t(r)%*%r where slp is the squared length of p and slr is the squared length of r. Note that the matrix solve(t(V)%*%V) is used for forming confidence intervals and tests for the individual i Virtually all the computations involved in fitting and inference for the linear regression matrix can be carried out using matrix computations in R like the ones we have illustrated. Packages There are many packages that have been written to extend the capability of basic R. It is very likely that if you have a data analysis need that cannot be met with R, then you can find a freely available package to add. We refer the reader to?install.packages and?library for more on this. B.2 Using Minitab All the computations found in this text were carried out using Minitab. This statistical software package is very easy to learn and use. Other packages such as SAS or R (see Section B.1) could also be used for this purpose. Most of the computations were performed using Minitab like a calculator, i.e., data were entered and then a number of Minitab commands were accessed to obtain the quantities desired. No programming is required for these computations. There were a few computations, however, that did involve a bit of programming. Typically, this was a computation in which numerous operations had to be performed many times, and so looping was desirable. In each such case, we have recorded here the Minitab code that we used for these computations. As the following examples show, these programs were never very involved. Students can use these programs as templates for writing their own Minitab pro­ grams. Actually, the language is so simple that we feel that anyone using another language for programming can read these programs and use them as templates in the same way. Simply think of the symbols c1, c2, etc. as arrays where we address the ith element in the array c1 by c1(i). Furthermore, there are constants k1, k2, etc. 700 Appendix B: Computations A Minitab program is called a macro and must start with the statement gmacro and end with the statement endmacro. The first statement after gmacro gives a name to the program. Comments in a program
, put there for explanatory purposes, start with note. If the file containing the program is called prog.txt and this is stored in the root directory of a disk drive called c, then the Minitab command MTB %c:/prog.txt will run the program. Any output will either be printed in the Session window (if you have used a print command) or stored in the Minitab worksheet. More details on Minitab can be found by using Help in the program. We provide some examples of Minitab macros used in the text. EXAMPLE B.2.1 Bootstrapping in Example 6.4.2 The following Minitab code generates 1000 bootstrap samples from the data in c1, calculates the median of each of these samples, and then calculates the sample variance of these medians. overwritten gmacro bootstrapping base 34256734 note ­ original sample is stored in c1 note ­ bootstrap sample is placed in c2 with each one note note ­ medians of bootstrap samples are stored in c3 note ­ k1 = size of data set (and bootstrap samples) let k1=15 do k2=1:1000 sample 15 c1 c2; replace. let c3(k2)=median(c2) enddo note ­ k3 equals (6.4.5) let k3=(stdev(c3))**2 print k3 endmacro EXAMPLE B.2.2 Sampling from the Posterior in Example 7.3.1 The following Minitab code generates a sample of 104 from the joint posterior in Ex­ density takes the form ample 7.3.1. Note that in Minitab software, the Gamma distribution, as defined So to generate from a Gamma 1e x x in this book, we must put the second shape parameter equal to 1 in Minitab. gmacro normalpost note ­ the base command sets the seed for the random note numbers Appendix B.2: Using Minitab 701 = (alpha_0 + n/2) base 34256734 note ­ the parameters of the posterior note ­ k1 = first parameter of the gamma distribution note let k1=9.5 note ­ k2 = 1/beta let k2=1/77.578 note ­ k3 = posterior mean of mu let k3=5.161 note ­ k4 = (
n + 1/(tau_0 squared) )^(­1) let k4=1/15.5 note ­ main loop note ­ c3 contains generated value of sigma**2 note ­ c4 contains generated value of mu note ­ c5 contains generated value of coefficient of variation do k5=1:10000 random 1 c1; gamma k1 k2. let c3(k5)=1/c1(1) let k6=sqrt(k4/c1(1)) random 1 c2; normal k3 k6. let c4(k5)=c2(1) let c5(k5)=sqrt(c3(k5))/c4(k5) enddo endmacro EXAMPLE B.2.3 Calculating the Estimates and Standard Errors in Example 7.3.1 We have a sample of 104 values from the posterior distribution of stored in C5. The following computations use this sample to calculate an estimate of the posterior probability that 0 5 (k1), as well as to calculate the standard error of this estimate (k2), the estimate minus three times its standard error (k3), and the estimate plus three times its standard error (k4). let c6=c5 le.5 let k1=mean(c6) let k2=sqrt(k1*(1­k1))/sqrt(10000) let k3=k1­3*k2 let k4=k1+3*k2 print k1 k2 k3 k4 702 Appendix B: Computations EXAMPLE B.2.4 Using the Gibbs Sampler in Example 7.3.2 The following Minitab code generates a chain of length 104 values using the Gibbs sampler described in Example 7.3.2. gmacro gibbs base 34256734 note ­ data sample is stored in c1 note ­ starting value for mu. let k1=mean(c1) note ­ starting value for sigma**2 let k2=stdev(c1) let k2=k2**2 note ­ lambda let k3=3 note ­ sample size let k4=15 note ­ n/2 + alpha_0 + 1/2 let k5=k4/2 +2+.5 note ­ mu_0 let k6=4 note ­ tau_0**2 let k7
=2 note ­ beta_0 let k8=1 let k9=(k3/2+.5) note ­ main loop do k100=1:10000 note ­ generate the nu_i in c10 do k111=1:15 let k10=.5*(((c1(k111)­k1)**2)/(k2*k3) +1) let k10=1/k10 random 1 c2; gamma k9 k10. let c10(k111)=c2(1) enddo note ­ generate sigma**2 in c20 let c11=c10*((c1­k1)**2) let k11=.5*sum(c11)/k3+.5*((k1­k6)**2)/k7 +k8 let k11=1/k11 random 1 c2; gamma k5 k11. let c20(k100)=1/c2(1) let k2=1/c2(1) note ­ generate mu in c21 let k13=1/(sum(c10)/k3 +1/k7) Appendix B.2: Using Minitab 703 let c11=c1*c10/k3 let k14=sum(c11)+k6/k7 let k14=k13*k14 let k13=sqrt(k13*k2) random 1 c2; normal k14 k13. let c21(k100)=c2(1) let k1=c2(1) enddo endmacro EXAMPLE B.2.5 Batching in Example 7.3.2 The following Minitab code divides the generated sample, obtained via the Gibbs sam­ pling code for Example 7.3.2, into batches, and calculates the batch means. gmacro batching note ­ k2= batch size let k2=40 note ­ k4 holds the batch sums note ­ c1 contains the data to be batched (10000 data values) note ­ c2 will contain the batch means (250 batch means) do k10=1:10000/40 let k4=0 do k20=0:39 let k3=c1(k10+k20) let k4=k4+k3 enddo let k11=floor(k10/k2) +
1 let c2(k11)=k4/k2 enddo endmacro EXAMPLE B.2.6 Simulating a Sample from the Distribution of the Discrepancy Sta­ tistic in Example 9.1.2 The following code generates a sample from the discrepancy statistic specified in Ex­ ample 9.1.2. gmacro goodnessoffit base 34256734 note ­ generated sample is stored in c1 note ­ residuals are placed in c2 note ­ value of D(r) are placed in c3 note ­ k1 = size of data set let k1=5 704 Appendix B: Computations do k2=1:10000 random k1 c1 let k3=mean(c1) let k4=sqrt(k1­1)*stdev(c1) let c2=((c1­k3)/k4)**2 let c2=loge(c2) let k5=­sum(c2)/k1 let c3(k2)=k5 enddo endmacro EXAMPLE B.2.7 Generating from a Dirichlet Distribution in Example 10.2.3 The following code generates a sample from a Dirichlet( 1 1 where 1 1 5. 2 3 2 4 2 3 3 4) distribution, number generator (so you can repeat a simulation). a Dirichlet(k1,k2,k3,k4) distribution. gmacro dirichlet note ­ the base command sets the seed for the random note base 34256734 note ­ here we provide the algorithm for generating from note note ­ assign the values of the parameters. let k1=2 let k2=3 let k3=1 let k4=1.5 let k5=K2+k3+k4 let k6=k3+k4 note ­ generate the sample with i­th sample in i­th row note do k10=1:5 random 1 c1; beta k1 k5. let c2(k10)=c1(1) random 1 c1; beta k2 k6. let c3(k10)=(1­c2(k10))*c1(1) random 1 c1; beta k3 k4. let c4(k10)=(1­c2(k10)­c3(k10))
*c1(1) let c5(k10)= 1­c2(k10)­c3(k10)­c4(k10) enddo endmacro of c2, c3, c4, c5,.... Appendix C Common Distributions We record here the most commonly used distributions in probability and statistics as well as some of their basic characteristics. C.1 Discrete Distributions [0 1] (same as Binomial 1 1 x for x x 1 ). 0 1 1. Bernoulli probability function: p x mean: variance: moment­generating function: m t 1 et for t R1 [0 1] n x for x 0 1 n 1 1 0 1] (same as Negative­Binomial 1 et n for t R1 ). n 0 an integer, n x 1 x 2. Binomial n probability function: p x mean: n variance: n 1 moment­generating function: m t 3. Geometric probability function: p x mean: 1 variance: 1 moment­generating function: m t 1 2 x for x 0 1 2 1 1 et 1 for t ln 1 4. Hypergeometric N M n, M N n probability function: N all positive integers for max 0 n M N x min n M mean: n M N variance: n M N 1 5. Multinomial an integer, each i [0 1] 1 k 1 705 706 Appendix C: Common Distributions probability function: p x1 xk n xk x1 and x1 x1 1 xk k where each xi 0 1 n xk n n i mean: E Xi variance: Var Xi covariance: Cov Xi X j n i 1 i n i j when i j r 6. Negative­Binomial r probability function: p x mean: r 1 variance: r 1 moment­generating function: m t 2 0 7. Poisson probability function: p x mean: variance: moment­generating function: m t x! e x 0 an integer r 1 r 1 x x 0 1] x for x 0 1 2 3 r 1 1 et r for t ln 1 for x 0 1 2 3 exp et 1 for t R1 C.2 Absolutely Continuous Distributions 0 (same as Dirichlet a b ). for for 1 2 R1 2 1 2 2 0 [ 1 1] 1. Beta a b a 0 b density function: f x mean
: a a b variance: ab a b 2. Bivariate Normal density function: f X1 X2 x1 x2 1 2 1 2 1 exp 2 1 2 1 2 for x1 R1 x2 R1 x1 2 2 1 1 x1 1 1 x2 2 2 2 x2 2 2 i mean: E Xi 2 variance: Var Xi i covariance: Cov X1 X2 2 or 3. Chi­squared density function: f x mean: variance: 2, 2 2 1 2 0 (same as Gamma 1x 2 2 2 1 2 ). 1e x 2 for x 0 Appendix C.2: Absolutely Continuous Distributions 707 moment­generating function: m t 1 2t 2 for t 1 2 4. Dirichlet density function: 1 k 1 i 0 for each i f X1 Xk x1 1 1 for xi 0 i xk x1 k 1 1 xk k and 0 x1 xk 1 mean: variance: Var Xi covariance when i j: E Xi Cov Xi ). 0 (same as Gamma 1 x for x 5. Exponential density function: f x 1 mean: variance: moment­generating function: m t Note that some books and software packages instead replace of the Exponential when using software to generate from this distribution. 1 for t t in the definition distribution — always check this when using another book or by 1 6. F density function for x 0 mean: variance: 2 2 7. Gamma 2 when 2 2 0 0 1 x density function: f x mean: variance: moment­generating function: m t 2 e 2 2 4 when 4 x for x 0 t for t 708 Appendix C: Common Distributions Note that some books and software packages instead replace of the Gamma when using software to generate from this distribution. in the definition distribution — always check this when using another book or by 1 8. Lognormal or log N density function: f x 2 2 mean: exp variance: exp 2 2 exp 2 1 2 2 2 0 2 R1 1 2x 1 exp 1 2 2 ln x 2 for x 0 9. N 2 R1 2 0 2 density function: f x mean: variance: moment­generating function: m t 2 2 1 2 exp 1 2 2 x 2 for x R1 exp t 2t 2 2 for t R1 10. Student density function: or t 0 ( 1 gives the
Cauchy distribution) f x 1 2 2 R1 1 2 for x x 2 1 1 2 1 mean: 0 when variance: 1 2 when 2 L 1 R 11. Uniform[L R] R density function: f x mean: L variance: (R moment­generating function: m t L 2 12 R 2 L for L x R eRt eLt t R L Appendix D Tables The following tables can be used for various computations. It is recommended, how­ ever, that the reader become familiar with the use of a statistical software package instead of relying on the tables. Computations of a much greater variety and accuracy can be carried out using the software, and, in the end, it is much more convenient. 709 710 Appendix D: Tables D.1 Random Numbers Each line in Table D.1 is a sample of 40 random digits, i.e., 40 independent and identi­ cally distributed (i.i.d.) values from the uniform distribution on the set Suppose we want a sample of five i.i.d. values from the uniform distribution on S 25, i.e., a random sample of five, with replacement, from S. To do this, pick a starting point in the table and start reading off successive (nonoverlapping) two­digit numbers, treating a pair such as 07 as 7, and discarding any pairs that are not in the range 1 to 25, until you have five values. For example, if we start at line 110, we read the pairs ( indicates a sample element) 38, 44, 84, 87, 89, 18, 33, 82, 46, 97, 39, 36, 44, 20, 06, 76, 68, 80, 87, 08, 81, 48, 66, 94, 87, 60, 51, 30, 92, 97, 00, 41, 27, 12. We can see at this point that we have a sample of five given by 18, 20, 6, 8, 12. If we want a random sample of five, without replacement, from S, then we proceed as above but now ignore any repeats in the generated sample until we get the five numbers. In this preceding case, we did not get any repeats, so this is also a simple random sample of size five without replacement. Table D.1 Random Numbers 19223 95034 05756
367 32337 03316 13121 54969 43912 18984 60869 12349 05376 58958 22720 87065 74133 21117 70595 22791 67306 28420 52067 42090 55494 09628 67690 54035 88131 93879 81800 98441 11188 04606 27381 82637 28552 25752 21953 16698 30406 96587 65985 07165 50148 16201 86792 16297 22897 98163 43400 07626 17467 45944 25831 68683 17638 34210 06283 45335 70043 64158 22138 34377 36243 76971 16043 72941 41764 77038 13008 83993 22869 27689 82926 75957 15706 73345 26238 97341 46254 88153 62336 21112 35574 99271 45297 64578 11022 67197 79124 28310 49525 90341 63078 37531 17229 63890 52630 76315 32165 01343 21394 81232 43939 23840 05995 84589 06788 76358 26622 Line 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 712 Appendix D: Tables D.2 Standard Normal Cdf N 0 1 then we can use Table D.2 to compute the cumulative distribution for Z For example, suppose we want to compute If Z function (cdf) 1 03 The symmetry of the N 0 1 distribution about 0 implies that 1 03 so using Table D.2, we have that 03 P Z z z 1 03 1 0 1515 0 8485 00.0003.0005.0007.0010.0013.0019.0026.0035.0047.0062.0082.0107.0139.0179.0228.0287.0359.0446.0548.0668.0808.0968.1151.1357.1587.1841.2119.2420.2743.3085.3446.3821.4207.4602.5000 01.0003.0005.0007.0009.0013.0018.0025.0034.0045.0060.0080.
0104.0136.0174.0222.0281.0351.0436.0537.0655.0793.0951.1131.1335.1562.1814.2090.2389.2709.3050.3409.3783.4168.4562.4960 Table D.2 Standard Normal Cdf 06 04.0003.0003 02.0003 03.0003 05.0003.0005.0006.0009.0013.0018.0024.0033.0044.0059.0078.0102.0132.0170.0217.0274.0344.0427.0526.0643.0778.0934.1112.1314.1539.1788.2061.2358.2676.3015.3372.3745.4129.4522.4920.0004.0006.0009.0012.0017.0023.0032.0043.0057.0075.0099.0129.0166.0212.0268.0336.0418.0516.0630.0764.0918.1093.1292.1515.1762.2033.2327.2643.2981.3336.3707.4090.4483.4880.0004.0006.0008.0012.0016.0023.0031.0041.0055.0073.0096.0125.0162.0207.0262.0329.0409.0505.0618.0749.0901.1075.1271.1492.1736.2005.2296.2611.2946.3300.3669.4052.4443.4840.0004.0006.0008.0011.0016.0022.0030.0040.0054.0071.0094.0122.0158.0202.0256.0322.0401.0495.0606.0735.0885.1056.1251.1469.1711.1977.2266.2578.2912.3264.3632.4013.4404.4801.0004.0006
.0008.0011.0015.0021.0029.0039.0052.0069.0091.0119.0154.0197.0250.0314.0392.0485.0594.0721.0869.1038.1230.1446.1685.1949.2236.2546.2877.3228.3594.3974.4364.4761 07.0003.0004.0005.0008.0011.0015.0021.0028.0038.0051.0068.0089.0116.0150.0192.0244.0307.0384.0475.0582.0708.0853.1020.1210.1423.1660.1922.2206.2514.2843.3192.3557.3936.4325.4721 08.0003.0004.0005.0007.0010.0014.0020.0027.0037.0049.0066.0087.0113.0146.0188.0239.0301.0375.0465.0571.0694.0838.1003.1190.1401.1635.1894.2177.2483.2810.3156.3520.3897.4286.4681 09.0002.0003.0005.0007.0010.0014.0019.0026.0036.0048.0064.0084.0110.0143.0183.0233.0294.0367.0455.0559.0681.0823.0985.1170.1379.1611.1867.2148.2451.2776.3121.3483.3859.4247.4641 Appendix D.3: Chi­Squared Distribution Quantiles 713 D.3 Chi­Squared Distribution Quantiles 2 d f If X For example, if d f distribution. then we can use Table D.3 to obtain some quantiles for this distribution 21 16 is the 0 98 quantile of this 0 98 then x0 98 10 and P Table D.3 2 d f Quantiles 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
29 30 40 50 60 80 100 0.75 0.85 0.90 0.95 1.32 2.77 4.11 5.39 6.63 7.84 9.04 10.22 11.39 12.55 13.70 14.85 15.98 17.12 18.25 19.37 20.49 21.60 22.72 23.83 24.93 26.04 27.14 28.24 29.34 30.43 31.53 32.62 33.71 34.80 45.62 56.33 66.98 88.13 109.1 2.07 3.79 5.32 6.74 8.12 9.45 10.75 12.03 13.29 14.53 15.77 16.99 18.20 19.41 20.60 21.79 22.98 24.16 25.33 26.50 27.66 28.82 29.98 31.13 32.28 33.43 34.57 35.71 36.85 37.99 49.24 60.35 71.34 93.11 114.7 2.71 4.61 6.25 7.78 9.24 10.64 12.02 13.36 14.68 15.99 17.28 18.55 19.81 21.06 22.31 23.54 24.77 25.99 27.20 28.41 29.62 30.81 32.01 33.20 34.38 35.56 36.74 37.92 39.09 40.26 51.81 63.17 74.40 96.58 118.5 3.84 5.99 7.81 9.49 11.07 12.59 14.07 15.51 16.92 18.31 19.68 21.03 22.36 23.68 25.00 26.30 27.59 28.87 30.14 31.41 32.67 33.92 35.17 36.42 37.65 38.89 40.11 41.34 42.56 43.77 55.76 67.50 79.08 101.9 124.3 P 0.975 5.02 7.38 9.35 11.14 12.83 14.45 16.01 17.53 19.02 20.48 21.92 23.34 24.74 26.12 27.49 28.85 30.19 31.53 32.85 34.17 35.48 36.78 38.
08 39.36 40.65 41.92 43.19 44.46 45.72 46.98 59.34 71.42 83.30 106.6 129.6 0.98 0.99 0.995 0.9975 5.41 7.82 9.84 11.67 13.39 15.03 16.62 18.17 19.68 21.16 22.62 24.05 25.47 26.87 28.26 29.63 31.00 32.35 33.69 35.02 36.34 37.66 38.97 40.27 41.57 42.86 44.14 45.42 46.69 47.96 60.44 72.61 84.58 108.1 131.1 6.63 9.21 11.34 13.28 15.09 16.81 18.48 20.09 21.67 23.21 24.72 26.22 27.69 29.14 30.58 32.00 33.41 34.81 36.19 37.57 38.93 40.29 41.64 42.98 44.31 45.64 46.96 48.28 49.59 50.89 63.69 76.15 88.38 112.3 135.8 7.88 10.60 12.84 14.86 16.75 18.55 20.28 21.95 23.59 25.19 26.76 28.30 29.82 31.32 32.80 34.27 35.72 37.16 38.58 40.00 41.40 42.80 44.18 45.56 46.93 48.29 49.64 50.99 52.34 53.67 66.77 79.49 91.95 116.3 140.2 9.14 11.98 14.32 16.42 18.39 20.25 22.04 23.77 25.46 27.11 28.73 30.32 31.88 33.43 34.95 36.46 37.95 39.42 40.88 42.34 43.78 45.20 46.62 48.03 49.44 50.83 52.22 53.59 54.97 56.33 69.70 82.66 95.34 120.1 144.3 0.999 10.83 13.82 16.27 18.47 20.51 22.46 24.32 26.12 27.88 29.59 31.26 32.91 34.
53 36.12 37.70 39.25 40.79 42.31 43.82 45.31 46.80 48.27 49.73 51.18 52.62 54.05 55.48 56.89 58.30 59.70 73.40 86.66 99.61 124.8 149.4 714 Appendix D: Tables D.4 t Distribution Quantiles Table D.4 contains some quantiles for t or Student distributions. For example, if X t d f with d f 2 359 is the 0 98 quantile of the t 10 distribution. Recall that the t d f distribution is symmetric about 0 so, for example, x0 25 0 98 then x0 98 10 and P x0 75 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 40 50 60 80 100 1000 0.75 1.000 0.816 0.765 0.741 0.727 0.718 0.711 0.706 0.703 0.700 0.697 0.695 0.694 0.692 0.691 0.690 0.689 0.688 0.688 0.687 0.686 0.686 0.685 0.685 0.684 0.684 0.684 0.683 0.683 0.683 0.681 0.679 0.679 0.678 0.677 0.675 0.674 50% 0.85 1.963 1.386 1.250 1.190 1.156 1.134 1.119 1.108 1.100 1.093 1.088 1.083 1.079 1.076 1.074 1.071 1.069 1.067 1.066 1.064 1.063 1.061 1.060 1.059 1.058 1.058 1.057 1.056 1.055 1.055 1.050 1.047 1.045 1.043 1.042 1.037 1.036 70% Table D.4 t d f Quantiles 0.90 3.078 1.886 1.638 1.533 1.476 1.440 1.415 1.397 1.383 1.372 1.363 1.356 1.350 1.345 1.341 1.337 1.333 1.330 1.328 1.325 1.323 1.321 1
.319 1.318 1.316 1.315 1.314 1.313 1.311 1.310 1.303 1.299 1.296 1.292 1.290 1.282 1.282 0.95 6.314 2.920 2.353 2.132 2.015 1.943 1.895 1.860 1.833 1.812 1.796 1.782 1.771 1.761 1.753 1.746 1.740 1.734 1.729 1.725 1.721 1.717 1.714 1.711 1.708 1.706 1.703 1.701 1.699 1.697 1.684 1.676 1.671 1.664 1.660 1.646 1.645 P 0.975 12.71 4.303 3.182 2.776 2.571 2.447 2.365 2.306 2.262 2.228 2.201 2.179 2.160 2.145 2.131 2.120 2.110 2.101 2.093 2.086 2.080 2.074 2.069 2.064 2.060 2.056 2.052 2.048 2.045 2.042 2.021 2.009 2.000 1.990 1.984 1.962 1.960 0.98 15.89 4.849 3.482 2.999 2.757 2.612 2.517 2.449 2.398 2.359 2.328 2.303 2.282 2.264 2.249 2.235 2.224 2.214 2.205 2.197 2.189 2.183 2.177 2.172 2.167 2.162 2.158 2.154 2.150 2.147 2.123 2.109 2.099 2.088 2.081 2.056 2.054 80% 90% 95% 96% 0.99 31.82 6.965 4.541 3.747 3.365 3.143 2.998 2.896 2.821 2.764 2.718 2.681 2.650 2.624 2.602 2.583 2.567 2.552 2.539 2.528 2.518 2.508 2.500 2.492 2.485 2.479 2.473 2
.467 2.462 2.457 2.423 2.403 2.390 2.374 2.364 2.330 2.326 98% Confidence level 0.995 63.66 9.925 5.841 4.604 4.032 3.707 3.499 3.355 3.250 3.169 3.106 3.055 3.012 2.977 2.947 2.921 2.898 2.878 2.861 2.845 2.831 2.819 2.807 2.797 2.787 2.779 2.771 2.763 2.756 2.750 2.704 2.678 2.660 2.639 2.626 2.581 2.576 0.9975 0.999 127.3 14.09 7.453 5.598 4.773 4.317 4.029 3.833 3.690 3.581 3.497 3.428 3.372 3.326 3.286 3.252 3.222 3.197 3.174 3.153 3.135 3.119 3.104 3.091 3.078 3.067 3.057 3.047 3.038 3.030 2.971 2.937 2.915 2.887 2.871 2.813 2.807 318.3 22.33 10.21 7.173 5.893 5.208 4.785 4.501 4.297 4.144 4.025 3.930 3.852 3.787 3.733 3.686 3.646 3.611 3.579 3.552 3.527 3.505 3.485 3.467 3.450 3.435 3.421 3.408 3.396 3.385 3.307 3.261 3.232 3.195 3.174 3.098 3.091 99% 99.5% 99.8% Appendix D.5: F Distribution Quantiles 715 D.5 F Distribution Quantiles F nd f dd f If X distribution For example, if nd f is the 0 975 quantile of the F 3 4 distribution. Note that if X Y then we can use Table D.5 to obtain some quantiles for this 9 98 then 0 975 then x0 975 F nd f dd f F dd f nd f and P X 4 and
P 3 dd f 1 x. 1 X P Y x Table D.5 F nd f dd f Quantiles nd f 1 39.86 161.45 647.79 2 49.50 199.50 799.50 3 53.59 215.71 864.16 4 55.83 224.58 899.58 5 57.24 230.16 921.85 6 58.20 233.99 937.11 4052.18 4999.50 5403.35 5624.58 5763.65 5858.99 405284.07 499999.50 540379.20 562499.58 576404.56 585937.11 8.53 18.51 38.51 98.50 9.00 19.00 39.00 99.00 9.16 19.16 39.17 99.17 9.24 19.25 39.25 99.25 9.29 19.30 39.30 99.30 9.33 19.33 39.33 99.33 998.50 999.00 999.17 999.25 999.30 999.33 5.54 10.13 17.44 34.12 5.46 9.55 16.04 30.82 5.39 9.28 15.44 29.46 5.34 9.12 15.10 28.71 5.31 9.01 14.88 28.24 5.28 8.94 14.73 27.91 167.03 148.50 141.11 137.10 134.58 132.85 4.54 7.71 12.22 21.20 74.14 4.06 6.61 10.01 16.26 47.18 3.78 5.99 8.81 13.75 35.51 3.59 5.59 8.07 12.25 29.25 4.32 6.94 10.65 18.00 61.25 3.78 5.79 8.43 13.27 37.12 3.46 5.14 7.26 10.92 27.00 3.26 4.74 6.54 9.55 4.19 6.59 9.98 16.69 56.18 3.62 5.41 7.76 12.06 33.20 3.29 4.76 6.60 9.78 4.11 6.39 9.60 15.98 53.44 3.52 5.19 7.39 11.39
31.09 3.18 4.53 6.23 9.15 4.05 6.26 9.36 15.52 51.71 3.45 5.05 7.15 10.97 29.75 3.11 4.39 5.99 8.75 4.01 6.16 9.20 15.21 50.53 3.40 4.95 6.98 10.67 28.83 3.05 4.28 5.82 8.47 23.70 21.92 20.80 20.03 3.07 4.35 5.89 8.45 2.96 4.12 5.52 7.85 2.88 3.97 5.29 7.46 2.83 3.87 5.12 7.19 21.69 18.77 17.20 16.21 15.52 dd.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 716 Appendix D: Tables dd f 1 2 3 4 5 6 7 Table D.5 F nd f dd f Quantiles (continued) nd f 7 58.91 236.77 948.22 8 59.44 238.88 956.66 9 59.86 240.54 963.28 10 60.19 241.88 968.63 11 60.47 242.98 973.03 12 60.71 243.91 976.71 5928.36 5981.07 6022.47 6055.85 6083.32 6106.32 592873.29 598144.16 602283.99 605620.97 608367.68 610667.82 9.35 19.35 39.36 99.36 9.37 19.37 39.37 99.37 9.38 19.38 39.39 99.39 9.39 19.40 39.40 99.40 9.40 19.40 39.41 99.41 9.41 19.41 39.41 99.42 999.36 999.
37 999.39 999.40 999.41 999.42 5.27 8.89 14.62 27.67 5.25 8.85 14.54 27.49 5.24 8.81 14.47 27.35 5.23 8.79 14.42 27.23 5.22 8.76 14.37 27.13 5.22 8.74 14.34 27.05 131.58 130.62 129.86 129.25 128.74 128.32 3.98 6.09 9.07 14.98 49.66 3.37 4.88 6.85 10.46 28.16 3.01 4.21 5.70 8.26 3.95 6.04 8.98 14.80 49.00 3.34 4.82 6.76 10.29 27.65 2.98 4.15 5.60 8.10 3.94 6.00 8.90 14.66 48.47 3.32 4.77 6.68 10.16 27.24 2.96 4.10 5.52 7.98 3.92 5.96 8.84 14.55 48.05 3.30 4.74 6.62 10.05 26.92 2.94 4.06 5.46 7.87 3.91 5.94 8.79 14.45 47.70 3.28 4.70 6.57 9.96 3.90 5.91 8.75 14.37 47.41 3.27 4.68 6.52 9.89 26.65 26.42 2.92 4.03 5.41 7.79 2.90 4.00 5.37 7.72 19.46 19.03 18.69 18.41 18.18 17.99 2.78 3.79 4.99 6.99 2.75 3.73 4.90 6.84 2.72 3.68 4.82 6.72 2.70 3.64 4.76 6.62 2.68 3.60 4.71 6.54 2.67 3.57 4.67 6.47 15.02 14.63 14.33 14.08 13.88 13.71 P 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.
900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 Appendix D.5: F Distribution Quantiles 717 Table D.5 F nd f dd f Quantiles (continued) nd f 30 60 15 20 120 61.22 245.95 984.87 61.74 248.01 993.10 6157.28 6208.73 62.26 250.10 1001.41 6260.65 62.79 252.20 1009.80 6313.03 63.06 253.25 1014.02 6339.39 10000 63.32 254.30 1018.21 6365.55 615763.66 620907.67 626098.96 631336.56 633972.40 636587.61 9.42 19.43 39.43 99.43 9.44 19.45 39.45 99.45 9.46 19.46 39.46 99.47 9.47 19.48 39.48 99.48 9.48 19.49 39.49 99.49 9.49 19.50 39.50 99.50 999.43 999.45 999.47 999.48 999.49 999.50 5.20 8.70 14.25 26.87 5.18 8.66 14.17 26.69 5.17 8.62 14.08 26.50 5.15 8.57 13.99 26.32 5.14 8.55 13.95 26.22 5.13 8.53 13.90 26.13 127.37 126.42 125.45 124.47 123.97 123.48 3.87 5.86 8.66 14.20 46.76 3.24 4.62 6.43 9.72 3.84 5.80 8.56 14.02 46.10 3.21 4.56 6.33 9.55 3.82 5.75 8.46 13.84 45.43 3.17 4.50 6.23 9.38 3.79 5.69 8.36 13.65 44.75 3.14 4.43 6.12 9.20 3.78 5.66 8.31 13.56 44.40
3.12 4.40 6.07 9.11 3.76 5.63 8.26 13.46 44.06 3.11 4.37 6.02 9.02 25.91 25.39 24.87 24.33 24.06 23.79 2.87 3.94 5.27 7.56 2.84 3.87 5.17 7.40 2.80 3.81 5.07 7.23 2.76 3.74 4.96 7.06 2.74 3.70 4.90 6.97 2.72 3.67 4.85 6.88 17.56 17.12 16.67 16.21 15.98 15.75 2.63 3.51 4.57 6.31 2.59 3.44 4.47 6.16 2.56 3.38 4.36 5.99 2.51 3.30 4.25 5.82 2.49 3.27 4.20 5.74 2.47 3.23 4.14 5.65 13.32 12.93 12.53 12.12 11.91 11.70 dd.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 718 Appendix D: Tables Table D.5 F nd f dd f Quantiles (continued) 1 3.46 5.32 7.57 11.26 25.41 3.36 5.12 7.21 10.56 22.86 3.29 4.96 6.94 10.04 21.04 3.23 4.84 6.72 9.65 dd f 8 9 10 11 12 13 14 P 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0
.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 nd f 3 2.92 4.07 5.42 7.59 2 3.11 4.46 6.06 8.65 4 2.81 3.84 5.05 7.01 5 2.73 3.69 4.82 6.63 6 2.67 3.58 4.65 6.37 18.49 15.83 14.39 13.48 12.86 3.01 4.26 5.71 8.02 2.81 3.86 5.08 6.99 2.69 3.63 4.72 6.42 2.61 3.48 4.48 6.06 2.55 3.37 4.32 5.80 16.39 13.90 12.56 11.71 11.13 2.92 4.10 5.46 7.56 2.73 3.71 4.83 6.55 2.61 3.48 4.47 5.99 2.52 3.33 4.24 5.64 14.91 12.55 11.28 10.48 2.46 3.22 4.07 5.39 9.93 2.39 3.09 3.88 5.07 9.05 2.33 3.00 3.73 4.82 8.38 2.28 2.92 3.60 4.62 7.86 2.24 2.85 3.50 4.46 7.44 2.86 3.98 5.26 7.21 2.66 3.59 4.63 6.22 2.54 3.36 4.28 5.67 19.69 13.81 11.56 10.35 3.18 4.75 6.55 9.33 2.81 3.89 5.10 6.93 2.61 3.49 4.47 5.95 18.64 12.97 10.80 3.14 4.67 6.41 9.07 2.76 3.81 4.97 6.70 2.56 3.41 4.35 5.74 17.82 12.31 10.21 3.10 4.60 6.30 8.86 2.73 3.74 4.86 6.51 17.14 11.78 2.52 3.34 4.24 5.56 9.73 2.48 3.26 4.12
5.41 9.63 2.43 3.18 4.00 5.21 9.07 2.39 3.11 3.89 5.04 8.62 2.45 3.20 4.04 5.32 9.58 2.39 3.11 3.89 5.06 8.89 2.35 3.03 3.77 4.86 8.35 2.31 2.96 3.66 4.69 7.92 Appendix D.5: F Distribution Quantiles 719 Table D.5 F nd f dd f Quantiles (continued) dd f 8 9 10 11 12 13 14 7 2.62 3.50 4.53 6.18 8 2.59 3.44 4.43 6.03 nd f 9 2.56 3.39 4.36 5.91 10 2.54 3.35 4.30 5.81 11 2.52 3.31 4.24 5.73 12 2.50 3.28 4.20 5.67 12.40 12.05 11.77 11.54 11.35 11.19 2.51 3.29 4.20 5.61 2.47 3.23 4.10 5.47 2.44 3.18 4.03 5.35 10.70 10.37 10.11 2.41 3.14 3.95 5.20 9.52 2.34 3.01 3.76 4.89 8.66 2.28 2.91 3.61 4.64 8.00 2.23 2.83 3.48 4.44 7.49 2.19 2.76 3.38 4.28 7.08 2.38 3.07 3.85 5.06 9.20 2.30 2.95 3.66 4.74 8.35 2.24 2.85 3.51 4.50 7.71 2.20 2.77 3.39 4.30 7.21 2.15 2.70 3.29 4.14 6.80 2.35 3.02 3.78 4.94 8.96 2.27 2.90 3.59 4.63 8.12 2.21 2.80 3.44 4.39 7.48 2.16 2.71 3.31 4.19 6.98 2.12 2.65 3.21 4.03 6.58 2.42 3.14 3.96 5
.26 9.89 2.32 2.98 3.72 4.85 8.75 2.25 2.85 3.53 4.54 7.92 2.19 2.75 3.37 4.30 7.29 2.14 2.67 3.25 4.10 6.80 2.10 2.60 3.15 3.94 6.40 2.40 3.10 3.91 5.18 9.72 2.30 2.94 3.66 4.77 8.59 2.23 2.82 3.47 4.46 7.76 2.17 2.72 3.32 4.22 7.14 2.12 2.63 3.20 4.02 6.65 2.07 2.57 3.09 3.86 6.26 2.38 3.07 3.87 5.11 9.57 2.28 2.91 3.62 4.71 8.45 2.21 2.79 3.43 4.40 7.63 2.15 2.69 3.28 4.16 7.00 2.10 2.60 3.15 3.96 6.52 2.05 2.53 3.05 3.80 6.13 P 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 720 Appendix D: Tables Table D.5 F nd f dd f Quantiles (continued) dd f 8 9 10 11 12 13 14 15 2.46 3.22 4.10 5.52 20 2.42 3.15 4.00 5.36 nd f 30 2.38 3.08 3.89 5.20 10.84 10.48 10.11 2.34 3.01 3.77 4.96 9.24 2.24 2.85 3.52 4.56 8.13 2.17 2.72 3.33 4.25 7.32 2.10 2.62 3.18 4.01 6.71 2.05 2
.53 3.05 3.82 6.23 2.01 2.46 2.95 3.66 5.85 2.30 2.94 3.67 4.81 8.90 2.20 2.77 3.42 4.41 7.80 2.12 2.65 3.23 4.10 7.01 2.06 2.54 3.07 3.86 6.40 2.01 2.46 2.95 3.66 5.93 1.96 2.39 2.84 3.51 5.56 2.25 2.86 3.56 4.65 8.55 2.16 2.70 3.31 4.25 7.47 2.08 2.57 3.12 3.94 6.68 2.01 2.47 2.96 3.70 6.09 1.96 2.38 2.84 3.51 5.63 1.91 2.31 2.73 3.35 5.25 P 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 60 2.34 3.01 3.78 5.03 9.73 2.21 2.79 3.45 4.48 8.19 2.11 2.62 3.20 4.08 7.12 2.03 2.49 3.00 3.78 6.35 1.96 2.38 2.85 3.54 5.76 1.90 2.30 2.72 3.34 5.30 1.86 2.22 2.61 3.18 4.94 120 2.32 2.97 3.73 4.95 9.53 2.18 2.75 3.39 4.40 8.00 2.08 2.58 3.14 4.00 6.94 2.00 2.45 2.94 3.69 6.18 1.93 2.34 2.79 3.45 5.59 1.88 2.25 2.66 3.25 5.14 1.
83 2.18 2.55 3.09 4.77 10000 2.29 2.93 3.67 4.86 9.34 2.16 2.71 3.33 4.31 7.82 2.06 2.54 3.08 3.91 6.76 1.97 2.41 2.88 3.60 6.00 1.90 2.30 2.73 3.36 5.42 1.85 2.21 2.60 3.17 4.97 1.80 2.13 2.49 3.01 4.61 Appendix D.5: F Distribution Quantiles 721 Table D.5 F nd f dd f Quantiles (continued) dd f 15 20 30 60 120 10000 P 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 1 3.07 4.54 6.20 8.68 2 2.70 3.68 4.77 6.36 16.59 11.34 2.97 4.35 5.87 8.10 14.82 2.88 4.17 5.57 7.56 13.29 2.79 4.00 5.29 7.08 11.97 2.75 3.92 5.15 6.85 11.38 2.71 3.84 5.03 6.64 10.83 2.59 3.49 4.46 5.85 9.95 2.49 3.32 4.18 5.39 8.77 2.39 3.15 3.93 4.98 7.77 2.35 3.07 3.80 4.79 7.32 2.30 3.00 3.69 4.61 6.91 nd f 3 2.49 3.29 4.15 5.42 9.34 2.38 3.10 3.86 4.94 8.10 2.28 2.92 3.59 4.51 7.05 2.18 2.76 3.34 4.13 6.17 2.13 2.68 3.23 3.95 5.78 2.08 2.
61 3.12 3.78 5.43 4 2.36 3.06 3.80 4.89 8.25 2.25 2.87 3.51 4.43 7.10 2.14 2.69 3.25 4.02 6.12 2.04 2.53 3.01 3.65 5.31 1.99 2.45 2.89 3.48 4.95 1.95 2.37 2.79 3.32 4.62 5 2.27 2.90 3.58 4.56 7.57 2.16 2.71 3.29 4.10 6.46 2.05 2.53 3.03 3.70 5.53 1.95 2.37 2.79 3.34 4.76 1.90 2.29 2.67 3.17 4.42 1.85 2.21 2.57 3.02 4.11 6 2.21 2.79 3.41 4.32 7.09 2.09 2.60 3.13 3.87 6.02 1.98 2.42 2.87 3.47 5.12 1.87 2.25 2.63 3.12 4.37 1.82 2.18 2.52 2.96 4.04 1.77 2.10 2.41 2.80 3.75 722 Appendix D: Tables Table D.5 F nd f dd f Quantiles (continued) dd f 15 20 30 60 120 10000 P 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 7 2.16 2.71 3.29 4.14 6.74 2.04 2.51 3.01 3.70 5.69 1.93 2.33 2.75 3.30 4.82 1.82 2.17 2.51 2.95 4.09 1.77 2.09 2.39 2.79 3.77 1.72 2.01 2.29 2.64 3.48 8 2.12 2.64 3.20 4.00 6.47
2.00 2.45 2.91 3.56 5.44 1.88 2.27 2.65 3.17 4.58 1.77 2.10 2.41 2.82 3.86 1.72 2.02 2.30 2.66 3.55 1.67 1.94 2.19 2.51 3.27 nd f 9 2.09 2.59 3.12 3.89 6.26 1.96 2.39 2.84 3.46 5.24 1.85 2.21 2.57 3.07 4.39 1.74 2.04 2.33 2.72 3.69 1.68 1.96 2.22 2.56 3.38 1.63 1.88 2.11 2.41 3.10 10 2.06 2.54 3.06 3.80 6.08 1.94 2.35 2.77 3.37 5.08 1.82 2.16 2.51 2.98 4.24 1.71 1.99 2.27 2.63 3.54 1.65 1.91 2.16 2.47 3.24 1.60 1.83 2.05 2.32 2.96 11 2.04 2.51 3.01 3.73 5.94 1.91 2.31 2.72 3.29 4.94 1.79 2.13 2.46 2.91 4.11 1.68 1.95 2.22 2.56 3.42 1.63 1.87 2.10 2.40 3.12 1.57 1.79 1.99 2.25 2.85 12 2.02 2.48 2.96 3.67 5.81 1.89 2.28 2.68 3.23 4.82 1.77 2.09 2.41 2.84 4.00 1.66 1.92 2.17 2.50 3.32 1.60 1.83 2.05 2.34 3.02 1.55 1.75 1.95 2.19 2.75 Appendix D.5: F Distribution Quantiles 723 Table D.5 F nd f dd f Quantiles (continued) dd f 15 20 30 60 120 10000 P 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900
0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 0.900 0.950 0.975 0.990 0.999 15 1.97 2.40 2.86 3.52 5.54 1.84 2.20 2.57 3.09 4.56 1.72 2.01 2.31 2.70 3.75 1.60 1.84 2.06 2.35 3.08 1.55 1.75 1.94 2.19 2.78 1.49 1.67 1.83 2.04 2.52 20 1.92 2.33 2.76 3.37 5.25 1.79 2.12 2.46 2.94 4.29 1.67 1.93 2.20 2.55 3.49 1.54 1.75 1.94 2.20 2.83 1.48 1.66 1.82 2.03 2.53 1.42 1.57 1.71 1.88 2.27 nd f 30 1.87 2.25 2.64 3.21 4.95 1.74 2.04 2.35 2.78 4.00 1.61 1.84 2.07 2.39 3.22 1.48 1.65 1.82 2.03 2.55 1.41 1.55 1.69 1.86 2.26 1.34 1.46 1.57 1.70 1.99 60 1.82 2.16 2.52 3.05 4.64 1.68 1.95 2.22 2.61 3.70 1.54 1.74 1.94 2.21 2.92 1.40 1.53 1.67 1.84 2.25 1.32 1.43 1.53 1.66 1.95 1.24 1.32 1.39 1.48 1.66 120 1.79 2.11 2.46 2.96 4.47 1.64 1.90 2.16 2.52 3.54 1.50 1.68 1.87 2.11 2.76 1.35 1.47 1.58 1.73 2.08 1.26 1.35 1.43 1.53 1.77 1.17 1.22 1.27 1.
33 1.45 10000 1.76 2.07 2.40 2.87 4.31 1.61 1.84 2.09 2.42 3.38 1.46 1.62 1.79 2.01 2.59 1.29 1.39 1.48 1.60 1.89 1.19 1.26 1.31 1.38 1.55 1.03 1.03 1.04 1.05 1.06 724 Appendix D: Tables D.6 Binomial Distribution Probabilities If X Binomial n p then Table D.6 contains entries computing P X k n k pk 1 p n k for various values of n k and p Note that if X X n Y Binomial n 1 p Binomial n p then P X k P Y n k where Table D.6 Binomial Probabilities.01.9801.0198.0001.9703.0294.0003.9606.0388.0006.9510.0480.0010.02.9604.0392.0004.9412.0576.0012.9224.0753.0023.9039.0922.0038.0001.03.9409.0582.0009.9127.0847.0026.8853.1095.0051.0001.8587.1328.0082.0003.04.9216.0768.0016.8847.1106.0046.0001.8493.1416.0088.0002.8154.1699.0142.0006.9415.0571.0014.8858.1085.0055.0002.8330.1546.0120.0005.7828.1957.0204.0011.9321.0659.0020.8681.1240.0076.0003.8080.1749.0162.0008.7514.2192.0274.0019.0001 p.05.9025.0950.0025.8574.1354.0071.0001.8145.1715.0135.0005.7738.2036.0214.0011.7351.2321.0305.0021.0001.6983.2573.0406.0036.0002.06.8836.
1128.0036.8306.1590.0102.0002.7807.1993.0191.0008.7339.2342.0299.0019.0001.6899.2642.0422.0036.0002.6485.2897.0555.0059.0004.9227.0746.0026.0001.8508.1389.0099.0004.7837.1939.0210.0013.0001.7214.2405.0351.0029.0002.6634.2793.0515.0054.0004.6096.3113.0695.0089.0007.07.8649.1302.0049.8044.1816.0137.0003.7481.2252.0254.0013.6957.2618.0394.0030.0001.6470.2922.0550.0055.0003.6017.3170.0716.0090.0007.5596.3370.0888.0134.0013.0001.08.8464.1472.0064.7787.2031.0177.0005.7164.2492.0325.0019.6591.2866.0498.0043.0002.6064.3164.0688.0080.0005.5578.3396.0886.0128.0011.0001.5132.3570.1087.0189.0021.0001.09.8281.1638.0081.7536.2236.0221.0007.6857.2713.0402.0027.0001.6240.3086.0610.0060.0003.5679.3370.0833.0110.0008.5168.3578.1061.0175.0017.0001.4703.3721.1288.0255.0031.0002 Appendix D.6: Binomial Distribution Probabilities 725 Table D.6 Binomial Probabilities (continued10.8100.1800.0100.7290.2430.0270.0010.6561.2916.0486.0036.0001.5905.3280.0729
.0081.0004.5314.3543.0984.0146.0012.0001.4783.3720.1240.0230.0026.0002.4305.3826.1488.0331.0046.0004.15.7225.2550.0225.6141.3251.0574.0034.5220.3685.0975.0115.0005.4437.3915.1382.0244.0022.0001.3771.3993.1762.0415.0055.0004.3206.3960.2097.0617.0109.0012.0001.2725.3847.2376.0839.0185.0026.0002.20.6400.3200.0400.5120.3840.0960.0080.4096.4096.1536.0256.0016.3277.4096.2048.0512.0064.0003.2621.3932.2458.0819.0154.0015.0001.2097.3670.2753.1147.0287.0043.0004.1678.3355.2936.1468.0459.0092.0011.0001.25.5625.3750.0625.4219.4219.1406.0156.3164.4219.2109.0469.0039.2373.3955.2637.0879.0146.0010.1780.3560.2966.1318.0330.0044.0002.1335.3115.3115.1730.0577.0115.0013.0001.1001.2670.3115.2076.0865.0231.0038.0004 p.30.4900.4200.0900.3430.4410.1890.0270.2401.4116.2646.0756.0081.1681.3602.3087.1323.0284.0024.1176.3025.3241.1852.0595.0102.0007.0824.2471.3177.2269.0972.0250.0036
.0002.0576.1977.2965.2541.1361.0467.0100.0012.0001.35.4225.4550.1225.2746.4436.2389.0429.1785.3845.3105.1115.0150.1160.3124.3364.1811.0488.0053.0754.2437.3280.2355.0951.0205.0018.0490.1848.2985.2679.1442.0466.0084.0006.0319.1373.2587.2786.1875.0808.0217.0033.0002.40.3600.4800.1600.2160.4320.2880.0640.1296.3456.3456.1536.0256.0778.2592.3456.2304.0768.0102.0467.1866.3110.2765.1382.0369.0041.0280.1306.2613.2903.1935.0774.0172.0016.0168.0896.2090.2787.2322.1239.0413.0079.0007.45.3025.4950.2025.1664.4084.3341.0911.0915.2995.3675.2005.0410.0503.2059.3369.2757.1128.0185.0277.1359.2780.3032.1861.0609.0083.0152.0872.2140.2918.2388.1172.0320.0037.0084.0548.1569.2568.2627.1719.0703.0164.0017.50.2500.5000.2500.1250.3750.3750.1250.0625.2500.3750.2500.0625.0313.1563.3125.3125.1562.0312.0156.0938.2344.3125.2344.0937.0156.0078.0547.1641.2734.2734.1641.0547.0078.0039.0313.10
94.2188.2734.2188.1094.0312.0039 726 Appendix D: Tables Table D.6 Binomial Probabilities (continued).01.9135.0830.0034.0001.02.8337.1531.0125.0006.03.7602.2116.0262.0019.0001.04.6925.2597.0433.0042.0003 p.05.6302.2985.0629.0077.0006.06.5730.3292.0840.0125.0012.0001.07.5204.3525.1061.0186.0021.0002.08.4722.3695.1285.0261.0034.0003.9044.0914.0042.0001.8171.1667.0153.0008.7374.2281.0317.0026.0001.6648.2770.0519.0058.0004.5987.3151.0746.0105.0010.0001.5386.3438.0988.0168.0019.0001.4840.3643.1234.0248.0033.0003.4344.3777.1478.0343.0052.0005.8864.1074.0060.0002.7847.1922.0216.0015.0001.6938.2575.0438.0045.0003.6127.3064.0702.0098.0009.0001.5404.3413.0988.0173.0021.0002.4759.3645.1280.0272.0039.0004.4186.3781.1565.0393.0067.0008.0001.3677.3837.1835.0532.0104.0014.0001.09.4279.3809.1507.0348.0052.0005.3894.3851.1714.0452.0078.0009.0001.3225.3827.2082.0686.0153.0024.0003.8601.1303.0092.0004.7386.2261.0323.0029
.0002.6333.2938.0636.0085.0008.0001.5421.3388.0988.0178.0022.0002.4633.3658.1348.0307.0049.0006.3953.3785.1691.0468.0090.0013.0001.3367.3801.2003.0653.0148.0024.0003.2863.3734.2273.0857.0223.0043.0006.0001.2430.3605.2496.1070.0317.0069.0011.0001 n 9 10 12 15 10 10 11 12 10 11 12 13 14 15 Appendix D.6: Binomial Distribution Probabilities 727 Table D.6 Binomial Probabilities (continued).10.3874.3874.1722.0446.0074.0008.0001.3487.3874.1937.0574.0112.0015.0001.2824.3766.2301.0852.0213.0038.0005.2059.3432.2669.1285.0428.0105.0019.0003.15.2316.3679.2597.1069.0283.0050.0006.1969.3474.2759.1298.0401.0085.0012.0001.1422.3012.2924.1720.0683.0193.0040.0006.0001.0874.2312.2856.2184.1156.0449.0132.0030.0005.0001.20.1342.3020.3020.1762.0661.0165.0028.0003.1074.2684.3020.2013.0881.0264.0055.0008.0001.0687.2062.2835.2362.1329.0532.0155.0033.0005.0001.0352.1319.2309.2501.1876.1032.0430.0138.0035.0007.0001.25.0751.2253.3003.2336.1168.0389.0087.0012.0001.0563.18
77.2816.2503.1460.0584.0162.0031.0004.0317.1267.2323.2581.1936.1032.0401.0115.0024.0004.0134.0668.1559.2252.2252.1651.0917.0393.0131.0034.0007.0001 n 9 10 12 15 10 10 11 12 10 11 12 13 14 15 p.30.0404.1556.2668.2668.1715.0735.0210.0039.0004.0282.1211.2335.2668.2001.1029.0368.0090.0014.0001.0138.0712.1678.2397.2311.1585.0792.0291.0078.0015.0002.0047.0305.0916.1700.2186.2061.1472.0811.0348.0116.0030.0006.0001.35.0207.1004.2162.2716.2194.1181.0424.0098.0013.0001.0135.0725.1757.2522.2377.1536.0689.0212.0043.0005.0057.0368.1088.1954.2367.2039.1281.0591.0199.0048.0008.0001.0016.0126.0476.1110.1792.2123.1906.1319.0710.0298.0096.0024.0004.0001.40.0101.0605.1612.2508.2508.1672.0743.0212.0035.0003.0060.0403.1209.2150.2508.2007.1115.0425.0106.0016.0001.0022.0174.0639.1419.2128.2270.1766.1009.0420.0125.0025.0003.0005.0047.0219.0634.1268.1859.2066.1771.1181.0612.0245.0074.0016.0003.45.
0046.0339.1110.2119.2600.2128.1160.0407.0083.0008.0025.0207.0763.1665.2384.2340.1596.0746.0229.0042.0003.0008.0075.0339.0923.1700.2225.2124.1489.0762.0277.0068.0010.0001.0001.0016.0090.0318.0780.1404.1914.2013.1647.1048.0515.0191.0052.0010.0001.50.0020.0176.0703.1641.2461.2461.1641.0703.0176.0020.0010.0098.0439.1172.2051.2461.2051.1172.0439.0098.0010.0002.0029.0161.0537.1208.1934.2256.1934.1208.0537.0161.0029.0002.0005.0032.0139.0417.0916.1527.1964.1964.1527.0916.0417.0139.0032.0005 728 Appendix D: Tables Table D.6 Binomial Probabilities (continued).01.8179.1652.0159.0010.02.6676.2725.0528.0065.0006.03.5438.3364.0988.0183.0024.0002.04.4420.3683.1458.0364.0065.0009.0001 p.05.3585.3774.1887.0596.0133.0022.0003.06.2901.3703.2246.0860.0233.0048.0008.0001.07.2342.3526.2521.1139.0364.0088.0017.0002.08.1887.3282.2711.1414.0523.0145.0032.0005.0001.09.1516.3000.2818.1672.0703.0222.0055.0011.0002 Table D.6 Binomial Probabilities (continued).
10.1216.2702.2852.1901.0898.0319.0089.0020.0004.0001.15.0388.1368.2293.2428.1821.1028.0454.0160.0046.0011.0002.20.0115.0576.1369.2054.2182.1746.1091.0545.0222.0074.0020.0005.0001.25.0032.0211.0669.1339.1897.2023.1686.1124.0609.0271.0099.0030.0008.0002 p.30.0008.0068.0278.0716.1304.1789.1916.1643.1144.0654.0308.0120.0039.0010.0002.35.0002.0020.0100.0323.0738.1272.1712.1844.1614.1158.0686.0336.0136.0045.0012.0003.40.45.50.0005.0031.0123.0350.0746.1244.1659.1797.1597.1171.0710.0355.0146.0049.0013.0003.0001.0008.0040.0139.0365.0746.1221.1623.1771.1593.1185.0727.0366.0150.0049.0013.0002.0002.0011.0046.0148.0370.0739.1201.1602.1762.1602.1201.0739.0370.0148.0046.0011.0002 n 20 n 20 10 11 12 13 14 15 16 17 18 19 20 10 11 12 13 14 15 16 17 18 19 20 Appendix E Answers to Odd­Numbered Exercises Answers are provided here to odd­numbered exercises that require a computation. No details of the computations are given. If the Exercise required that something be demonstrated, then a significant hint is provided. 5 6 (b) P 1 2 3 1 (c) P 1 P 2 3 1 2 [0 1] Ac B 1 12 P 3 3 8 P 3 0 9
(b) 0 1 25% 1 6 P 4 5 12 2 3 1 6 0 for any s 1.2.1 (a) P 1 2 1.2.3 P 2 1.2.5 P s 1.2.7 This is the subset A Bc 1 12 P 2 1.2.9 P 1 5 24 P 1 1.2.11 P 2 1.3.1 (a) P 2 3 4 100 1.3.3 P late or early or both 1.3.5 (a) 1 32 1.3.7 10% 1.4.1 (a) 1 6 8 1.4.3 1 1.4.5 (a) 4 1 1.4.7 48 10 1.4.9 5 6 2 1 6 12 5 3 3 5051 2100 39 13 13 13 13 13 52 10 25 216 18 6 3 3 246 595 1.4.11 0 03125. (b) 0 96875 1 1,679,616 (b) 1 6 7 52 13 13 13 13 (b) 4 0 4134 1 7 3 12 3 12 3 18 3 11 128 0 0859 3 2 1 23 1.4.13 2 4 1 22 2 1 1.5.1 (a) 3 4 (b) 16 21 1.5.3 (a) 1 8 (b) 1 8 1.5.5 1 1.5.7 0 074 1 24 2 1 1 22 3 0 1 23 4 3 1 24 1 2 1 4 (c) 0 1 2 0 729 1 279,936 (c) 8 1 6 8 1 209,952 4 4 48 9 39 13 13 13 52 13 13 13 13 730 Appendix E: Answers to Odd­Numbered Exercises y 0 0 S A 0 9 630 4 8 limn 1 2 3 0 for y 18 Z 3 P [0 n] 1 4 P X 0 (c) W 3 4 (c) Y 4 2 2 36 P Y 6 36 P Y s and Y s 84 Z 4 s2 for all s 260 Z 5 2 (b) W 2 1 (b) Y 2 P X 1.5.9 (a) No (b) Yes (c) Yes (d) Yes (e) No 1.5.11 (a) 0 1667 (b) 0 3125 1.6.1 1 3 1.6.3 An 1.6.
5 1 1.6.7 Suppose there is no n such that P [0 n] 1 P [0 1.6.9 No 2.1.1 (a) 1 (b) Does not exist (c) Does not exist (d) 1 2.1.3 (a) X s S. 2 Z 2 2.1.5 Yes, for A B. 2.1.7 (a) W 1 2.1.9 (a) Y 1 2.2.1 P X x 0 1 2 2.2.3 (a) P Y 1 36 P Y 5 36 P Y 3 36 P Y 2 36 IB 3 4 36 IB 9 2.2.5 (a) P X for all x P Y y P W 4 other choices of 25 2.2.7 P X 2.3.1 pY 2 1 36 pY 3 pY 7 pY 12 2.3.3 pZ 1 2.3.5 pW 1 2 36 pW 6 4 36 pW 15 2 36 pW 25 otherwise 2.3.7 2.3.9 53 512 2.3.11 10 2.3.15 (a) 10 3 3 7 11 3 36 IB 4 3 36 IB 10 1 1 36 pW 2 4 36 pW 8 2 36 pW 16 1 36 pW 30 6 36 pY 8 1 36 and pY y pZ 5 0 3 P Y 1 2 3 (c) P W 0 2 P W 6 2 36 pW 3 2 36 pW 9 1 36 pW 18 1 2 3 (b) P Y 0 for all y 30 2 36 pY 4 12 4 36 IB 5 0 34 P W 5 4 36 pY 10 2 36 IB 11 5 36 pY 9 0 otherwise 1 4 pZ 0 2 36 P Y 0 45 35 3 0 65 7 (b) 0 35 0 65 9 (c) 9 1 2 and pZ z 11 12 1 2 0 9 and then note this implies (b) For this example, Z 1 1 (d) W Z is not true. 1 1 2 P X x 0 for 3 36 P Y 5 36 10 11 12, P Y 4 36 P Y 4 36 P Y B 6 36 IB 7 5 9 1 36 (b) P Y 2 6 10 1 36 IB 2 5 36 IB 8 5 36 IB 6 1 36 IB 12 3 0 5 and P X 0 2 P Y 0 09 P W