In a previous post, I discussed Wolfram|Alpha’s facility with probability distributions, such as the distribution of probability among the possible totals that can be shown with a pair of fair dice:
If you rolled the dice many times, what would be your average roll? To compute this you would take the grand total of all your rolls and divide by the number of rolls, but we can get a good idea of what to expect using the distribution.
The heights of the bars above represent the approximate fraction of times you would observe each roll. So you would roll a total of 2 roughly 3% of the time, and the amount of the grand total contributed by the times you rolled a 2 would be roughly (2)(3%) times the number of rolls. We can apply the same reasoning to each of the other outcomes and can sum all the contributions to get the grand total. Dividing by the number of rolls to get the average gives us the sum (2)(3%) + (3)(6%) + (4)(8%) + …, which we call the expected value of the distribution. The value of this expression is 7, as can be seen in the “Expected total” pod above.
The effect of totaling the products of outcomes and probabilities is to create a weighted average of the outcomes with the probabilities providing the weights. This represents your approximate average over many rolls and is called the expected value of the probability distribution from which it came.
Expected value has a nice visual interpretation as the balance point of the distribution. If the horizontal axis above were a seesaw, the expected value would be the point where you’d have to put the fulcrum to get it to balance. For the distribution of the rolls of two dice, it is visually obvious that this point is 7.
Wolfram|Alpha can compute expected values of the many probability distributions that it knows. For example, the binomial distribution distributes probability among the possible counts of heads in n flips of a coin that is weighted so that the probability of a single flip landing heads is p:
For almost all named families of probability distributions, the expected value can be computed as a function of the parameters. We can get these formulas from Wolfram|Alpha, too:
This makes sense! If I flip n = 100 coins with p = 0.2 probability of heads on each flip, then I expect to get np = (100)(.2) = 20 heads.
For continuous distributions, the mathematical definition of the expected value is slightly more complicated, but with Wolfram|Alpha, this additional computational complexity is not an obstacle. What’s more, the interpretation of the expected value as the balance point of the distribution is still a good one. Looking at the standard normal distribution, we would guess that the expected value is 0…
…and indeed it is:
We noted in the probability blog post that the parameter μ controls the center of a normal distribution.
Other distributions are not so symmetric:
It turns out that the expected value of a gamma distribution is the product of the distribution’s parameters:
In Wolfram|Alpha, you can specify some of a distribution’s parameters and see how the expected value is a function of the others:
Computing expected values often requires computing complicated sums or integrals. The burden of this requirement is eased somewhat by the existence of nice formulas for the expected values of many distributions. Wolfram|Alpha provides one place to do such computations easily, but where Wolfram|Alpha really offers a significant advance is in its ability to easily compute expected values of functions of distributions. Suppose you were to flip a fair coin ten times and square the number of heads you observe. What do you expect? Perhaps surprisingly, the answer is not 25:
The “Example simulations” pod above shows the results of a few runs of the experiment just described—flip the coin, count the heads, square the result, and average these numbers over many trials. These averages all move close to the computed expected value of 27.5 as the number of trials grows.
For other distributions, one can do similar thought experiments. Draw a value from the distribution (i.e., pick a “random” number, where the probability of an outcome is given by the probability distribution in question) and square it (or cube it, or multiply it by 7 and add 4, etc.)—what do we expect?
These expected values can be quite complicated:
Of course, we are eager to expand Wolfram|Alpha’s facility with expected values even further and look forward to getting feedback from you and bringing you more and better functionality in the future.