Chapter 3. Probability Mass Functions
In the previous chapter we represented distributions using a FreqTab object, which contains a set of values and their frequencies—that is, the number of times each value appears. In this chapter we’ll introduce another way to describe a distribution, a probability mass function (PMF).
To represent a PMF, we’ll use an object called a Pmf, which contains a set of values and their probabilities. We’ll use Pmf objects to compute the mean and variance of a distribution, and the skewness, which indicates whether it is skewed to the left or right. Finally, we will explore how a phenomenon called the “inspection paradox” can cause a sample to give a biased view of a distribution.
PMFs
A Pmf object is like a FreqTab that contains probabilities instead of frequencies. So one way to make a Pmf is to start with a FreqTab. For example, here’s a FreqTab that represents the distribution of values in a short sequence:
fromempiricaldistimportFreqTabftab=FreqTab.from_seq([1,2,2,3,5])ftab
| freqs | |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 3 | 1 |
| 5 | 1 |
The sum of the frequencies is the size of the original sequence:
n=ftab.sum()n
5
If we divide the frequencies by n, they represent proportions, rather than counts:
pmf=ftab/npmf
| probs | |
|---|---|
| 1 | 0.2 |
| 2 | 0.4 |
| 3 | 0.2 |
| 5 | 0.2 |
This result indicates that 20% of the values in the sequence are 1, 40% are 2, and so on.
We can also think of these proportions as probabilities in the following sense: if we choose a random ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access