liveBook · Manning

Mean

As explained in Statistics Every Programmer Needs

The mean, or expected value in a probability model, is the average level of a random variable or observed values.

The mean is the arithmetic average: add the observed values and divide by their count. It describes the central level of a dataset. When outcomes have known or estimated probabilities, the expected value is a probability-weighted mean: multiply each outcome by its probability, then add the products. section 14.1.2 section 10.1.4

Choose the form of the mean that matches the decision:

  • For historical stock returns, calculate the mean log return to represent the observed daily trend. Pair it with standard deviation, which captures fluctuations around that trend; both feed a Monte Carlo simulation. section 9.5.4
  • For quality control, use the process mean as a control chart’s center line. Compare plotted observations with that reference to spot patterns or shifts. section 14.1.2
  • For choices under uncertainty, calculate each option’s expected payoff from its possible payoffs and their probabilities, then compare the options. section 10.1.4

Compare investment alternatives

Suppose a stock-market investment pays $100,000 in a strong economy and loses $120,000 in a weak one. With probabilities of 0.75 and 0.25, its expected value is 0.75 × $100,000 + 0.25 × (−$120,000) = $45,000. Check that the scenario probabilities sum to one before comparing this result with other investments. The highest expected payoff is a decision criterion, not a guarantee of that payoff. section 10.1.4

>>> strong_econ = 0.75     #1
>>> weak_econ = 0.25    #2
>>> if strong_econ + weak_econ != 1:
>>>     raise ValueError(‘The probabilities ‘ \
>>>             must sum to 1.’)     #3

>>> payoff_table['EV'] = \
>>>   (payoff_table['Strong Economy'] * strong_econ) + \
>>>   (payoff_table['Weak Economy'] * weak_econ)   #4
>>> print(payoff_table)     #5
             Investment Alternatives  Strong Economy  Weak Economy       EV
0                       Stock Market          100000       -120000  45000.0
1           Professional Soccer Club           60000        -20000  40000.0
2 Stock Market / Soccer Club (50/50)           80000        -70000  42500.0
3                    Savings Account           35000         35000  35000.0

>>> max_ev = payoff_table['EV'].max()   #6
>>> print("Maximum Expected Value:", max_ev)  #7
Maximum Expected Value: 45000.0

The Python payoff table checks the probabilities, calculates an expected value for each investment, and finds the largest. section 10.1.4

A mean does not describe the full range of outcomes. In staffing simulations, an expected need near two employees can coexist with more variable days; a ten-run simulation may also be skewed by anomalies. Use enough simulations and consider variability and the cost of a shortfall before acting on an average alone. section 9.3.6

How Statistics Every Programmer Needs covers it

How deep it goes
Defines the arithmetic mean, works through probability-weighted payoffs, and implements a historical mean in Python; does not develop a formal probability proof.
Examples
Uses historical stock returns, an investment payoff table, employee absenteeism, and a quality-control center line.
What it assumes
Starts with summing and counting observed values; requires scenario probabilities that are known or estimable for expected-value decisions.
What you can do after
Apply it via Python to calculate historical averages and expected payoffs, then interpret them alongside variability and decision priorities.
How it connects
Links mean to standard deviation, Monte Carlo simulation, control charts, expected value, and decision trees.

Also explained in

Compare how 29 books explain mean →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.