5 August 2016
Question 1
x<-1 #choice of door (change this)
doors<-sample(c("pig","pig","car"), 3)
ppc_sample <- function(x){
door<-sample(c("pig","pig","car"), 3)
door[x]
}
count <- 0
for(i in 1:20) {
door <- ppc_sample(x)
if(door =="car") {
count <- count +1
}
}
proportion<-count*100/20
paste("Given we chose door ", x, ", the car is selected ", count, " times out
of 20; or ", proportion,"% of the time.", sep="")
## [1] "Given we chose door 1, the car is selected 4 times out of 20; or 20%
of the time."
On average, we expect the car to be selected 6-7 times every 20 runs; or one third of the
time.
Question 2
x<-1 #choice of door (change this)
if(you=="car") {
number <- sample(other,1)
host <- door[number]
paste("The host reveals a", host, "behind door", number, sep =" ")
} else {
if(door[other[1]]=="pig") {
number <- other[1]
host <- door[number]
paste("The host reveals a", host, "behind door", number, sep =" ")
} else {
number <- other[2]
host <- door[number]
paste("The host reveals a", host, "behind door", number, sep =" ")
}
}
}
ppc_host(x)
Question 3
x<-1 #choose between door 1, 2 or 3.
strategy<-"stay" #choose between "stay" or "switch".
if(you=="car") {
number <- sample(other,1)
host <- door[number]
#paste("The host reveals a", host, "behind door", number, sep =" ")
} else {
if(door[other[1]]=="pig") {
number <- other[1]
host <- door[number]
#paste("The host reveals a", host, "behind door", number, sep =" ")
} else {
number <- other[2]
host <- door[number]
#paste("The host reveals a", host, "behind door", number, sep =" ")
}
}
if(strategy =="stay"){
#reveal original door
paste("There is a", door[x],"behind door", x, sep=" ")
} else {
#reveal third door
n <- (1:3)[-c(x, number)]
paste("There is a", door[n] ,"behind door", n, sep=" ")
}
}
ppc_final(x,strategy)
Question 4
monty<-function(strat='stay',N=1000,print_games=TRUE)
{
doors<-1:3 #initialize the doors behind one of which is a good prize
win<-0 #to keep track of number of wins
for(i in 1:N)
{
prize<-sample(1:3, 1) #randomize which door has the good prize
guess<-sample(1:3, 1) #guess a door at random
## Reveal one of the doors you didn't pick which has a bum prize
if(prize!=guess)
reveal<-doors[-c(prize,guess)]
else
reveal<-sample(doors[-c(prize,guess)],1)
if(print_games)
cat(paste('Guess: ',guess,
'\nRevealed: ',reveal,
'\nSelection: ',select,
'\nPrize door: ',prize,
'\n',outcome,'\n\n',sep=''))
}
cat(paste('Using the ',strat,' strategy, your win percentage was ',win/N*100
,'%\n',sep='')) #Print the win percentage of your strategy
}
If we choose to stay:
monty('stay',N=100,print_games=FALSE)
If we choose to switch:
monty('switch',N=100,print_games=FALSE)
Question 5
The Monty Hall problem and Deal or No Deal are quite different in a number of key aspects.
Firstly let's assume that the contestant in Deal or No Deal is only interested in winning the
highest value prize to allow for a better comparison with Monty Hall. Obviously in reality,
someone would be quite happy with any of the high value prizes. Also in Monty Hall, the
host knows where the car is and can subsequently reveal the other door with the pig. But
this does not happen with Deal or no Deal: there is the chance that the desired prize is
eliminated before the contestant even reaches the final two cases. Finally, there is
technically no way to switch cases in Deal or No Deal, however we can say that taking the
deal offered by the banker is effectively "switching" cases.
With that in mind, "switching" cases in Deal or No Deal does not provide an advantage to
the contestant as in Monty Hall. The key reason being is that the host does not have any
knowledge of where the highest prize is. As such in the Deal or No Deal scenario, there is
only a 50-50 chance of picking the highest prize.