Download PDF
Download page Dice Experiment in R.
Dice Experiment in R
Download file for R Shiny application here:
dice_roll.R
Note: An Excel-based version of this workshop is available here: Part 1. Dice Experiment
Launch the Application
- Launch R Studio and open the provided .R file
- Along the top bar, press the green play button to run the R Shiny app. You may need to install packages if they are not already installed.

- There are two tabs you will navigate between in this workshop: Single Experiment and Multiple Experiment

- General tips
- Feel free to resize the window as needed to see all the content
- The input bar (on the left) can be expanded and hidden by clicking the > and < symbol at the top
- Plots can be expanded to full-size by clicking the arrows icon in the bottom-right corner of each plot
- This workshop uses a random number generator, which means each time you click "Roll", a new random sample will be drawn
Rolling a (Virtual) 6-Sided Die - Single Experiment
Navigate to the Single Experiment tab.
On this tab, you can simulate rolling a die an N number of times and counting the outcomes for each roll (1, 2, 3, 4, 5, or 6).
12 rolls. The goal is to take a 6-sided die, and attempt to determine the probability of rolling a 4. Do this by computing the relative frequency of rolling a 4 after 12 rolls. Relative frequency = (# times roll 4) / (# rolls). Enter "12" as the number of rolls and click "Roll". The roll outcomes will be tabulated as well as plotted in the histogram. The histogram (estimated PMF) of the sample shows both count and relative frequency of each possible outcome (1 through 6).. The true (expected) probability is shown in a dashed red horizontal line. Note that each time you hit "Roll", producing a new experiment of 12 rolls, the counts and plotted histograms all change.
Question 1: How many times did you roll a 4, and so what is your estimated probability of rolling a 4? How many times did you expect to roll a 4?
Question 2: Do you think 12 is enough rolls to determine the probability of rolling a 4?
No, it’s unlikely to see exactly 2 rolls of each side in 12 rolls, due to sampling error. So, the probability estimate will probably not be correct. Test increasing the N number of rolls to see the effect on the estimated probabilities.
Rolling a (Virtual) 6-Sided Die - Multiple Experiment
Navigate to the Multiple Experiment tab.
On this tab, you can simulate rolling a die N number of times, and repeating that experiment an n number of times to estimate the probability of rolling a 4. The estimated probability (calculated from each experiment, n) is tabulated as well as plotted. The true (expected) probability is shown in a dashed red horizontal line.
12 rolls | 20 experiments. Enter 12 as the number of rolls (N) and 20 as the number of experiments (n). The estimated probability of rolling a 4 will be recorded in the table (one row for each experiment outcome). Study the plot for the 20 trials, which plots those estimates, along with the true probability of 1/6 (shown in a dashed red horizontal line).
Question 3: How do we know the true value is 1/6 for this experiment?
A dice roll produces equally likely values between 1 and 6.
Question 4: Does the experiment do a good job of estimating the probability of rolling a 4 on a 6-sided die?
No, the estimate rarely gave the answer we know to be correct.
100 rolls | 20 experiments. Enter 100 as the number of rolls (N). Keep the number of experiments at 20. Run the experiments by clicking "Roll".
Question 5: What is different between this simulation and the previous simulation?
In each of the 20 experiments, we are rolling a die 100 times instead of 12 times to estimate the number of times a 4 was rolled.
Hit "Roll" a few times to study the resulting plot of each trial of the experiment.
Question 6: How do the results of the 100-roll experiment differ from the 12-roll experiment?
The estimates of the probability of rolling a 4 are all closer to the actual value.
12 rolls:
100 rolls:
1,000 and 10,000 rolls | 20 experiments. Try re-running the experiments by increasing the number of rolls (N) to 1,000 and 10,000. Study those results to build your understanding of the relationship between sample size and accuracy of the probability estimate. Feel free to continue experimenting with different number of rolls and number of experiments.
Question 7: Do the 1,000-trial experiment and the 10,000-trial experiment support your answer to the last question?
If your answer to the last question was that 100 rolls did better than 12, then yes. These experiments of 1,000 and 10,000 rolls support that fact that a larger sample will be more representative of the true population and probability distribution, and so give better estimates of the probabilities.