Session 5: Practice

Of many indicators, which few actually carry the signal?

Thierry Warin, PhD

HEC Montréal

Outline · The workshop

  1. Ninety minutes
  2. Before you start
  3. Test the paper — 25 min
  4. What to look for
  5. Apply to your own angle — 30 min
  6. Break one assumption — 15 min
  7. Write it down — 20 min
  8. Submitting
  9. What loses marks
  10. Two-minute report
  11. After class, if you want it

What session 5 is for

The mathematics

  • Say how stepwise (AIC), ridge, the lasso and the elastic net each automate model selection
  • Say in plain words what ridge, the lasso and the elastic net each do to the coefficients
  • Say what the elastic net adds when predictors are correlated
  • Apply soft-thresholding by hand to a small example

The Python

  • Standardise before penalising, with StandardScaler inside a pipeline
  • Fit Ridge, Lasso, ElasticNet, knowing that scikit-learn calls \(\lambda\) alpha
  • Choose \(\lambda\) with RidgeCV, LassoCV, ElasticNetCV
  • Read a coefficient path and a cross-validation curve

The international business

  • Choose among 56 candidate determinants of bilateral FDI
  • Say why a variable the lasso dropped is not thereby irrelevant
  • Report a penalised model honestly, including what selection did

Your Python so far

Everything you need to type is on one sheet — how to start Python in VS Codium on your platform, how to make a file and run it, the DataFrame basics, and every name from sessions 1 to 5, each with a line showing it in use.

Python Cheatsheet · Session 05 (PDF) · in the repository at 05-…/PYTHON-CHEATSHEET.pdf

One sheet per package, functions explained with pictures: pandas · NumPy · matplotlib · scikit-learn · statsmodels · SciPy

Print it, or keep it open beside the editor. Nothing on it is examinable; all of it is assumed.

Practice

Of many indicators, which few actually carry the signal?

Ninety minutes

00–25 Test the paper on the same design, two decades later
25–55 Apply the method, to your own angle
55–70 Break one assumption, deliberately
70–90 Write, and report 250 words, then two minutes to the room

The presenter is drawn at random when your group is called. All three of you prepare.

Before you start

Everyone pushes at least once. Replace XX with your group number — group 07 uses group-07.

git checkout -b group-XX
mkdir -p groups/A2026/group-XX/session-05      # macOS and Linux
git checkout -b group-XX
mkdir groups/A2026/group-XX/session-05         # Windows — no -p

PowerShell’s mkdir creates the intermediate folders already, and rejects -p. The git log is the participation record. It is not a formality.

1 · Test the paper — 25 min

Blonigen and Piger ran Bayesian model averaging over 56 candidate determinants of bilateral FDI in 2000, and found about sixteen that mattered. You have the same 56 candidates for 2019.

import numpy as np, qmib

fdi = qmib.load("fdi")
cov = [c for c in fdi.columns if c not in ("parent", "host", "year", "fdi_stock_musd")]

d = fdi[fdi.fdi_stock_musd > 0].dropna(subset=cov)   # the log-levels sample
y = np.log(d.fdi_stock_musd)

Fit the lasso with \(\lambda\) chosen by cross-validation. Compare what it keeps with the paper’s table 3. Which of their survivors survive for you? Which of their rejects come back?

Standardise inside the pipeline, not before the split. A penalty on \(\beta_j\) is otherwise a penalty on your choice of units.

Paper: Blonigen & Piger (2014), Determinants of foreign direct investment, CJE 47(3) · 10.1111/caje.12091 · data: dictionary

What to look for

  • The paper’s gravity block — parent GDP, host GDP, distance — should be immovable. If it is not, something is wrong with your pipeline, not with the paper.
  • The paper found host institutions near zero. Check yours.
  • Watch host_is_tax_haven. The paper gave it an inclusion probability of 4%. Look at what it does in 2019, and think about why.

A result that disagrees with the paper and is diagnosed earns full marks. One you do not attempt earns none. “It did not work” is not a diagnosis: where did it stop, and what did you check?

2 · Apply to your own angle — 30 min

core = qmib.load("core")
mine = qmib.load("angle_c_country")     # your angle — see your dictionary
df   = core.merge(mine, on=["geo", "time"], how="inner")

Fit the session’s method on your data, and report what the lecture said to report — in the units of your own variables.

A coefficient without units is not a finding.

3 · Break one assumption — 15 min

Every method in this course rests on something.

Find the assumption this one leans on hardest. Break it deliberately. Record what happened to your answer.

Candidates, if you want one: drop the standardisation · refit on a bootstrap resample and see whether the selected set is the same · keep the zero-FDI pairs instead of logging them away · swap the lasso for the elastic net and watch the correlated pairs come back together.

This is the part that carries the marks. A group that shows how its result falls apart understands it; a group that only shows it holding does not yet know.

4 · Write it down — 20 min

250 words in your submissions folder:

  • What you found, in units
  • Which assumption you broke, and what it did
  • What this result does not license you to claim

And the standing rule: one LLM output you identified as wrong, and how you established that.

Submitting

git add groups/A2026/group-XX/session-05
git commit -m "Session 05 practice — group XX"
git push -u origin group-XX

Deliverable. A penalised fit on your own angle: the path, the chosen \(\lambda\), what survived, and what that does not license you to claim.

What loses marks

  • Penalising unstandardised predictors
  • Standardising before the cross-validation split
  • Reporting the selected set as “the variables that matter”
  • Reporting post-selection p-values with no caveat
  • Reading a dropped variable as evidence of no effect
  • Comparing your 2019 result with the paper’s 2000 result as though the samples were the same

And everywhere in this course: an association described in causal language.

Two-minute report

One number with its units and its uncertainty
One assumption the one you broke, and what happened
One limit what you cannot claim from this

Listen for traceable evidence, not confidence of delivery.

After class, if you want it

The QMIB Lab has a knowledge check on what you have just done: warin.ca/qmib-labs

Optional, never a prerequisite for the next lecture, and never marked for correctness. A completed report counts because attempting it is the engagement being measured — it is one of the three routes to the participation mark.

What is required before the next session: the article, the session dataset loaded once, and the self-check. That is the pre-session deck, not this.