Analytics Check

Expectations and variances of dice rolls


Often when rolling a dice, we know what we want — a high roll to defeat the monster or win a wager — unfortunately for us, desire has little impact on the outcome of the roll. In these situations, it’s useful to know what to expect and how variable the outcome will be around that expectation.

In this post, we define expectation and variance mathematically, compute them for dice rolls, and explore some key properties that help us understand the potential outcomes.

Some definitions

Just by their names, we get a decent idea of what these concepts tell us. Expectation (also known as expected value or mean) gives us a single value that summarizes the average outcome, often representing some measure of the center of a probability distribution. Variance quantifies how variable the outcomes are about the average. A low variance implies that most of the outcomes are clustered near the expected value whereas a high variance implies the outcomes are spread out.

We represent the expectation of a discrete random variable XX as E(X)E(X) and variance as Var(X)\mathrm{Var}(X). They can be defined as follows:

E(X)=k=1nkP(X=k)Var(X)=E(X2)E(X)2E(X) = \sum_{k=1}^n k P(X=k) \qquad \mathrm{Var}(X) = E(X^2) - E(X)^2

Expectation is a sum of outcomes weighted by their probability. The variance is itself defined in terms of expectations. As we primarily care dice rolls here, the sum only goes over the nn finite outcomes representing the nn faces of the dice (it can be defined more generally as summing over infinite outcomes for other probability distributions).

One important thing to note about variance is that it depends on the squared expectation and the expectation of X2X^2. While we could calculate the probability distribution of X2X^2 and compute the expectation directly, it is much easier to use the law of the unconscious statistician:

E(g(X))=k=1ng(k)P(X=k)E(g(X)) = \sum_{k=1}^n g(k) P(X=k)

This allows us to compute the expectation of a function of a random variable, g(X)g(X), with the original probability distribution and applying the function, gg, to the outcomes, kk, in the sum.

Applying these to dice rolls

All we need to calculate these for simple dice rolls is the probability mass function, which we explored in our post on the dice roll distribution:

XDice(n)P(X=x)={1nx{1,,n}0otherwiseX \sim \textrm{Dice}(n) \qquad P(X=x) = \begin{cases} \frac{1}{n} & x\in\{1,\cdots,n\} \\ 0 & \mathrm{otherwise} \end{cases}

The direct calculation is straightforward from here:

E(X)=k=1nkn=1nk=1nk=n(n+1)2n\begin{aligned} E(X) &= \sum_{k=1}^n \frac{k}{n} \\ &= \frac{1}{n} \sum_{k=1}^n k \\ &= \frac{n(n+1)}{2n} \end{aligned}

Yielding the simplified expression for the expectation:

E(X)=n+12\boxed{ E(X) = \frac{n+1}{2} }

The expected value of a dice roll is half of the number of faces plus 1/21/2. Let’s take a look at the variance — we first calculate E(X2)E(X^2):

E(X2)=1nk=1nk2=1nn(n+1)(2n+1)6=(n+1)(2n+1)6\begin{aligned} E(X^2) &= \frac{1}{n} \sum_{k=1}^n k^2 \\ &= \frac{1}{n}\frac{n(n+1)(2n+1)}{6}\\ &= \frac{(n+1)(2n+1)}{6} \end{aligned}

Substituting this result and the square of our expectation into the definition for variance we get:

Var(X)=(n+1)(2n+1)6(n+12)2\mathrm{Var}(X) = \frac{(n+1)(2n+1)}{6} - \left(\frac{n+1}{2}\right)^2

Simplifying this expression yields:

Var(X)=n2112\boxed{ \mathrm{Var}(X) = \frac{n^2 - 1}{12} }

What does this tell us about dice rolls?

This is the part where I tell you that expectations and variances are mostly useless summaries of single dice rolls. The fact that every face is equiprobable in a single roll is all the information you need to understand the behavior of one dice.

On the other hand, expectations and variances are extremely useful when rolling multiple dice. At the end of our post on simple dice roll probabilities, we showed that when you sum multiple dice rolls, the distribution concentrates about the center of possible outcomes — in fact, it concentrates exactly around the expectation of the sum. We see this for two d6s here:

As we add more dice, the distributions concentrates to the expected value as it approaches a normal distribution.

Since our multiple dice rolls are independent of each other, calculating the expectation and variance can be done using the following true statements (the statement on expectations is always true, the statement on variance is true only if the random variables are uncorrelated):

E(i=1mXi)=i=1mE(Xi)E\left(\sum_{i=1}^m X_i\right) = \sum_{i=1}^m E(X_i)
Var(i=1mXi)=i=1mVar(Xi)\mathrm{Var}\left(\sum_{i=1}^m X_i\right) = \sum_{i=1}^m \mathrm{Var}(X_i)

The expectation and variance of a sum of mm dice is the sum of their respective expectations and variances. If we plug in what we derived above, we get expressions for the expectation and variance of a sum of mm identical dice:

E(i=1mXi)=m(n+1)2E\left(\sum_{i=1}^m X_i\right) = \frac{m(n+1)}{2}
Var(i=1mXi)=m(n21)12\mathrm{Var}\left(\sum_{i=1}^m X_i\right) = \frac{m(n^2 - 1)}{12}

A quick check using m=2m=2 and n=6n=6 gives an expected value of 77, which matches up exactly with the peak in the above graph.

Both expectation and variance grow with linearly with the number of dice. As we said before, variance is a measure of the spread of a distribution, but we can also look at the standard deviation for a more interpretable way of quantifying spread — it is defined as the square root of the variance:

σX=Var(X)\sigma_X = \sqrt{\mathrm{Var}(X)}

σX\sigma_X is considered more interpretable because it has the same units as the expected value, whereas variance is measured in terms of squared units (a consequence of all those powers of two in the definition.) On the other hand, standard deviation allows us to use quantities like E(X)±σXE(X) \pm \sigma_X to directly summarize the spread of outcomes.

The important conclusion from this is: when measuring with the same units, expectation grows faster than the spread of the distribution, as:

E( ⁣X)mσXmE(\textstyle\sum\! X) \propto m \qquad \sigma_X \propto \sqrt{m}

The range of possible outcomes also grows linearly with mm, so as you roll more and more dice, the likely outcomes are more concentrated about the expected value relative to the range of all possible outcomes. This can be seen intuitively by recognizing that if you are rolling 10 6-sided dice, it is unlikely that you would get all 1s or all 6s, and more likely to get a mixture of values which have a tendency to average out near the expected value.

While we have not discussed exact probabilities or just how many of the possible outcomes lie close to the expectation, the main takeaway is the same — when rolling multiple dice, the expected value gives a good estimate for about where you should expect the outcome to be. The more dice you roll, the more confident you should be that the sum will be close to the expectation.

All rights reserved.