R × Python

Online textbook companion

Regression
with R & Python

Description, Prediction, and Causal Analysis in Social Science and Medicine

Per Johansson and Jiajing Sun

One organising principle

Start with the research question. Then choose the design, model, assumptions, and code.

Endorsements

“This is a comprehensive and up-to-date introduction to regression, one of our most powerful econometric tools.”

Joshua AngristMITNobel laureate in Economic Sciences, 2021
Read full endorsement from Joshua Angrist

This is a comprehensive and up-to-date introduction to regression, one of our most powerful econometric tools. The presentation is self-contained, with a concise overview of relevant stats, math, and an accessible introduction to two modern open-source programming languages. In combination with crystal-clear videos, the book is sure to be a hit with students and practitioners alike.

“A timely book that teaches not only how to analyse data, but how data become knowledge.”

Wolfgang Karl HärdleHumboldt-Universität zu BerlinProfessor of Statistics
Read full endorsement from Wolfgang Karl Härdle

Regression with R and Python is a wonderful and inspiring guide to learning from data rather than merely processing it. It shows how the proliferation of data becomes valuable only when statistical reasoning transforms information into knowledge. Its great strength is the learning path: from description and visualization, through prediction, to causal reasoning and credible empirical conclusions. R and Python turn this path into an active experience in which readers reproduce, modify, and extend real analyses. The book thereby connects data analytics with understanding: computation serves interpretation, rather than replacing it. Different learning depths—from intuitive applications to advanced technical material—allow readers to construct their own route through the subject. A timely book that teaches not only how to analyse data, but how data become knowledge.

“This is a rare regression textbook that treats description, prediction, and causal inference as genuinely distinct tasks requiring different assumptions, rather than three flavours of the same exercise.”

Oliver LintonUniversity of CambridgeFellow of the British Academy
Read full endorsement from Oliver Linton

Johansson and Sun have written a regression textbook that does something genuinely useful: it insists, from Chapter 1 onward, that the right way to analyse data depends on whether the question is descriptive, predictive, or causal, and it carries that distinction through every subsequent chapter rather than treating it as a one-off framing device. The nonparametric regression material is a particular strength. The exposition moves cleanly from the regressogram's intuitive local-averaging logic through kernel and local polynomial regression to the bias-variance trade-off and the subtleties of inference under smoothing, with the more technical asymptotics cleanly separated into a companion appendix so the main text stays accessible. The connections to regression discontinuity design and to robust HAC and self-normalized inference are handled with real care, reflecting the authors' own research in these areas. I would be glad to recommend this book to students and applied researchers who want to understand not just how to run a regression, but what it can and cannot tell them.

How the book is organised

Three kinds of research question

Every chapter uses the same reading structure: guide, concepts, methods and formulas, empirical case, diagnostics, extensions, and exercises with code.

  1. DescriptionPlots, correlation, regression, and R²
  2. PredictionValidation, regularisation, and trees
  3. CausationPotential outcomes and research designs

What you will find here

Fourteen online chapters, a protected web edition of the teaching slides, a companion lecture course, original chapter quizzes, a complete learning map, and public R and Python code organised around the printed book.

Quizzes and the learning map are listed under Learning; the R and Python companion is under Code & QR.