liveBook · Manning

Variance

As explained in Statistics Every Programmer Needs

Variance is a measure of the average squared deviation of values from their mean.

Variance measures spread around a mean: it is the average of the squared differences between individual values and that mean. For n measurements, calculate the mean, square each measurement’s difference from it, add those squares, and divide by n. Taking the square root gives standard deviation, which expresses spread in the original units. section 14.1.3

The distinction matters when setting quality-control limits. Variance describes squared deviations, while standard deviation supplies a spread measure in the units being monitored. Conventional control limits sit three standard deviations above and below the process mean; the roughly 99.73% benchmark depends on a normal distribution and may be adjusted for operational needs. section 14.1.3 section 14.1.1

Choose a measure of variation that fits the decision:

  • Use an s-chart to track the standard deviation within each sample over time; it is especially useful for larger samples. section 14.3.3
  • Use a range chart for each sample’s maximum-minus-minimum spread, or a moving-range chart for differences between consecutive observations. section 14.1.4 section 14.1.10
  • Use process capability indices to compare process spread with specification limits; Cpk also accounts for how the process is centered. section 14.1.12

Checking simulated stock-price spread

Flatten simulated prices into one dataset and run pandas `describe()` to inspect their mean and standard deviation. The simulated mean was $35.56, close to the observed $35.46, but the simulated standard deviation was $2.20 versus $0.81 observed. A close mean therefore did not mean the simulation reproduced the observed variability; its wider spread included more extreme price scenarios. section 9.5.8

>>> all_simulations = \
>>>     simulation_df.values.flatten()   #1
>>> overall_stats = pd.DataFrame(all_simulations, 
>>>         columns = ['Simulated Prices']).describe() #2
>>> print(overall_stats)     #3
       Simulated Prices
count      10500.000000
mean          35.559536
std            2.204029
min           25.996207
25%           34.261598
50%           35.691632
75%           36.821081
max           47.983021

Shows the pandas calculation and its mean, standard deviation, and range across flattened simulated prices. section 9.5.8

Spread also affects simulation decisions before results are generated: an uncertain variable’s distribution and parameters, including mean and variance where applicable, need justification from data, domain knowledge, or assumptions. Afterward, inspect the outcome distribution rather than relying on its average alone. Ten staffing trials gave a mean of 2.4 additional employees, but so few trials may miss important variability; more trials can give a more reliable picture. section 9.2 section 9.3.6

How Statistics Every Programmer Needs covers it

How deep it goes
Defines variance through squared deviations and explains its square-root relationship to standard deviation, without developing a separate variance estimator.
Examples
Compares simulated and observed stock-price standard deviations and tracks piston-ring sample variability with an s-chart.
What it assumes
Uses individual measurements and their mean while explaining squared deviations; simulation applications additionally require a chosen probability distribution.
What you can do after
Evaluate/understand it when interpreting simulated spread or selecting variability measures for quality-control charts.
How it connects
Connects variance to the mean, standard deviation, control limits, process capability, and probability distributions.

Also explained in

Compare how 19 books explain variance →

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.