Conditional Expectation

Conditional Expectation#

\[ E[X \cdot I(X < n)] = E[X \mid X < n] \cdot P(X < n) \]

Proof: $\( E[X \cdot I(X < n)] = E[X \cdot I(X < n) \mid X < n] \cdot P(X < n) + E[X \cdot I(X < n) \mid X > n] \cdot P(X > n) \)$

\[ = E[X \mid X < n] \cdot P(X < n) + 0 \]
import numpy as np
num_samples = 1_000_000
X = np.random.normal(0, 1, num_samples)  # Standard normal

I_X_less_0 = X < 0  # Indicator for X < 0

# 1. Calculate E[X | X < 0] * P(X < 0)
E = np.mean(X[X<0])  # E[X | X < 0]
P = np.mean(I_X_less_0)             # P(X < 0)
print(P)
E1 = E * P

# 2. Calculate E[X * I(X < 0)]
X[X > 0] = 0
E2 = np.mean(X)


print(E1, E2)
0.499603
-0.3988524658505171 -0.39885246585051737