Regression

Week 7 lecture

Open full screen ↗ Week 7 workshop → F full screen · S speaker notes · ? shortcuts

Explore it: find the line of best fit yourself

Each dot is a country in 2022: how much light it emits at night per person (from satellites) against its GDP per capita, both on a log scale. The red line is yours. Drag its two handles, or drag the line itself, and watch the residuals (blue) and their sum of squares. OLS is simply the one line that makes that sum as small as possible. Try to get within 1% of it before you press "Show OLS".

drag the handles or the line · tap a dot

Residual sum of squares

Your RSS–
Minimum–
Your R²–
0↑ OLSTSS (flat line)

RSS against slope

The curve is the lowest RSS reachable at each slope (lines through the average point). Its bottom is the OLS slope. Drag along it to choose a slope.

Your line

your line OLS residual mean of y

RSS = Σ(yᵢ − ŷᵢ)², TSS = Σ(yᵢ − ȳ)², R² = 1 − RSS/TSS. With "Squares" on, each square has side equal to a residual, so its area is that residual squared: OLS minimises their total area. Data: 183 countries, the same file as the Week 7 workshop. Nighttime lights from the harmonised DMSP/VIIRS series (Li et al. 2020, Scientific Data, CC BY 4.0), summed within Natural Earth borders and divided by population; GDP per capita (PPP, constant 2021 international $) and population from the World Bank. An association across countries, not a causal effect.