Skip to Content
Think Stats, 3rd Edition
book

Think Stats, 3rd Edition

by Allen B. Downey
April 2025
Intermediate to advanced
324 pages
6h 56m
English
O'Reilly Media, Inc.
Content preview from Think Stats, 3rd Edition

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:

from empiricaldist import FreqTab

ftab = 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 / n
pmf
  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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Think Bayes, 2nd Edition

Think Bayes, 2nd Edition

Allen B. Downey
Practical Statistics for Data Scientists, 2nd Edition

Practical Statistics for Data Scientists, 2nd Edition

Peter Bruce, Andrew Bruce, Peter Gedeck
LLM Engineer's Handbook

LLM Engineer's Handbook

Paul Iusztin, Maxime Labonne

Publisher Resources

ISBN: 9781098190248Errata Page