2026-10-18

The Question

-Some countries emit a lot of CO₂ per person, others much less.
-Question: Do richer countries produce more CO₂ per person?
-Data: Our World in Data CO₂ dataset, countries in 2022. -Source: Our World in Data, CO₂ and Greenhouse Gas Emissions dataset. github.com/owid/co2-data

The Data

Linear Regression

Lets fit a straight line through the data:

\[ y = \beta_0 + \beta_1 x + \varepsilon \] \(y\) = CO₂ per person \(x\) = GDP per person \(\beta_1\) = Slope, how much \(y\) changes when \(x\) goes up by one

Now we need to find \(\beta_1\) and to do that we use this function: \[ \hat\beta_1 = \frac{\sum (x_i - \bar x)(y_i - \bar y)}{\sum (x_i - \bar x)^2} \] The top of the fraction measures a countries CO₂ and GDP per person against the average \(\bar{x}\) and \(\bar{y}\). The bottom of the fraction measures how far each country is away from the average GDP. Dividing these values gives us the slope of our regression line.

How good is the fit?

Now that we have a slope for our regression line we need to test how much of the data the line explains.

\[ R^2 = 1 - \frac{\sum (y_i - \hat y_i)^2}{\sum (y_i - \bar y)^2} \] - \(R^2 = 0\): the line explains nothing
- \(R^2 = 1\): the line explains everything

Essentially the higher \(R^2\) is, the less variation there is for other variables to explain.

R Code

co2 <- co2_data%>%
  filter(!is.na(iso_code), !str_starts(iso_code, "OWID"), year == 2022) %>%
  mutate(gdp_per_person = gdp / population) %>%
  drop_na(gdp_per_person, co2_per_capita, energy_per_capita)
#Prepares data keeping only 2022 and makes a GDP per person column

fit <- lm(log10(co2_per_capita) ~ log10(gdp_per_person), data = df)
summary(fit)
#This is how we find the regression line, summary(fit) gives us the intercept, slope, and R^2

ggplot(df, aes(gdp_per_person, co2_per_capita)) +
  geom_point() +
  geom_smooth(method = "lm") +
  scale_x_log10() + scale_y_log10()

Regression Line

Slope = 1.04, \(R^2\) = 0.82

3D View

log is used here in order to prevent the data from bunching up due to many countries having a low GDP but some countries have a very high GDP. Drag to rotate. Hover to see each country. Richer countries use more energy, which produces more CO₂.

What Did We Learn?

  • Yes, richer countries emit more CO₂ per person.
  • The slope is about 1.04: a country that has 10 times higher GDP will use about 10 times more CO₂ per person.
  • GDP alone explains about 82% of the differences between countries.
  • The 3D plot shows why, higher GDP means more energy used which emits higher levels of CO₂
  • Limitation: this shows a relationship, not cause and effect. Countries that use clean energy (like Sweden or France) emit less than their income predicts.