Robert_V._Hogg,_Joseph_W._McKean,_Allen_T._Craig

(Jacob Rumans) #1
1.8. Expectation of a Random Variable 65

1.8.1 R Computation for an Estimation of the Expected Gain

In the following example, we use an R function to estimate the expected gain in a
simple game.

Example 1.8.9.Consider the following game. A player paysp 0 to play. He then
rolls a fair 6-sided die with the numbers 1 through 6 on it. If the upface is a 1 or a
2, then the game is over. Otherwise, he flips a fair coin. If the coin toss results in a
tail, he receives $1 and the game is over. If, on the other hand, the coin toss results
in a head, he draws 2 cards without replacement from a standard deck of 52 cards.
If none of the cards is an ace, he receives $2, while he receives $10 or $50 if gets 1
or 2 aces, respectively. In both cases, the game is over. LetGdenote the player’s
gain. To determine the expected gain, we need the distribution ofG. The support
ofGis the set{−p 0 , 1 −p 0 , 2 −p 0 , 10 −p 0 , 50 −p 0 }. For the associated probabilities
we need the distribution ofX,whereXis the number of aces in a draw of 2 cards
from a standard deck of 52 cards without replacement. This is another example of
the hypergeometric distribution discussed in Example 1.6.2. For our situation, the
distribution is


P(X=x)=

( 4
x

)( 48
2 −x

)
( 52
2

) ,x=0, 1 , 2.

Using this formula, the probabilities ofX,to4places,are0. 8507 , 0. 1448 ,and 0.0045
forxequal to 0, 1, and 2, respectively. Using these probabilities and independence,
the distribution and expected value ofGcan be determined; see Exercise 1.8.13.
Suppose, however, a person does not have this expertise. Such a person would
observe the game a number of times and then use the average of the observed gains
as his/her estimate ofE(G). We will show in Chapter 2 that this estimate, in
a probability sense, is close toE(G), as the number of times the game is played
increases. To compute this estimation, we use the following R function,simplegame,
which plays the game and returns the gain. This function can be downloaded at the
site given in the Preface. The argument of the function is the amount the player
pays to play. Also, the third line of the function computes the distribution of the
above random variableX. To draw from a discrete distribution, the code makes
use of the R functionsamplewhich was discussed previously in Example 1.4.12.


simplegame <- function(amtpaid){
gain <- -amtpaid
x <- 0:2; pace <- (choose(4,x)*choose(48,2-x))/choose(52,2)
x <- sample(1:6,1,prob=rep(1/6,6))
if(x > 2){
y <- sample(0:1,1,prob=rep(1/2,2))
if(y==0){
gain <- gain + 1
} else {
z <- sample(0:2,1,prob=pace)
if(z==0){gain <- gain + 2}
if(z==1){gain <- gain + 10}
if(z==2){gain <- gain + 50}

Free download pdf