Learn

Variance for the Binomial distribution is similarly calculated using the n and p parameters. Let’s use the 10 fair coin flips example to try to understand how variance is calculated. Each coin flip has a certain probability of landing as heads or tails: 0.5 and 0.5, respectively.

The variance of a single coin flip will be the probability that the success happens times the probability that it does not happen: p·(1-p), or 0.5 x 0.5. Because we have n = 10 number of coin flips, the variance of a single fair coin flip is multiplied by the number of flips. Thus we get the equation:

Variance(#ofHeads)=Var(X)=n×p×(1p)Variance(#ofHeads)=10×0.5×(10.5)=2.5\begin{aligned} Variance(\#\;of\;Heads) = Var(X) = n \times p \times (1-p) \\ Variance(\#\;of\;Heads) = 10 \times 0.5 \times (1 - 0.5) = 2.5 \end{aligned}

Let’s consider our 20 multiple choice quiz again. The variance around getting an individual question correct would be p·(1-p), or 0.25 x 0.75. We then multiply this variance for all 20 questions in the quiz and get:

Variance(#ofCorrectAnswers)&=20×0.25×(10.25)=3.75Variance(\#\;of\;Correct\;Answers) \&= 20 \times 0.25 \times (1 - 0.25) = 3.75

We would expect to get 5 correct answers, but the overall variance of the probability distribution is 3.75.

Instructions

1.

A certain basketball player has an 85% chance of making a given free throw. Uncomment variance_baskets and set it equal to the variance of free throws made from 20 shots.

Then print variance_baskets.

2.

Let’s say a student has a 98% chance of arriving on time to class. Uncomment variance_late and set it equal to the variance of days the student will arrive late to class throughout the 180 school days in a school year.

Then print variance_late.

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?