Question: This is a R Studio question. # Flip a coin three times, heads is 1, tails is zero flips = sample(x = C(O. 1), size

This is a R Studio question.

This is a R Studio question. # Flip a coin three times,

# Flip a coin three times, heads is 1, tails is zero flips = sample(x = C(O. 1), size = 3, replace = T) # Calculate the number of times it landed heads sum_flips = sum(flips) # If it landed on heads more than zero times execute the code in brackets if (sum_flips > 0) { # Roll die sum_flips times rolls sample(1:6, size = sum_flips, replace # Add up the different rolls sum_rolls = sum(rolls) } else { # If it didn't land on heads, let sum_flips be zero sum_rolls = 0 } # Store sum_flips and sum_rolls in a data set sim_results data.frame(sum_flips, sum_rolls) T) Modify the code using a for-loop to simulate that process 100,000 times. (a) Use the results to approximate the answers to question 4. In other words, using the results of your simulation, nd an approximation of the following probabilities if the sum of the rolls of the dice add up to four. i. Probability that the coin landed on heads once ii. Probability that the coin landed on heads twice iii. Probability that the coin landed on heads three times iv. Expected value of the number of times the coin landed on heads. (1)) Now approximate the same values if the rolls of the dice added up to twelve instead of four

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!