Ask Claude about this

Exploring Expected Value Properties

Expectation of Functions of Random Variables

The expected value, often denoted E[X], tells us the "average" outcome of a random variable X if we were to repeat an experiment many times. Sometimes, we're not just interested in the average of X itself, but the average of some function of X. For example, we might want to find the average of X squared (E[X²]), or the average of X plus a constant (E[X+c]), or the average of some other transformation, say g(X).

If X is a discrete random variable (meaning it can only take on specific, separate values), and it can take values x1, x2, x3, ... with corresponding probabilities P(x1), P(x2), P(x3), ..., then the expected value of a function g(X) is calculated by: E[g(X)] = Σ [g(xi) * P(xi)] This means: for each possible value xi that X can take, you first apply the function g to it (calculate g(xi)), then multiply by the probability of X being xi, and finally, sum up all these products.

A common example is finding E[X²]. Here, g(X) = X². So, the formula becomes: E[X²] = Σ [xi² * P(xi)]. This value is important because it's used to calculate the variance of X, which measures how spread out the values of X are.

Expectation of Products of Independent Variables

What if we have two random variables, X and Y, and we want to find the expected value of their product, E[XY]? There's a very useful property that applies if X and Y are independent.

Two random variables are independent if knowing the outcome of one tells you nothing about the outcome of the other (like two separate coin flips or two separate dice rolls).

If X and Y are independent, then: E[XY] = E[X] × E[Y] This means you can find the expected value of X, find the expected value of Y, and then simply multiply these two averages together to get the expected value of their product.

Important Note: This rule (E[XY] = E[X]E[Y]) only works if X and Y are independent. If they are dependent (meaning the value of one influences the value of the other), then E[XY] is generally not equal to E[X]E[Y]. The difference between E[XY] and E[X]E[Y] when they are dependent is related to something called their covariance, which measures how they vary together.

Expected Value Properties

ADVANCED

Let X be a discrete random variable following a Uniform distribution from 1 to N, i.e., X ~ Uniform(1, N). This means X can take any integer value from 1 to N, each with probability 1/N.

Find:

  1. E[X²] (The expected value of X squared)
  2. E[XY], where Y is another random variable, independent of X, and also distributed as Y ~ Uniform(1, N).

Challenge: Using the results for E[X] = (N+1)/2 and E[X²] = (N+1)(2N+1)/6, can you find the formula for the Variance, Var(X), for a discrete uniform distribution X ~ Uniform(1, N)? Recall the formula for variance: Var(X) = E[X²] - (E[X])².

Nerchuko Academy · Free DS Interview Prep