Simple linear regression I

Quantitative Methods for
International Politics

IPOL 3270 • Fall 2026

September 27, 2026

Plan for today

Relationships between variables

Correlation

Drawing lines

Lines and regression

Relationships between variables

Why statistics?

  • We want to know the relationships and differences between variables!
  • We want to know if those relationships and differences are “real”

Standard stats classes

Everything in statistics can be done with regression!

  • Sample averages
  • Differences in means
  • Differences in proportions
  • Slopes

Essential parts of regression

Y

Outcome variable

Response variable

Dependent variable

Thing you want to
explain or predict

X

Explanatory variable

Predictor variable

Independent variable

Thing you use to
explain or predict Y

Your turn #1: Identify variables

  • A study examines the effect of smoking on lung cancer
  • Researchers predict genocides by looking at negative media coverage, revolutions in neighboring countries, and economic growth
  • You want to see if taking more honors classes in secondary school improves university grades
  • Netflix uses your past viewing history, the day of the week, and the time of the day to guess which show you want to watch next

Two purposes of regression

Prediction

Forecast the future

Focus is on Y

Netflix trying to
guess your next show

Predicting which countries
will have a coup

Explanation

Explain effect of X on Y

Focus is on X

Netflix looking at the effect of the time of day on show selection

Measuring the effect of
foreign aid on democratization

Basic steps for regression

  1. Plot X and Y
  2. Check how strongly they move together
  3. Draw a line that approximates the relationship (and that would plausibly work for data not in the sample!)
  4. Find mathy parts of the line
  5. Interpret the math

Fertility and life expectancy

Do countries with longer life expectancy have lower fertility rates?

library(moderndive)

UN_data_ch5 <- un_member_states_2024 |>
  select(
    iso,
    country,
    life_exp = life_expectancy_2022,
    fert_rate = fertility_rate_2022,
    obes_rate = obesity_rate_2016
  ) |>
  na.omit()
  • fert_rate: Expected number of children born per woman (Y)
  • life_exp: Average life expectancy in years (X)
  • obes_rate: % of adults who are obese (save for later!)
  • 181 countries

Fertility and life expectancy

iso country life_exp fert_rate
AFG Afghanistan 53.65 4.3
ALB Albania 79.47 1.4
DZA Algeria 78.03 2.7
AGO Angola 62.11 5.0
ATG Antigua and Barbuda 77.80 1.6
ARG Argentina 78.31 1.9
ARM Armenia 76.13 1.6
AUS Australia 83.09 1.6
AUT Austria 82.27 1.5
AZE Azerbaijan 74.15 1.6

Plot X and Y

Correlation

Univariate vs. bivariate

Univariate summaries

Describe one variable

Mean, median, standard deviation, minimum, maximum, etc.

Bivariate summaries

Describe how two variables are related

Correlation!

Correlation coefficient (\(r\))

A number that measures the strength and direction of the linear relationship between two numeric variables

Written as \(r\); ranges between −1 and 1

−1

Perfect negative relationship: as X goes up, Y goes down

0

No relationship: X and Y move independently

+1

Perfect positive relationship: as X goes up, Y goes up

What do correlations look like?

Correlation only measures lines

Clear relationship, but r ≈ 0
because it’s not a straight line!

Guess the correlation!

https://www.guessthecorrelation.com/

How close can you get?

Fertility and life expectancy

What’s your guess?

UN_data_ch5 |>
  get_correlation(
    fert_rate ~ life_exp
  )
# A tibble: 1 × 1
     cor
   <dbl>
1 -0.812
# Or with regular {dplyr}
UN_data_ch5 |>
  summarize(
    r = cor(fert_rate, life_exp)
  )

Interpreting correlation

r = -0.812

Fairly strong negative relationship!

Countries with higher life expectancy tend to have lower fertility rates

Rough guidelines (though these are subjective!):

  • ±0.1–0.3: Weak
  • ±0.3–0.7: Moderate
  • ±0.7–1.0: Strong

What correlation doesn’t tell us

How much does fertility change when life expectancy goes up by one year?

Correlation only tells us direction and strength, not size!

What does life expectancy do to fertility?

Correlation isn’t causation! Wealth, education, health care, etc. probably drive both

To measure the size of the relationship, we need a line

Drawing lines

Cookies and happiness

cookies happiness
1 0.5
2 2.0
3 1.0
4 2.5
5 3.0
6 1.5
7 2.0
8 2.5
9 2.0
10 3.0

Residuals

Residual = observed value − value on the line

\[ \text{residual} = y - \widehat{y} \]

The line’s “error” or “lack of fit” for each observation

Good lines have small residuals

Which line is best?

Which line is best?

  1. Square each residual
  2. Add them all up

Ordinary least squares (OLS)

The “best-fitting” line is the one with the smallest sum of squared residuals

Lines and regression

Drawing lines with math

\[ y = mx + b \]

\(y\) A number
\(x\) A number
\(m\) Slope (\(\frac{\text{rise}}{\text{run}}\))
\(b\) y-intercept

Slopes and intercepts

\[ y = 2x - 1 \]

\[ y = -0.5x + 6 \]

Draw some lines!

Sketch out the lines I give you in class!

Drawing lines with stats

\(y = mx + b\) \(\widehat{y} = b_0 + b_1 x\)
\(y\) Outcome variable (Y) \(\widehat{y}\)
\(x\) Explanatory variable (X) \(x\)
\(m\) Slope \(b_1\)
\(b\) y-intercept \(b_0\)

The ^ hat on \(\widehat{y}\) is called a “hat”—we say “y hat”

It means it’s a fitted value, or the value on the line

Fertility and life expectancy

\[ \widehat{y} = b_0 + b_1 x \]

 

\[ \begin{aligned} &\widehat{\text{fert}\_\text{rate}} = \\ &b_0 + b_1 \times \text{life}\_\text{exp} \end{aligned} \]

Building models in R

name_of_model <- lm(<Y> ~ <X>, data = <DATA>)
  • lm() = linear model
  • <Y> ~ <X> is a model formula (same as in get_correlation()!)
library(moderndive)

# Make the model
name_of_model <- lm(..., data = BLAH)

# Coefficients in a nice table
get_regression_table(name_of_model)

# Fitted values and residuals for 
# every observation
get_regression_points(name_of_model)

Cookies and happiness

\[ \begin{aligned} &\widehat{\text{happiness}} = \\ &b_0 + b_1 \times \text{cookies} \end{aligned} \]

cookies_model <- lm(
  happiness ~ cookies,
  data = cookies
)

Cookies and happiness

get_regression_table(cookies_model)
# A tibble: 2 × 7
  term      estimate std_error statistic p_value lower_ci upper_ci
  <chr>        <dbl>     <dbl>     <dbl>   <dbl>    <dbl>    <dbl>
1 intercept    1.1       0.47       2.34   0.047    0.016    2.18 
2 cookies      0.164     0.076      2.16   0.063   -0.011    0.338

Translating results to math

term estimate
intercept 1.100
cookies 0.164

\[ \begin{aligned} &\widehat{\text{happiness}} = \\ &b_0 + b_1 \times \text{cookies} \end{aligned} \]

\[ \begin{aligned} &\widehat{\text{happiness}} = \\ &1.1 + 0.164 \times \text{cookies} \end{aligned} \]

Template for the slope

A one unit increase in X is associated with a \(b_1\) increase (or decrease) in Y, on average

\[ \widehat{\text{happiness}} = 1.1 + 0.164 \times \text{cookies} \]

On average, eating one more cookie is associated with a 0.164 increase in happiness

Template for the intercept

\(b_0\) is the average value of
Y when X is 0

\[ \widehat{\text{happiness}} = 1.1 + 0.164 \times \text{cookies} \]

For someone who eats 0 cookies, the average level of happiness would be 1.1

Observed vs. fitted values

● Observed value (\(y\)): Actual happiness = 3
■ Fitted value (\(\widehat{y}\)): \(1.1 + 0.164 \times 5 = 1.918\)
↓ Residual (\(y - \widehat{y}\)): \(3 - 1.918 = 1.082\)

Residuals for every person

get_regression_points(cookies_model)
ID happiness cookies happiness_hat residual
1 0.5 1 1.264 -0.764
2 2.0 2 1.427 0.573
3 1.0 3 1.591 -0.591
4 2.5 4 1.755 0.745
5 3.0 5 1.918 1.082
6 1.5 6 2.082 -0.582
7 2.0 7 2.245 -0.245
8 2.5 8 2.409 0.091
9 2.0 9 2.573 -0.573
10 3.0 10 2.736 0.264

Fertility and life expectancy

\[ \begin{aligned} &\widehat{\text{fert}\_\text{rate}} = \\ &b_0 + b_1 \times \text{life}\_\text{exp} \end{aligned} \]

demographics_model <- lm(
  fert_rate ~ life_exp,
  data = UN_data_ch5
)

Fertility and life expectancy

get_regression_table(demographics_model)
# A tibble: 2 × 7
  term      estimate std_error statistic p_value lower_ci upper_ci
  <chr>        <dbl>     <dbl>     <dbl>   <dbl>    <dbl>    <dbl>
1 intercept   12.6       0.545      23.1       0   11.5     13.7  
2 life_exp    -0.137     0.007     -18.6       0   -0.152   -0.123

(We’ll learn what all those other columns mean later in the semester!)

Translating results to math

term estimate
intercept 12.599
life_exp -0.137

\[ \begin{aligned} &\widehat{\text{fert}\_\text{rate}} = \\ &b_0 + b_1 \times \text{life}\_\text{exp} \end{aligned} \]

\[ \begin{aligned} &\widehat{\text{fert}\_\text{rate}} = \\ &12.6 + (-0.137) \times \text{life}\_\text{exp} \end{aligned} \]

Template for the slope

A one unit increase in X is associated with a \(b_1\) increase (or decrease) in Y, on average

\[ \widehat{\text{fert}\_\text{rate}} = 12.6 + (-0.137) \times \text{life}\_\text{exp} \]

On average, a one-year increase in life expectancy is associated with a 0.137 decrease in the fertility rate

Use the right language!

“Associated”

Correlation isn’t causation! Adding a year of life to everyone in a country won’t make people have fewer kids. Wealthier, healthier, more educated countries tend to have both higher life expectancy and lower fertility

“On average”

Two countries with life expectancies one year apart won’t have fertility rates exactly 0.137 apart. Some are above the line, some below

Template for the intercept

\(b_0\) is the average value of
Y when X is 0

\[ \widehat{\text{fert}\_\text{rate}} = 12.6 + (-0.137) \times \text{life}\_\text{exp} \]

In a country where life expectancy is 0 years, the average fertility rate would be 12.6

A life expectancy of 0 is actually impossible, so this intercept has no practical meaning—it’s just where the line crosses the y-axis!

Correlation vs. slope

Correlation

r = -0.812

Strength and direction of the relationship

Always between −1 and 1; no units

Slope

\(b_1\) = -0.137

Size of the relationship

Measured in units of Y per one unit of X

They’ll always have the same sign, but usually not the same value!

Observed vs. fitted values

● Observed value (\(y\)): Bosnia’s actual fertility rate = 1.3
■ Fitted value (\(\widehat{y}\)): \(12.599 + (-0.137) \times 77.98 = 1.894\)
↓ Residual (\(y - \widehat{y}\)): \(1.3 - 1.894 = -0.594\)

Residuals for every country

get_regression_points(demographics_model)
iso fert_rate life_exp fert_rate_hat residual
AFG 4.3 53.65 5.234 -0.934
ALB 1.4 79.47 1.689 -0.289
DZA 2.7 78.03 1.887 0.813
AGO 5.0 62.11 4.072 0.928
ATG 1.6 77.80 1.918 -0.318
ARG 1.9 78.31 1.848 0.052
ARM 1.6 76.13 2.148 -0.548
AUS 1.6 83.09 1.192 0.408

Your turn #2

Does a country’s obesity rate predict its fertility rate?

  1. Make a scatterplot of fert_rate and obes_rate
  2. Find the correlation between the two with get_correlation()
  3. Fit a model with lm() and look at the coefficients with get_regression_table()
  4. Interpret the slope and the intercept