Contents
Deep Breakdown
What it tells me (Situation Awareness): The variance of a discrete random variable measures the expected squared deviation from the mean. The shortcut formula is computationally convenient. Used in risk analysis, feature importance (variance-based sensitivity), regularization design, and A/B test power calculations.
Flowchart
Real-world use
Where it is used
Risk quantification (variance of revenue streams), feature selection (high-variance features carry more information), ensemble diversity (variance of model predictions), and A/B test minimum detectable effect (MDE depends on pooled variance).
Problem it solves
Quantifies the spread and uncertainty around the expected value, complementing the mean with dispersion information.
How it solves the problem
Computes the expected squared deviation from the mean, with the shortcut avoiding direct computation of for each outcome.
Example in a business
Revenue model: Bernoulli conversion with , value $= \$100$. $E[\text{rev}] = 0.05 \times 100 = $5$. $Var[\text{rev}] = 100^2 \times 0.05 \times 0.95 = $475$ — high relative variance signals uncertainty in revenue projections.
The formula, piece by piece
- : expected squared deviation (definition).
- : second moment — .
- : square of the first moment.
- Shortcut: faster to compute, algebraically equivalent.
The formula in words
"Variance equals the expected value of minus the square of the expected value of ."
Critical Concepts
- always.
- (linearity of variance, shift doesn't matter).
- For independent : .
- Binomial: .
- Poisson(): (mean = variance).
Step-by-step calculation (tiny example)
Step 1: PMF , , . Bernoulli().
Step 2: E[X] and E[X²]
Step 3: Variance
Step 4: Verify For Bernoulli: . Correct.
Code examples
Beginner example (Python)
import numpy as np
from scipy.stats import bernoulli
p_conv = 0.3
dist = bernoulli(p_conv)
print(f"E[X] = {dist.mean():.4f}") # 0.3
print(f"Var[X] = {dist.var():.4f}") # 0.21
print(f"Std[X] = {dist.std():.4f}") # ~0.458Beginner example (R)
p_conv <- 0.3
outcomes <- c(0, 1); probs <- c(1 - p_conv, p_conv)
ex <- sum(outcomes * probs)
ex2 <- sum(outcomes^2 * probs)
var_x <- ex2 - ex^2
cat(sprintf("E[X] = %.4f | Var[X] = %.4f\n", ex, var_x))Professional example (Python)
import numpy as np
from scipy.stats import binom
def revenue_model_risk( conversion_rate: float, revenue_per_conversion: float, n_exposures: int ) -> dict[str, float]:
"""Compute expected revenue and risk metrics for a conversion model. Revenue = sum of Bernoulli conversions * value. Under Binomial(n, p): E[R] = n*p*v, Var[R] = n*p*(1-p)*v^2. Args: conversion_rate: p, probability of conversion. revenue_per_conversion: v, value per conversion. n_exposures: n, total users/impressions. Returns: Dict with E[revenue], Var[revenue], std, and coefficient of variation. """
expected_conversions = n_exposures * conversion_rate
var_conversions = n_exposures * conversion_rate * (1 - conversion_rate)
expected_revenue = expected_conversions * revenue_per_conversion
var_revenue = var_conversions * revenue_per_conversion**2
std_revenue = np.sqrt(var_revenue)
cv = std_revenue / expected_revenue if expected_revenue > 0 else float("inf")
return { "expected_revenue": expected_revenue, "variance_revenue": var_revenue, "std_revenue": std_revenue, "coefficient_of_variation": cv, }
for p_conv in [0.01, 0.05, 0.10, 0.20]:
metrics = revenue_model_risk(p_conv, 100.0, 10_000)
print(f"p={p_conv:.2f}: E=$ {metrics['expected_revenue']:>8,.0f} | " f"Std=${metrics['std_revenue']:>7,.0f} | CV={metrics['coefficient_of_variation']:.3f}")Source: AIO p. 85