Session 3: Before the session

You have fitted a regression. Can it be trusted?

Thierry Warin, PhD

HEC Montréal

Outline · Before class

  1. What to do, and how long it takes
  2. Read the paper
  3. Get BOTH datasets
  4. The course data
  5. Self-check, and what the session will ask of you
  6. Before you run anything

What session 3 is for

The mathematics

  • Derive the least-squares slope, and read “controlling for” as a residual regression
  • Read residuals versus fitted and say what structure it reveals
  • Compute leverage from the hat matrix, and show it sums to \(p\)
  • Separate an outlier from an influential point with Cook’s distance
  • Compare models on AIC, and say why that is not model selection

The Python

  • Fit a simple and a multiple regression with smf.ols, and read .params
  • Pull diagnostics from a fitted model with get_influence()
  • Build the four diagnostic plots yourself rather than calling one function
  • Compare candidate specifications side by side on AIC and BIC
  • Report the comparison as a publication table with qmib.regtable

The international business

  • Quote a slope in units a manager can act on
  • Say why a slope is an association, and what more is needed to call it a cause
  • Say whether a published coefficient survives its own diagnostics
  • Decide what to do about the one country that moves the whole result
  • Refuse a model whose residuals show it has missed the structure

Before the session

You have fitted a regression. Can it be trusted?

What to do, and how long it takes

1 Read the paper 45–60 min
2 Get both datasets — the paper’s, and your own angle 10 min
3 Attempt the self-check 15 min

The lecture assumes all three are done. The practice assumes the data is already cached on your machine.

1 · Read the paper

Amsili, van Es & Schindelbeck (2024), Pedotransfer Functions for Field Capacity, Permanent Wilting Point, and Available Water Capacity

Read for the argument, not for coverage. Annotate four things:

1 The research question, in one sentence
2 The method or design, and why they chose it
3 The strongest single piece of evidence
4 One limitation you would raise as a referee

2 · Get BOTH datasets

The practice uses two: the paper’s data, to reproduce one of its results, and your own angle, to apply the method. Have both before you arrive.

a) The paper’s replication package — Harvard Dataverse

Download it from the terminal — no Dataverse account, no browser. From the repository root:

macOS and Linux

mkdir -p 03-regression-adequacy-and-validity/data/replication && cd 03-regression-adequacy-and-validity/data/replication
curl -L -o replication.zip \
  "https://dataverse.harvard.edu/api/access/dataset/:persistentId/?persistentId=doi:10.7910/DVN/U5DAEP"
unzip -q replication.zip && rm replication.zip && cd -

Windows PowerShell

mkdir 03-regression-adequacy-and-validity/data/replication; cd 03-regression-adequacy-and-validity/data/replication
curl.exe -L -o replication.zip `
  "https://dataverse.harvard.edu/api/access/dataset/:persistentId/?persistentId=doi:10.7910/DVN/U5DAEP"
Expand-Archive replication.zip .; Remove-Item replication.zip; cd -

data/replication/ is git-ignored, so nothing large is committed. Keep the authors’ own structure — do not tidy it.

This deposit is about 220 MB — much the largest in the course. Start the download before you sit down to read, not while the room is waiting for you.

2b · The course data

import qmib

core = qmib.load("core")                # the spine, shared by every group
mine = qmib.load("angle_c_country")     # REPLACE with your own angle

print(core.shape, mine.shape)

Run this before you arrive. It downloads once and caches as parquet, so the practice works whatever the room’s wifi is doing.

angle_c_country is an example, not your angle. Yours is named in RESEARCH-MANDATES.md.

The regression fitted at the top of the lecture — GDP per capita on productivity · everything available: qmib.catalog()

3 · Self-check, and what the session will ask of you

Answer these on paper. If you cannot, that is what the lecture is for.

  1. In one sentence: what does this session’s method let you claim that the previous one did not?
  2. What must be true of your data for it to apply?
  3. Which claim in the paper rests on this method — and how hard does it lean on it?

By the end of the session you should be able to:

  • Fit a simple and a multiple regression, and state the slope in units
  • Read a residuals-versus-fitted plot and say what structure it reveals
  • Diagnose non-constant variance from a scale–location plot
  • Tell an outlier, a leverage point and an influential point apart
  • Use Cook’s distance to find the observations that move the answer
  • Compare candidate models on AIC and BIC, and say why that is not model selection

Arrive with: the paper read and annotated · the replication package unzipped · qmib.load() run at least once · your self-check answers on paper.

Before you run anything

Everything runs in the VS Codium terminal, from the repository root, with the project environment active. Activate it in every new terminal, not only the first:

source .venv/bin/activate        # macOS and Linux
.venv\Scripts\activate           # Windows (PowerShell)

Your prompt must begin with (.venv). Without it python and pip are your system’s, and nothing the course installed is visible to them.

ModuleNotFoundError means the packages went somewhere else, or were never installed. Check the prompt first, then pip install -r requirements.txt — from the repository root, with the environment active. Building the environment from scratch is Session 01, step 1.4.

Session 03: README.md · the lecture: 01-lecture/