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.
from os.path import basename, exists
def download(url):
filename = basename(url)
if not exists(filename):
from urllib.request import urlretrieve
local, _ = urlretrieve(url, filename)
print("Downloaded " + local)
download("https://github.com/AllenDowney/ThinkStats/raw/v3/nb/thinkstats.py")
try:
import empiricaldist
except ImportError:
%pip install empiricaldist
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from thinkstats import decorate
