Skip to main content

Chapter 2 Distributions

This chapter introduces one of the most fundamental ideas in statistics, the distribution. We’ll start with frequency tables — which represent the values in a dataset and the number of times each of them appears — and use them to explore data from the National Survey of Family Growth (NSFG). We’ll also look for extreme or erroneous values, called outliers, and consider ways to handle them.
Listing 2.0.1. Python Code
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")
Listing 2.0.2. Python Code
try:
    import empiricaldist
except ImportError:
    %pip install empiricaldist
Listing 2.0.3. Python Code
import numpy as np
import matplotlib.pyplot as plt
from thinkstats import decorate