BRAGA

02 Writing02-02 Notes02-02-409

Expected Value (Mean)

Published 16 Apr 20263 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
E[X]=∑xxP(X=x)E[X] = \sum_{x} x P(X = x)
(1)

Deep Breakdown

What it tells me (Situation Awareness): The expected value E[X]E[X] is the probability-weighted average of all values a discrete random variable can take. It is the "center of mass" of a distribution. In DA/DS: it is the theoretical counterpart of the sample mean, used in loss functions (MSE = E[(y−y^)2]E[(y - \hat{y})^2]), reinforcement learning (expected reward), and decision theory.

Flowchart

Discrete RV Xwith PMFP(X=x)Each value x,weighted byP(X=x)Multiply x *P(X=x) for eachxSum allweighted valuesE[X] = Σ x *P(X=x)

Real-world use

Where it is used

Reinforcement learning (expected cumulative reward). Decision trees (expected value of each branch). A/B test effect size. Pricing: expected revenue per customer = ∑xx⋅P(revenue=x)\sum_x x \cdot P(\text{revenue} = x).

Problem it solves

Computes the long-run average value of a random variable over many trials, without needing to observe all outcomes.

How it solves the problem

Weights each outcome by its probability and sums — produces the probability-weighted mean of the distribution.

Example in a business

Click-value model: clicks yield $\$0(60(60%),$5(30(30%),$20(10(10%).E[\text{revenue}] = 0 \times 0.6 + 5 \times 0.3 + 20 \times 0.1 = 0 + 1.5 + 2.0 = $3.50$ expected revenue per click.

The formula, piece by piece

E[X]=∑xx⋅P(X=x)E[X] = \sum_x x \cdot P(X = x)

  • xx: each possible value of XX.
  • P(X=x)P(X = x): the PMF evaluated at xx.
  • ∑x\sum_x: sum over all values xx in the support of XX.

The formula in words

"The expected value is the sum of each outcome times the probability of that outcome."

Critical Concepts

  • E[X]E[X] may not be a value that XX can actually take (e.g., E[die]=3.5E[\text{die}] = 3.5).
  • Linearity: E[aX+b]=aE[X]+bE[aX + b] = aE[X] + b.
  • For the Bernoulli distribution: E[X]=pE[X] = p.
  • For Binomial(n,p)(n, p): E[X]=npE[X] = np.
  • For Poisson(λ\lambda): E[X]=λE[X] = \lambda.

Step-by-step calculation (tiny example)

Step 1: Revenue outcomes Revenue: {$0, $5, $20}, P = {0.6, 0.3, 0.1}.

Step 2: Weighted sum E=0×0.6+5×0.3+20×0.1=0+1.5+2.0=3.5E = 0 \times 0.6 + 5 \times 0.3 + 20 \times 0.1 = 0 + 1.5 + 2.0 = 3.5

Step 3: Interpret Expected revenue per click is $3.50.

Code examples

Beginner example (Python)

python
import numpy as np   # Expected revenue per click
outcomes = np.array([0, 5, 20])
probabilities = np.array([0.6, 0.3, 0.1])
expected_revenue = np.dot(outcomes, probabilities)
print(f"E[revenue] = ${expected_revenue:.2f}")   # $3.50

Beginner example (R)

r
outcomes <- c(0, 5, 20)
probabilities <- c(0.6, 0.3, 0.1)
expected_revenue <- sum(outcomes * probabilities)
cat(sprintf("E[revenue] = $%.2f\n", expected_revenue))  # $3.50

Professional example (Python)

python
import numpy as np
from scipy.stats import rv_discrete

def expected_value_discrete( outcomes: np.ndarray, probabilities: np.ndarray ) -> float:
    """Compute E[X] for a discrete distribution. Args: outcomes: Array of possible values. probabilities: Corresponding probabilities (must sum to 1). Returns: E[X] = sum(x * P(X=x)). """
    if abs(probabilities.sum() - 1.0) > 1e-8:
        raise ValueError(f"Probabilities sum to {probabilities.sum():.6f}, not 1.0")
    return float(np.dot(outcomes, probabilities))   # Multi-tier revenue model
tiers = { "free": {"revenue": 0, "prob": 0.60}, "basic": {"revenue": 10, "prob": 0.25}, "premium": {"revenue": 50, "prob": 0.12}, "enterprise":{"revenue": 500, "prob": 0.03},
}
rev_outcomes = np.array([t["revenue"] for t in tiers.values()])
rev_probs = np.array([t["prob"] for t in tiers.values()])
ev = expected_value_discrete(rev_outcomes, rev_probs)
variance = expected_value_discrete(rev_outcomes**2, rev_probs) - ev**2
std_dev = np.sqrt(variance)
print(f"E[revenue] = ${ev:.2f}")
print(f"Var[revenue] = ${variance:.2f}")
print(f"Std[revenue] = ${std_dev:.2f}")
for tier_name, tier_data in tiers.items():
    contribution = tier_data["revenue"] * tier_data["prob"]
print(f" {tier_name:<12}: contributes ${contribution:.2f} ({contribution/ev*100:.1f}%)")

Source: 1300 p. 333

#probability-statistics#statistical-operations-and-random-variables#discrete-random-variables-drvs

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close