Computational Statistics: A Tutorial in Python

Computational Statistics: A Tutorial in Python#

Allen Downey

Do you know the difference between standard deviation and standard error? Do you know what statistical test to use for any occasion? Do you really know what a p-value is? How about a confidence interval?

Most people don’t really understand these concepts, even after taking several statistics classes. The problem is that these classes focus on mathematical methods that bury the concepts under a mountain of details.

This tutorial uses Python to implement simple statistical experiments that develop deep understanding: effect sizes, sampling distributions, and hypothesis testing with resampling and simulation. The examples use real-world data to answer relevant questions, and you will practice with hands-on exercises.

It is based on my book, Think Stats, and my blog, Probably Overthinking It.

Level: beginner. You should be comfortable with basic Python; some experience with NumPy helps. You don’t need any background in statistics.

Length: about 3 hours.

The notebooks#

The pages on this site show the notebooks with solutions. To do the exercises, run the versions with blanks on Colab:

  1. Effect size: the difference in height between men and women, described as a difference in means, as overlap, as “probability of superiority”, and as Cohen’s d. Exercises on Colab

  2. Random sampling: sampling distributions, standard errors, and confidence intervals, by simulation and by resampling. Exercises on Colab

  3. Hypothesis testing: are first babies more likely to be late? Permutation tests, p-values, p-hacking, and statistical power. Exercises on Colab

  4. Resampling: the whole approach in one notebook, with the Euro problem, estimating average height, and first babies again. Run on Colab

Slides for this tutorial are here.

The extras use the same ideas: an introduction to PMFs, text analysis with Pride and Prejudice, and There is only one test, a problem from the AP Statistics exam solved by simulation.

Recordings#

I presented this tutorial at PyCon US 2015 and 2016 and at SciPy 2015 and 2017. The most recent recording is from SciPy 2017. The code in the videos is an earlier version; the repository README lists the version that goes with each video.

Next steps#

To go further, read Think Stats, which is free online, or see my other workshops.

The code is on GitHub, under the MIT License.