R Companion
R Companion
The R Companion is a chapter-by-chapter walkthrough that loads the dataset each chapter is built on, runs the headline analyses the chapter narrative describes, and reproduces the verified numbers in copy-pasteable R code. The full walkthroughs live online at stats.marginoferrormedia.com: searchable, with pre-rendered outputs, and updated whenever the book is corrected. The book’s reasoning stands on its own; the R Companion is there when you want to do the analysis yourself.
What each chapter’s walkthrough covers:
Each walkthrough loads the chapter’s dataset, runs the headline analyses, and reproduces the verified numbers in copy-pasteable R code. Click through to the chapter you want.
- Chapter 1. Why Statistics Matters Now: Flint water data; histogram and ward summary; verification habits.
- Chapter 2. Asking Good Questions: Simple random, stratified, cluster, and systematic sampling compared.
- Chapter 3. Summarizing Data with Numbers: Mean, median, IQR, quartiles, outlier rule on ACS income.
- Chapter 4. Summarizing Data with Pictures: Histograms, boxplots, scatter, correlations, Anscombe’s quartet.
- Chapter 5. Probability: Sensitivity, specificity, PPV, Bayes’ theorem, binomial distribution.
- Chapter 6. Normal Distribution and CLT:
dnorm/pnorm/qnorm, QQ plots, Shapiro–Wilk, CLT simulation. - Chapter 7. Confidence Intervals: CIs by hand and via
t.test()/prop.test(), coverage simulation. - Chapter 8. Hypothesis Testing: t-tests, Cohen’s d, p-hacking simulation.
- Chapter 9. Comparing Groups: Bertrand–Mullainathan reproduction; ANOVA; TukeyHSD; Kruskal–Wallis.
- Chapter 10. Simple Linear Regression:
lm(), coefficients, prediction intervals, residual diagnostics. - Chapter 11. Multiple Regression: Four nested wage-gap models, VIF, coefficient evolution.
Each walkthrough begins with source("_common.R") to load tidyverse and the book’s color palette. Download _common.R if you want the chapter figures to match the book’s look, or replace the source() line with library(tidyverse). The analyses run either way.