2  Introduction

2.1 How to read this guide?

This book can be read in many ways, depending on the reader’s experience and interests. Here you’ll find theory, examples, code snippets and explanations. But you don’t have to read through it all page by page. Specifically, the book is organized as follows:

  • Chapter 3 presents the mathematical foundations behind analysis of variance and linear models. To read it, it is helpful to have an university level understanding of linear algebra and probability theory; typically, the knowledge gained in the first year of an engineering program is sufficient. This chapter covers all the mathematical foundations used in the subsequent chapters. However, if you’re more interested in examples and/or intuitions, you can skip this chapter.
  • Chapter 4 introduces simple linear regression, a linear model with a single quantitative predictor, through the lens of the MedScore dataset.
  • Chapter 5 introduces one-way analysis of variance with a single categorical predictor, through the lenses of the CuriosityScore dataset.
  • Chapter 6 introduces two-way and three-way analysis of variance with two or three categorical predictors with the example based on MobilityScore dataset.
  • Chapter 7 introduces nested analysis of variance based on NutritionScore dataset.
  • Chapter 8 covers models with mixed categorical and quantitative predictors with the use of EmploymentScore dataset.
  • Section 9.2.1 covers linear models with multiple variables and the SocialScore data.

Each subsequent chapter consists of three parts:

  • “The Case,” a section providing the story background. You can skip this if you’re not interested in the narrative layer.
  • “The Formula,” a section describing how a specific problem is expressed in the language of linear models. This section is usually based on the notation used in the Chapter 3 chapter, but it can also be read independently.
  • “The Terminal,” a section describing how to implement the specific problem in the R or Python console. If you’re interested in hands-on experience, this is the section you’ll find most useful.

These chapters can also be read in any order, skipping the narrative or the methodological section, depending on the reader’s preference.

2.2 Why StatPunk? Statistical Models Through Dystopian Narrative

Introducing Beta …

Linear models are among the oldest and most fundamental tools in statistical analysis. Since the pioneering work of Legendre (1805) and Gauss (1809) in the early 19th century, regression (Galton, 1886) has evolved into one of the most widely applied methodologies across sciences, social research, and industry (Stigler, 1986). Yet despite their ubiquity and mathematical elegance, linear models often remain abstract to students, being seen as a collection of formulas, assumptions, and diagnostic plots that exist primarily in textbooks and academic papers.

This book takes a different approach. Alongside traditional examples from biomedical research, genomics, and social sciences, we introduce StatPunk, a dystopian fictional universe set in the year 2047, where algorithms control resource allocation, predictive models determine life outcomes, and statistical analysis becomes a tool of both oppression and resistance. Through the eyes of Beta and Bit, two data forensics specialists operating in the megacity of WaszKrak, we explore how linear regression, ANOVA, and related techniques can reveal hidden biases, expose systematic inequalities, and ultimately serve as instruments for questioning the structures of power embedded in data.

2.3 The Pedagogical Power of Narrative

… and Bit

Why embed statistical methodology within fiction? Because context transforms comprehension. StatPunk narratives illuminate three critical aspects of statistical modeling that traditional examples sometimes obscure:

First, models are not neutral. Every choice, which variable serves as the predictor, how we transform the data, whether we include an intercept, carries consequences. In the MedScore case, Beta and Bit discover that healthcare spending follows an exponential relationship with MasterScore. The \(R^2 = 0.94\) indicates an almost perfect fit. But perfect fit to what? The model doesn’t predict healthcare needs, it predicts algorithmic allocation. The distinction matters. Through dystopian examples, students confront the reality that statistical models can describe injustice just as precisely as they describe natural phenomena.

Second, model diagnostics have ethical dimensions. When we examine residual plots, test for homoscedasticity, or calculate prediction intervals, we’re not merely checking mathematical assumptions, we’re investigating whether our models treat all observations fairly. In traditional regression analysis, heteroscedasticity is a technical problem requiring correction. In StatPunk, heteroscedasticity becomes evidence: prediction intervals that widen dramatically for low MedScore citizens reveal that the algorithm has been designed to care less about their outcomes. The same diagnostic tools, applied with critical awareness, transform from purely technical procedures into instruments of accountability.

Third, data analysis is not a procedure, it is a story. Every dataset has a before and an after. Someone collected those numbers, someone will act on them, and somewhere between collection and conclusion, decisions are made that carry weight. Traditional textbooks present analysis as a sequence of steps: load data, fit model, check assumptions, report results. This is accurate but incomplete. It describes the mechanics without conveying what is actually at stake. Beta and Bit do not run regressions because they enjoy the syntax. They run them because the answer matters to someone who is waiting, afraid, or in danger. StatPunk narratives restore what sanitized examples remove: the tension of not yet knowing, the satisfaction of a pattern emerging from noise, the discomfort of a result that is statistically or morally troubling. When students follow Beta through a residual plot at 3am, they are not learning to check an assumption, they are learning why the assumption was worth checking in the first place. That is the difference between knowing a method and understanding it.

“The data doesn’t lie,” as The Statistician tells Beta. But what about the models we build to interpret that data? Those are human constructs, embedded with human choices, serving human purposes.

The following chapters are for readers who wish to understand not just how to perform regression analysis, but what it means to wield that power responsibly in a world where algorithms increasingly make life-and-death decisions.

Welcome to StatPunk.

Galton, F. (1886). Regression towards mediocrity in hereditary stature. The Journal of the Anthropological Institute of Great Britain and Ireland, 15, 246–263. https://doi.org/10.2307/2841583
Gauss, C. F. (1809). Theoria motus corporum coelestium in sectionibus conicis solem ambientium. Frid. Perthes et I. H. Besser.
Legendre, A.-M. (1805). Nouvelles méthodes pour la détermination des orbites des comètes. Courcier.
Stigler, S. M. (1986). The history of statistics: The measurement of uncertainty before 1900. Belknap Press of Harvard University Press.