When you were in high school, you probably studied basic statistics using virtual experiments like flipping a coin, rolling dice, or selecting a certain number of cards. When you start your career in data analysis, you will frequently encounter various situations where you might need to recall those experiments to help you learn various statistical topics, such as probability distributions, moments, the law of large numbers, and so on. If you are an R user, you can benefit from the tidydice library, which presents automated results of rolling a die and flipping a coin.
In this guide, you will learn to perform these simulations and plot their binomial distribution.
Download and install the tidydice library with the following command:
1install.packages("tidydice")
If your internet proxy doesn't interfere in downloading the package and you have system permission to save the package in your drive, you should receive the following success message along with other information:
package ‘tidydice’ successfully unpacked and MD5 sums checked
Next, load the package in your current R environment using the given code:
1library(tidydice)
Note: You can also install and load the tidyverse package, which goes hand in hand with the tidydice package.
You can plot the binomial distribution of your experiment using the command plot_binom
.
Binomial distribution of flipping a coin 100 times:
1binom_coin(times = 100) %>% plot_binom()
Binomial distribution of rolling a die 50 times:
1binom_dice(times = 50) %>% plot_binom()
In this guide, you learned how to create automated simulations related to flipping a coin and rolling a die (including creating a plot). You can use these simulations with other statistical packages in R or to revise your statistical concepts.