Simulating dice throws in R

I am currently following a course on probability theory in coursera (https://www.coursera.org/course/probas) and I’ve seen some graphs concerning the outcome of some dice throws. Being an R-nerd I wrote a little function to do this in R. This is nothing fancy just I find it interesting the process of thoughts going from a real-world problem (100 throws of two dice) to some code and graphs (histogramms of the empirical and theoretical results of the sum of the two dice).

Here is the problem: We throw two six-faced fair dice a certain number of times and we compute the sum of their values, we want to compare the theoretical expectations with empirical ones as we are varying the number of times dice are thrown.

The code can be found here: http://rpubs.com/Lionel/11497

And just as a teaser here is one of the figure we can get from it

dice

2 thoughts on “Simulating dice throws in R

  1. Does anybody know how I can compute the number of times I have to roll a fair dice before I get 4?

    I was wondering whether I could do it by using while loop

    1. This would indeed be a nice little exercise to create such a loop (while would be appropriate), I would argue to pack this up in a function so that you could use replicate this many times to get a distribution of the number of dice roll until you get a certain outcome.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s