Question: ** R CODE ** It is very common to run simulation studies to estimate probabilities that are difficult to work out. In this exercise we
** R CODE **
It is very common to run simulation studies to estimate probabilities that are difficult to work out. In this exercise we will investigate a gambling question that sparked much of the fundamental mathematics behind the study of [probability](http://homepages.wmich.edu/~mackey/Teaching/145/probHist.html). The game is to roll a pair of 6-sided dice 24 times. If a "double-sixes" comes up on any of the 24 rolls, the player wins. What is the probability of winning? a) We can simulate rolling two 6-sided dice using the `sample()` function with the `replace=TRUE` option. Read the help file on `sample()` to see how to sample from the numbers $1,2,\dots,6$. Sum those two die rolls and save it as `throw`. b) Write a `for{}` loop that wraps your code from part (a) and then tests if any of the throws of dice summed to 12. Read the help files for the functions `any()` and `all()`. Your code should look something like the following: ```{r, eval=FALSE} throws <- NULL for( i in 1:24 ){ throws[i] <- ?????? # Your part (a) answer goes here } game <- any( throws == 12 ) # Gives a TRUE/FALSE value ``` c) Wrap all of your code from part (b) in *another* `for(){}` loop that you run 10,000 times. Save the result of each game in a `games` vector that will have 10,000 elements that are either TRUE/FALSE depending on the outcome of that game. You'll need initiallize the `games` vector to NULL and modify your part (b) code to save the result into some location in the vector `games`. d) Finally, calculate win percentage by taking the average of the `games` vector.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
