Chapter 5 : Project Question 5 ( page 201 )

Roulette - In American roulette, there are 38 spaces on the wheel: 0, 00, and 1-36.

  • Half the spaces numbered 1-36 are red
  • and half are black.
  • The two spaces 0 and 00 are green.

Simulate the playing of 1000 games betting either red or black (which pay even money, 1:1). - Bet $1 on each game and keep track of your earnings. - What are the earnings per game betting red/black according to your simulation? - What was your longest winning streak? Your - Longest losing streak? Simulate 1000 games betting green (pays 17:1, so if you win, you add $17 to your kitty, and if you lose, you lose $1).

  • What are your earnings per game betting green according to your simulation?
  • How does it differ from your earnings betting red/black?
  • What was your longest winning streak betting green ?
  • Longest losing streak?
  • Which strategy do you recommend using, and why?

Problem 1

Step 1: Writing probabilities

  • We have 18 red, 18 black and 2 greens. So total is 38.
probabilities <- c(18/38,18/38,2/38)
  • Printing total of probabilities which should be one.
(sum(probabilities))
## [1] 1

Step 2: Function for simulation

raceSamples <- function(noOfSamples) 
{

  sample(x = c("black","red","green"), 
                noOfSamples, 
                replace = T, 
                prob = probabilities)
}

#nrow   the desired number of rows.
samples<-raceSamples(1000)
#df <- data.frame(matrix(unlist(samples), nrow=4, byrow=T))
#Converting to dataframe
df <- data.frame(matrix(unlist(samples), byrow=T),stringsAsFactors=FALSE)
#renaming column name
names(df)[1] <- "color"
#getting sequence of continuation (to get longest winning streak)
df$count<-sequence(rle(as.character(samples))$lengths)

Step 3: Earning from black

#Assuming we did bet on black, so getting blackEarning from black
black<-subset(df, color=='black')
#max means total how many times there was black
blackColorWining<-length(black$count)

#getting lost count
red<-subset(df, color=='red' )
redColorWinning<-length(red$count)
green<-subset(df, color=='green' )
greenColorWinning<-length(green$count)

lost_timesBlack<-redColorWinning + greenColorWinning
lost_timesRed<-blackColorWining + greenColorWinning
lost_timesGreen<-blackColorWining + redColorWinning

blackColorWining
## [1] 444
redColorWinning
## [1] 501
greenColorWinning
## [1] 55
blackEarning<-blackColorWining -(lost_timesBlack)
blackEarning
## [1] -112
redEarning<-redColorWinning -(lost_timesRed)
redEarning
## [1] 2
greenColorEarning<-(greenColorWinning*17) - lost_timesGreen
greenColorEarning
## [1] -10

Step 4: Longest winning streak?

max(subset(df, color=='black')$count)
## [1] 9

Step 5: Longest losing streak?

#getting sequence of continuation (to get longest winning streak)
df$count<-sequence(rle(as.character(samples))$lengths)
df$color[df$color=='red'|df$color=='green']<-"lost"
max(subset(df, color=='lost')$count)
## [1] 21

Problem 2

Chapter 9 : Project Question 4 ( page 376 )

The NBC TV network earns an average of $400,000 from a hit showand loses an average of $100,000 on a flop (a show that cannot hold its rating and must be canceled). If the network airs a show without a market review, 25% turn out to be hits, and 75% are flop.

For $40,000, a market research firm can be hired to help determine whether the show will be a hit or a flop.

If the show is actually going to be a hit, there is a 90% chance that the market research firm will predict a hit.

If the show is going to be a flop, there is an 80% chance that the market research will predict the show to be a flop.

Determine how the network can maximize its profits over the long haul.

This is Conditional Probabilities problem.

There are four outcomes. Two with research and Two without research (Decision Trees)

  1. Air show a hit with research

  2. Air show a flop with research

  3. Air show a hit without research

  4. Air show a flop without research

With the market research firm …

NBC TV network will pay $40,000 to the market research firm.

Expected Value if the show is hit is 0.25 * 0.9 * 400,000 + 0.75 * 0.2 * 400,000 = $150,000

Expected Value if the show is Flop 0.25 * 0.1 * 100000 + 0.75 * 0.8 * 100000 = $62,500

So the total profit is 150000 - 62500 - 40,000 = $47,500

Without the market research firm

Expected Value if the show is hit is 0.25 * 400,000 = $100,000

Expected Value if the show is Flop 0.75 * 100000 = $75,000

So the total profit is 100000- 75000 = $25,000

Based on the above results : We would recommend NBC TV network to hire a market research firm before airing a show.