Question

Please help me write these in R script / Code 1, Suppose you're on a game...

Please help me write these in R script / Code

1, Suppose you're on a game show, and you're given the choice of three doors. Behind one door is a car; behind the others, goats. You pick a door, say #1, and the host, who knows what's behind the doors, opens another door, say #3, which has a goat. He then says to you, "Do you want to pick door #2?" What is the probability of winning the car if you use the strategy of first picking a random door and then switching doors every time? Note that the host will always open a door you did not pick, and it always reveals a goat.

2, A famous coin tossing game has the following rules: The player tosses a coin repeatedly until a tail appears or tosses it a maximum of 1000 times if no tail appears. The initial stake starts at 2 dollars and is doubled every time heads appears. The first time tails appears, the game ends and the player wins whatever is in the pot. Thus the player wins 2 dollars if tails appears on the first toss, 4 dollars if heads appears on the first toss and tails on the second, 8 dollars if heads appears on the first two tosses and tails on the third, and so on. Mathematically, the player wins 2k dollars, where k equals the number of tosses until the first tail. What is the probability of profit if it costs 15 dollars to participate?

3, In a random thirteen-card hand from a standard deck, what is the probability that none of the cards is an ace and none is a hear

4, In six coin tosses, what is the probability of having a different side come up with each throw, that is, that you never get two tails or two heads in a row

5, A random five-card poker hand is dealt from a standard deck. What is the chance of a flush (all cards are the same suit)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1: R script will be :

# Load the package ggplot2, if it is not already loaded
library( ggplot2 )
library( dplyr )

Game_show <- function(n=1000, switch=TRUE) {

# Initialize the win vector, where we'll store wins
win <- rep(NA, n)

# Define the possible prizes and 'bad prizes' resulting in a loss
prizes <- c("Car", "Goat1", "Goat2")
badprizes <- c("Goat1", "Goat2")

for (i in 1:n) {
  
# Player picks a door randomly
x <- sample(1:3, 1)
# Randomly assign each one of the prizes to a 'door'
doorsetup <- sample(prizes,3)
if(switch) {
if(doorsetup[x]=="Car") {
reveal <- sample(badprizes,1)   
revealpos <- which(doorsetup==reveal)   
} else if (doorsetup[x]=="Goat1") {
revealpos <- which(doorsetup=="Goat2")
} else if (doorsetup[x]=="Goat2") {
revealpos <- which(doorsetup=="Goat1") }
y <- doorsetup[-c(x, revealpos)]
} else if (!switch) {
y <- doorsetup[x]
}

# Determine whether player won based on the value of y
if (y=="Car") {
win[i] <- 1
} else {win[i] <- 0}
}

n_wins <- sum( win )
n_losses <- n - sum( win )


# Print & graph the results of simulation
data <- data.frame(result = c("loss","win"),
count = c( n_losses, n_wins ),
relativefrequency = c( n_losses/n, n_wins/n ),
stringsAsFactors = FALSE )
plot <- ggplot(data, aes(x=result, y=relativefrequency)) +
geom_bar(stat = "identity")
  
list( data = data,
plot = plot )
}

Using the Game_show function to simulate playing the Game_show game 100 times

### Using the function

set.seed(123)

# Strategy: You always stick with your original door choice

Game_show(n=100, switch=FALSE)

# Strategy: You always switch doors when given the chance to switch

Game_show(n=100, switch=TRUE)

Answer 2: R script will be:

Add a comment
Know the answer?
Add Answer to:
Please help me write these in R script / Code 1, Suppose you're on a game...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Game: Suppose you're on a game show, and you're given the choice of 3 doors....

    The Game: Suppose you're on a game show, and you're given the choice of 3 doors. Behind one door is a car, behind the others, goats. You start by choosing a door, say number 1, which remains closed for now. The game show host, who knows what's behind the doors, opens another door, say number 3, which reveals a goat. He says to you, "You've already chosen door number 1, now that I've shown you a goat behind door number...

  • Monty Hall Problem - Suppose you are going to be on a game show, and you...

    Monty Hall Problem - Suppose you are going to be on a game show, and you will be given the choice of three doors: Behind one door is a car; behind the other two doors are goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your...

  • tails up? 42. Juan draws a black card from an ordinary deck as the first card...

    tails up? 42. Juan draws a black card from an ordinary deck as the first card for a game of Gin Rummy. What is the probability the card was a king? What's the probability that the next black card is also a king given that the first one was? 43. At a carnival gambling booth, two dice are rolled, and a sum of 7 wins double your money. Find the probability that the sum is 7 given that one of...

  • This is discrete mathematics If you do it right, I must give praise. You must use probability spa...

    This is discrete mathematics If you do it right, I must give praise. You must use probability space is a triple relative acknowledge. S: is a sample sapce E=p(s) is the set of all events P: E-->R is a function. The important thing that I need to say three times:   If you don't know how to do it, please don't do it. don't copy others, especially for question (a), give sample space, probability measure The important thing that I need...

  • Question 1: Consider the following Monty Hall problem. Suppose you are on a game show, and...

    Question 1: Consider the following Monty Hall problem. Suppose you are on a game show, and you are given the choice of three doors. Behind one door is a car, behind the others, goats. You pick a door, say #1, and the host, who knows what is behind the doors, opens another door, say #3, which has a goat. Here we assume that the host cannot open the door to expose the car and when he can open either of...

  • Geometric Random Variables Part 1 A fair coin is flipped repeatedly until tails shows. What is...

    Geometric Random Variables Part 1 A fair coin is flipped repeatedly until tails shows. What is the probability of the game stopping on exactly the 5 th flip? What is the probability of the game stopping on one of the first 5 flips? Part 2 Cards are drawn with replacement from a standard shuffled deck repeatedly until a black 10 appears. What is the probability of the game stopping on exactly the 15th card? What is the probability of the...

  • Geometric Random Variables Part 1 A fair coin is flipped repeatedly until tails shows. What is...

    Geometric Random Variables Part 1 A fair coin is flipped repeatedly until tails shows. What is the probability of the game stopping on exactly the 5 th flip? What is the probability of the game stopping on one of the first 5 flips? Part 2 Cards are drawn with replacement from a standard shuffled deck repeatedly until a black 10 appears. What is the probability of the game stopping on exactly the 15th card? What is the probability of the...

  • 1.3 Cars and goats: the Monty Hall dilemma On Sunday September 9, 1990, the following question...

    1.3 Cars and goats: the Monty Hall dilemma On Sunday September 9, 1990, the following question appeared in the "Ask Marilyn" column in Parade, a Sunday supplement to many newspapers across the United States: Suppose you're on a game show, and you're given the choice of three doors; behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3,...

  • Can someone help me with this HW problem. It's a C# assignment. Two-Up (10 points) Two-up is an old gambling game u...

    Can someone help me with this HW problem. It's a C# assignment. Two-Up (10 points) Two-up is an old gambling game using two coins. Before the coins are tossed, the player would guess whether the toss would result in two heads (obverse), two tails (reverse) or one head and one tail (ewan). The "spinner" would spin (or toss) the two coins and the player would see if they won their bet. Write an application for the game Two-up with the...

  • i need a help pleassssse? 5. What is the probability that the sum of the numbers...

    i need a help pleassssse? 5. What is the probability that the sum of the numbers on two dice is even when they are rolled? 6. What is the probability that a card selected at random from a standard deck of 52 cards is an ace or a heart? What is the probability that a positive integer not exceed- 100 selected at random is divisible by 5 or 7? nd the probability of winning a lottery by selecting the t...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT