Learn

Probability distributions also have calculable variances. Variances are a way of measuring the spread or dispersion of values and probabilities in the distribution. For the Poisson distribution, the variance is simply the value of lambda (λ), meaning that the expected value and variance are equivalent in Poisson distributions.

We know that the Poisson distribution has a discrete random variable and must be greater than 0 (think, a salesperson cannot have less than 0 sales, a shop cannot have fewer than 0 customers), so as the expected value increases, the number of possible values the distribution can take on would also increase.

The first plot below shows a Poisson distribution with lambda equal to three, and the second plot shows a Poisson distribution with lambda equal to fifteen. Notice that in the second plot, the spread of the distribution increases. Also, take note that the height of the bars in the second bar decrease since there are more possible values in the distribution.

This image shows a Poisson distribution with lambda equal to three.

This image shows a Poisson distribution with lambda equal to fifteen.

As we can see, as the parameter lambda increases, the variance — or spread — of possible values increases as well.

We can calculate the variance of a sample using the numpy.var() method:

import scipy.stats as stats import numpy as np rand_vars = stats.poisson.rvs(4, size = 1000) print(np.var(rand_vars))

Output:

3.864559

Because this is calculated from a sample, it is possible that the variance might not equal EXACTLY lambda. However, we do expect it to be relatively close when the sample size is large, like in this example.

Another way to view the increase in possible values is to take the range of a sample (the minimum and maximum values in a set). The following code will take draw 1000 random variables from the Poisson distribution with lambda = 4 and then print the minimum and maximum values observed using the .min() and .max() Python functions:

import scipy.stats as stats rand_vars = stats.poisson.rvs(4, size = 1000) print(min(rand_vars), max(rand_vars))

Output:

0 12

If we increase the value of lambda to 10, let’s see how the minimum and maximum values change:

import scipy.stats as stats rand_vars = stats.poisson.rvs(10, size = 1000) print(min(rand_vars), max(rand_vars))

Output:

1 22

These values are spread wider, indicating a larger variance.

Instructions

1.

In script.py, a variable called rand_vars_7 contains 5000 random draws from the Poisson distribution with lambda = 7.

Calculate and print the variance of rand_vars_7.

2.

Calculate and print the minimum value and maximum value of rand_vars_7.

3.

In script.py, a variable called rand_vars_17 contains 5000 random draws from the Poisson distribution with lambda = 17.

Calculate and print the variance of rand_vars_17.

4.

Calculate and print the minimum and maximum values of rand_vars_17.

Note that the range of values of rand_vars_17 is wider than rand_vars_7.

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?