Question: USING R STUDIO In this week's assignment, you will use simulation to estimate the probability of rolling two fair dice with the first die landing

USING R STUDIO

In this week's assignment, you will use simulation to estimate the probability of rolling two

fair dice with the first die landing on 1 and the second landing on 2. The true probability of

this event is:

1/6 * 1/6 = 1/36

To estimate this probability, you will need to simulate the process of rolling two dice. You

can use the following code to do:

# roll the first die

roll1 <- sample(x=c(1,2,3,4,5,6), size=1)

# roll the second die

roll2 <- sample(x=c(1,2,3,4,5,6), size=1)

We will "roll" the dice many times (using a for-loop), and "count" how many times the first

die "landed" on 1 and the second die "landed" on 2. If we divide this number by the total

number of "rolls", this will be an estimate of the probability of interest.

1. First, let's write logical statement to check if BOTH roll1 is exactly equal to 1 AND

roll2 is exactly equal to 2 (at the same).

a. "Roll" the dice once. You should be able to see which numbers you "rolled" by

printing the variable contents. This will be helpful when you are forming

your logic statements in parts b., c., and d. (It gives you a way to check if the

logic statements are producing the right result!)

b. Write logic statement (R code) to check if roll1 is exactly equal to 1.

c. Write logic statement (R code) to check if roll2 is exactly equal to 2.

d. Combine these statements to check if both are TRUE at the same time.

2. Use a for-loop with a total of 1000 iterations to estimate the probability. You should

be able to re-purpose the for-loop code from the lecture video.

a. Make sure to initialize a storage vector outside of the loop.

b. Inside the loop you should "roll" the two dice (use the code I provided

above).

c. Now, use your logical statement from 1. d) to check if the first die "landed" on

1 AND the second die "landed" on 2. You will need to keep track (and store) if

this is true or false at each iteration of the loop.

d. Calculate the estimated probability and report it in your homework report.

Submit your homework file (PDF or Word document) and R script to the 'Week 6

homework' dropbox folder.

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!