This folder contains the computational notebooks that accompany the the No Bullshit Guide to Statistics.
The purpose of these notebooks is to allow you to experiment and play with all the code examples presented in the book. Each notebook contains numerous empty code cells, which are an invitation for you to try some commands on your own. For example, you can copy-paste some of the neighbouring commands and try modifying them to see what outputs you get.
Chapter 1: Data¶
Data is
1.1 Data collection¶
This is a very short notebook that gives some examples of random selection and random assignment. See the text for the actual definitions of concepts related to data collection.
View notebook: 11
_data _collection .ipynb
1.2 Data in practice¶
This notebook explains practical aspects of data manipulations using Python library Pandas, including data preprocessing steps like data cleaning and outlier removal. The notebook also introduces basic plots using the library Seaborn.
View notebook: 12
_data _in _practice .ipynb Colab link: TODO
1.3 Descriptive statistics¶
This notebook explains how to compute numerical summaries (mean, standard deviation, quartiles, etc.) and how to generate data statistical plots like histograms, box plots, bar plots, etc.
View notebook: 13
_descriptive _statistics .ipynb
Chapter 2: Probability¶
In this chapter you’ll learn about random variables and probability distributions, which are essential building blocks for statistical models.
2.1 Discrete random variables¶
This notebook contains a complete introduction to probability theory, including definitions, formulas, and lots of examples of discrete random variables like coin toss, die roll, and other.
View notebook: 21
_discrete _random _vars .ipynb
2.2 Multiple random variables¶
This section will introduce you to the concept of a joint probability distribution. For example, the pair of random variables can be described by the joint probability distribution function .
View notebook: 22
_multiple _random _vars .ipynb
2.3 Inventory of discrete distributions¶
The Python module scipy.stats contains pre-defined probability models that you
can use for modeling tasks. These are like LEGOs for the XXIst century.
View notebook: 23
_inventory _discrete _dists .ipynb
2.4 Continuous random variables¶
In this notebook we’ll revisit all the probability concepts we learned for discrete random variables, and learn the analogous concepts for continuous random variables. You can think of Section 2.5 as the result of taking Section 2.1 and replacing every occurrence with .
View notebook: 24
_continuous _random _vars .ipynb
2.5 Multiple continuous random variables¶
We study of pairs of continuous random variables and their joint probability density functions. We’ll revisit some of the ideas from Section 2.2 but apply them to continuous random variables.
View notebook: 25
_multiple _continuous _random _vars .ipynb
2.6 Inventory of continuous distributions¶
In this section we’ll complete the inventory of probability distributions by
introducing the “continuous LEGOs” distributions like uniform, norm, expon,
t, f, chi2, gamma, beta, etc.
View notebook: 26
_inventory _continuous _dists .ipynb
2.7 Simulations¶
How can we use computers to generation observations from random variables? In this notebooks, we’ll describe some practical techniques for generating observations from any probability distribution. We’ll learn how to use lists of observations from random variables for probability calculations.
View notebook: 27
_simulations .ipynb
2.8 Probability models for random samples¶
Consider a random variable with a known probability distribution . What can we say about the characteristics of copies of the random variable . Each is independent copy of the random variable . This is called the independent, identically distributed (iid) setting. Understanding the properties of the random sample is important for all the statistics operations we’ll be doing in Chapter 3.
View notebook: 28
_random _samples .ipynb
Chapter 3: Classical (frequentist) statistics¶
This chapter introduces the main ideas of STAT101.
3.1 Estimators¶
Estimators are the function that we use to compute estimates. The value of the estimator computed from a random sample is called the sampling distribution of the estimator. Understanding estimators and sampling distributions is the key step to understanding the statistics topics in Chapter 3.
View notebook: 31_estimators.ipynb
3.2 Confidence intervals¶
A confidence interval describes a lower bound and an upper bound on the possible values for some unknown parameter. We’ll learn how to construct confidence intervals based on what we learned about sampling distributions in Section 3.1.
View notebook: 32
_confidence _intervals .ipynb
3.3 Introduction to hypothesis testing¶
Hypothesis testing is a statistical analysis technique we can use to detect “unexpected” patterns in data. We start our study of hypothesis testing using direct simulation.
View notebook: 33
_intro _to _NHST .ipynb
3.4 Hypothesis testing using analytical approximations¶
We revisit the hypothesis testing procedures using analytical formulas.
View notebook: 34
_analytical _approx .ipynb
3.5 Two-sample hypothesis tests¶
In this notebook, we focus on the specific problem of comparing samples from two unknown populations.
View notebook: 35
_comparing _two _populations .ipynb
3.6 Statistical design and error analysis¶
This section describes the possible mistakes we can make when using the hypothesis testing procedure. The statistical design process includes considerations we take before the study to ensure the hypothesis test we perform has the correct error rates.
View notebook: 36_design.ipynb
3.7 Inventory of statistical tests¶
This notebook contains examples of the statistical testing “recipes” for use in different data analysis scenarios.
View notebook: 37
_inventory _stats _tests .ipynb
3.8 Statistical practice¶
No notebook available. See the text or the preview.
Chapter 4: Linear models¶
Linear models are a unifying framework for studying the influence of predictor variables on an outcome variable .
4.1 Simple linear regression¶
The simplest linear model has one predictor and one outcome variabel .
View notebook: 41
_simple _linear _regression .ipynb
4.2 Multiple linear regression¶
We extend the study to a linear model with predictors .
View notebook: 42
_multiple _linear _regression .ipynb
4.3 Interpreting linear models¶
We learn how to interpret the parameter estimates and perform hypothesis tests based on linear models.
View notebook: 43
_interpreting _linear _models .ipynb
4.4 Regression with categorical predictors¶
We can encode categorical predictor variables using the “dummy coding” that involves indicator variables. We’ll use dummy coding to revisit some of the statistical analyses we saw in Chapter 3.
View notebook: 44
_regression _with _categorical _predictors .ipynb
4.5 Model selection for causal inference¶
We often want to learn about causal links between variables, which is difficult when all we have is observational data. In this section, we’ll use linear models as a platform to learn about confounding variables and other obstacles to causal inference.
View notebook: 45
_causal _inference .ipynb
4.6 Generalized linear models¶
In this section, we’ll use the structure of linear models to build models for binary outcome variables (logistic regression) or count data (Poisson regression).
View notebook: 46
_generalized _linear _models .ipynb
Chapter 5: Bayesian statistics¶
Bayesian statistics is a whole other approach to statistical inference.
5.1 Introduction to Bayesian statistics¶
This section introduces the basic ideas from first principles, using simple hands-on calculations based on the grid approximation.
View notebook: 51
_intro _to _Bayesian _stats .ipynb
5.2 Bayesian inference computations¶
In this section, we revisit the Bayesian inference calculations we saw in Section 5.1, but this time use the Bambi library to take care of the calculations for us. We’ll also use the ArViZ to help with visualization of Bayesian inference results.
View notebook: 52
_Bayesian _inference _computations .ipynb
5.3 Bayesian linear models¶
We use Bambi to build linear models and revisit some of the analyses from Chapter 4 from a Bayesian perspective.
View notebook: 53
_Bayesian _linear _models .ipynb
5.4 Bayesian difference between means¶
We build a custom model for comparing two unknown populations based on Bayesian principles. We use this model to revisit some of the statistical analyses from Section 3.5 from a Bayesian perspective.
View notebook: 54
_difference _between _means .ipynb
5.5 Hierarchical models¶
Certain datasets have a group structure. For example students’ data often comes in groups according to the class they are part of. Hierarchical models (a.k.a. multilevel models) are specially designed to handle data with group structure.
View notebook: 55
_hierarchical _models .ipynb