oldoc63 / learningDS

Learning DS with Codecademy and Books
0 stars 0 forks source link

Properties of Expectation and Variance #431

Open oldoc63 opened 1 year ago

oldoc63 commented 1 year ago

There are several properties of expectation and variance that are consistent though 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) $$

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.

  1. 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) $$

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

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

$$ E(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.

oldoc63 commented 1 year ago

Properties of Variance

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

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

This is because a 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.

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

$$ Var(aX)=a^2Var(X) $$

  1. The variance of the sum of two random variables is the sum of the individual variances:

$$ 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∗(1−0.5)=0.25 $$

$$ Var(Y)=0.167∗(1−0.167)=0.139 $$

$$ Var(X+Y)=Var(X)+Var(Y)=0.25+0.139=0.389 $$

oldoc63 commented 1 year ago

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 $75000, what is the expected value (or average value) of the bonuses?

oldoc63 commented 1 year ago

The number of goals a soccer team scores follows the Poisson distribution with lambda equal to four. Set num_goals equal to 100 random draws from games following this Poisson distribution. Use stats.poisson.rvs() method from the scipy library with lambda equal to 4 and 100 random draws.

oldoc63 commented 1 year ago

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.

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).

oldoc63 commented 1 year ago

Let's practice calculating different values from the Poisson distribution:

  1. You work at ambulance dispatch where the number of calls that come in daily follows the Poisson distribution with lambda equal to 9. There's a rule that a team can go on no more than 12 calls a day. But how often could this happen? Create a variable calls that is the probability of observing more than 12 calls on a given day. Then print calls.
oldoc63 commented 1 year ago
  1. Let's say that you have to call in a backup team if you have 10 or more calls in a given day. But you don't want to have to call in a backup team unless they really will be needed. What is the probability that they will be called and not needed? Create and print a variable false_backup that is the probability of observing a minimum of 10 calls, but no more than 12.
oldoc63 commented 1 year ago
  1. A certain tennis star has a first-serve rate of 62%. Let's say they serve 80 times in a given match. What is the expected value of the number of serves they make? Create and print a variable expected_serves that is the number of first-serves they are expected to make.
oldoc63 commented 1 year ago
  1. At the same firs-serve rate, what is the variance of this player's first-serves? Create and print a variable variance-serves that is the variance of the player making their first serve.