Learn

There are several properties of expectation and variance that are consistent through all distributions:

Properties of Expectation

  1. The expected value of two independent random variables is the sum of each expected value separately:

    E(X+Y)=E(X)+E(Y)E(X + Y) = E(X) + E(Y)

    For example, if we wanted to count the total number of heads between 10 fair quarter flips and 6 fair nickel flips, the expected value combined would be 5 heads (from the quarters) and 3 heads (from the nickels) so 8 heads overall.

  2. Multiplying a random variable by a constant a changes the expected value to be a times the expected value of the random variable:

    E(aX)=aE(X)E(aX) = aE(X)

    For example, the expected number of heads from 10 fair coin flips is 5. If we wanted to calculate the number of heads from this event run 4 times (40 total coin flips), the expected value would now be 4 times the original expected value, or 20.

  3. Adding a constant a to the distribution changes the expected value by the value a:

    E(X+a)=E(X)+aE(X + a) = E(X) + a

    Let’s say that a test was given and graded, and the average grade was 78 out of 100 points. If the teacher decided to curve the grade by adding 2 points to everyone’s grade, the average would now be 80 points.

Properties of Variance

  1. Increasing the values in a distribution by a constant a does not change the variance:

    Var(X+a)=Var(X)Var(X + a) = Var(X)

    This is because the variance of a constant is 0 (there is no range for a single number). Adding a constant to a random variable does not add any additional variance. Let’s take the previous example with the teacher curving grades: though the expected value (or average) of the test changes from 78 to 80, the spread and dispersion (or variance) of the test scores stays the same.

  2. Scaling the values of a random variable by a constant a scales the variance by the constant squared:

    Var(aX)=a2Var(X)Var(aX) = a^2Var(X)
  3. The variance of the sum of two random variables is the sum of the individual variances:

    Var(X+Y)=Var(X)+Var(Y)Var(X + Y) = Var(X) + Var (Y)

    This principle ONLY holds if the X and Y are independent random variables. Let’s say that X is the event getting a heads on a single fair coin flip, and Y is the event rolling a 2 on a fair six-sided die:

    Var(X)=0.5(10.5)=0.25Var(X) = 0.5 * (1 - 0.5) = 0.25
    Var(Y)=0.167(10.167)=0.139Var(Y) = 0.167 * (1 - 0.167) = 0.139
    Var(X+Y)=Var(X)+Var(Y)=0.25+0.139=0.389Var(X + Y) = Var(X) + Var(Y) = 0.25 + 0.139 = 0.389

Instructions

1.

At the end of the year, your company’s boss decides that the end-of-year bonus will be 8% of each employee’s salary. If the average salary in the company is $75,000, what is the expected value (or average value) of the bonuses?

Uncomment expected_bonus and set it equal the expected value of the bonuses. Then print expected_bonus.

2.

Let’s say that the number of goals a soccer team scores follows the Poisson distribution with lambda equal to four. Uncomment num_goals and set it equal to 100 random draws from games following this Poisson distribution.

You can do this using the stats.poisson.rvs() method from the scipy library with lambda equal to four and 100 random draws. Click the hint if you need more guidance.

3.

Print the variance of num_goals using np.var().

4.

Someone thinks that the soccer team is being robbed of goals each game and decides that they are going to count each goal from this team as 2 goals.

Uncomment num_goals_2 and set it equal to each value of num_goals multiplied by 2.

Then calculate and print the variance of num_goals_2 to see that the variance of num_goals_2 is equal to the variance of num_goals times two squared (same as times four).

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?