Lesson 9 of 15

Expectation & Variance Properties

Rules for Transforming Random Variables

Linearity of Expectation

For any constants aa and bb:

E[aX+b]=aE[X]+bE[aX + b] = a \cdot E[X] + b

This holds for all random variables, regardless of dependence or distribution. It is the most useful fact in probability.

Variance Under Linear Transformation

Var(aX+b)=a2Var(X)\text{Var}(aX + b) = a^2 \cdot \text{Var}(X)

Adding a constant shifts the distribution but does not change spread. Scaling by aa stretches spread by a|a|, so variance scales by a2a^2.

# X ~ Bernoulli(0.5): E[X] = 0.5, Var(X) = 0.25
# Y = 2X + 3
# E[Y] = 2*0.5 + 3 = 4.0
# Var(Y) = 4 * 0.25 = 1.0
mean_x, var_x = 0.5, 0.25
a, b = 2, 3
print(round(a * mean_x + b, 4))   # 4.0
print(round(a**2 * var_x, 4))     # 1.0

Sum of Independent Random Variables

E[X+Y]=E[X]+E[Y](always)E[X + Y] = E[X] + E[Y] \quad \text{(always)} Var(X+Y)=Var(X)+Var(Y)(if independent)\text{Var}(X + Y) = \text{Var}(X) + \text{Var}(Y) \quad \text{(if independent)}

Your Task

Implement linear_transform(mean_x, var_x, a, b) that prints E[aX+b]E[aX+b] and Var(aX+b)\text{Var}(aX+b), each rounded to 4 decimal places.

Pyodide loading...
Loading...
Click "Run" to execute your code.