Modeling

October 27, 2026

Modeling

  • Use models to explain the relationship between variables and to make predictions
  • Explaining relationships (usually interested in causal relationships, but not always)
    • Does oil wealth impact regime type?
  • Predictive modeling
    • Where is violence most likely to happen in [country X] during their next election?
    • Is this email spam?

Modeling

Modeling

Example: GDP per capita and Democracy

Pull in the VDEM Data


What is this code doing?

library(vdemdata)

modelData <- vdem |>
  filter(year == 2019) |> 
  select(
    country = country_name, 
    lib_dem = v2x_libdem, 
    wealth = e_gdppc) |>
  mutate(log_wealth = log(wealth))

glimpse(modelData)
Rows: 179
Columns: 4
$ country    <chr> "Mexico", "Suriname", "Sweden", "Switzerland", "Ghana", "So…
$ lib_dem    <dbl> 0.428, 0.583, 0.866, 0.860, 0.606, 0.623, 0.753, 0.246, 0.1…
$ wealth     <dbl> 34.308, 24.668, 106.746, 109.451, 10.820, 24.104, 88.837, 1…
$ log_wealth <dbl> 3.535379, 3.205507, 4.670452, 4.695477, 2.381396, 3.182378,…

A Note on V-Dem’s GDP Measure


  • e_gdppc is not measured in dollars
  • It is a model-based index that combines many GDP sources (World Bank, Maddison, Penn World Tables, etc.) going back to 1789 (Fariss et al. 2022)
  • In 2019 the US scores about 144 and India about 16
    • Not dollars, but the ratios are meaningful: the US is about 9× as wealthy per person as India
  • Because we model log GDP, we interpret results as percentage changes (e.g., doubling GDP), which doesn’t depend on the units
  • Lesson: always check the codebook before putting a dollar sign on a variable!

Plot the Relationship

Plot the Relationship

Plot the Relationship


ggplot(modelData, aes(x = wealth, y = lib_dem)) +
  geom_point() +
  geom_smooth(method = "lm", color = "#E48957", se = FALSE) +
  labs(x = "GDP per capita (V-Dem index)", y = "Liberal Democracy Index") +
  theme_bw()

Using the Scales Package

Using the Scales Package


ggplot(modelData, aes(x = wealth, y = lib_dem)) +
  geom_point() +
  geom_smooth(method = "lm", color = "#E48957", se = FALSE) +
  scale_x_log10() +
  labs(
    title = "Wealth and Democracy, 2019",
    x = "GDP per capita (V-Dem index, log scale)", 
    y = "Liberal Democracy Index") +
  theme_bw()

Models as Functions

  • We can represent relationships between variables using functions
  • A function is a mathematical concept: the relationship between an output and one or more inputs
    • Plug in the inputs and receive back the output
  • Example: The formula \(y = 3x + 7\) is a function with input \(x\) and output \(y\).
    • If \(x\) is \(5\), \(y\) is \(22\),
    • \(y = 3 \times 5 + 7 = 22\)

Quant Lingo


  • Response variable: Variable whose behavior or variation you are trying to understand, on the y-axis in the plot
    • Dependent variable
    • Outcome variable
    • Y variable
  • Explanatory variables: Other variables that you want to use to explain the variation in the response, on the x-axis in the plot
    • Independent variables
    • Predictors


Linear model with one explanatory variable…

  • \(y = b_0 + b_1 x\)
  • \(y\) is the outcome variable
  • \(x\) is the explanatory variable
  • \(b_0\) is the intercept: the predicted value of \(y\) when \(x\) is equal to 0
  • \(b_1\) is the slope of the line (remember rise over run!)

Quant Lingo


  • Predicted value: Output of the model function
    • The model function gives the typical (expected) value of the response variable conditioning on the explanatory variables
    • We often call this \(\hat{y}\) to differentiate the predicted value from an observed value of \(y\) in the data
  • Residuals: A measure of how far each case is from its predicted value (based on a particular model)
    • Residual = Observed value (\(y\)) - Predicted value (\(\hat{y}\))
    • How far above/below the expected value each case is

Residuals

Linear Model

\(\hat{y} = b_0 + b_1 \times x\)

\(\hat{y} = 0.01 + 0.13 \times x\)

Linear Model: Interpretation


\(\hat{y} = b_0 + b_1 \times x\)
\(\hat{y} = 0.01 + 0.13 \times x\)

What is the interpretation of our estimate of \(b_0\)?


\(\hat{y} = 0.01 + 0.13 \times 0\)
\(\hat{y} = 0.01\)

\(b_0\) is our predicted level of democracy when log GDP per capita is 0 (i.e., when the GDP index equals 1).

Linear Model: Interpretation


\(\hat{y} = b_0 + b_1 \times x\)
\(\hat{y} = 0.01 + 0.13 \times x\)

What is interpretation of our estimate of \(b_1\)?


\(\hat{y} = b_0 + \frac{Rise}{Run} \times x\)
\(\hat{y} = b_0 + \frac{Change\ y}{Change\ x} \times x\)

Linear Model: Interpretation


\(b_1 = \frac{Change\ y}{Change\ x}\)
\(0.13 = \frac{Change\ y}{Change\ x}\)
\(Change\ y = 0.13 \times Change\ x\)


When \(Change\ x = 1\):
\(Change\ y = 0.13\)


\(b_1\) is the predicted change in \(y\) associated with a ONE unit change in \(x\).

Linear Model: Interpretation

Linear Model: Interpretation

Linear Model: Interpretation

Linear Model: Interpretation


Is this the causal effect of GDP per capita on liberal democracy?


No! It is only the association…


To identify causality we need other methods (beyond the scope of this course).

Your Task


An economist is interested in the relationship between years of education and hourly wages. They estimate a linear model with estimates of \(b_0\) and \(b_1\) as follows:


\(\hat{y} = 9 + 1.60 \times YrsEdu\)


1. Interpret \(b_0\) and \(b_1\)
2. What is the predicted hourly wage for those with 10 years of education?

Next step


  • Linear model with one predictor: \(y = b_0 + b_1 x\)
  • For any given data…
  • How do we figure out what the best values are for \(b_0\) and \(b_1\)??