4  What Is a Distribution?

Rather than presenting the normal distribution as the default and others as exotic detours, this chapter builds the general vocabulary first — PMF, PDF, CDF — and treats every named distribution as one instance later.

def empirical_cdf(data):
    sorted_data = sorted(data)
    n = len(sorted_data)
    def cdf(x):
        return sum(1 for d in sorted_data if d <= x) / n
    return cdf

def empirical_survival(data):
    cdf = empirical_cdf(data)
    return lambda x: 1 - cdf(x)

The reader builds the empirical CDF and survival function for a small hand-entered dataset before ever sampling from a named distribution — the point being that these functions are properties of any data, not features that only show up once you’ve picked a textbook distribution.