August 24, 2026
Goal: Estimate Democracy score (\(\hat{Y_{i}}\)) of a country given level of GDP per capita (\(X_{i}\)).
Or: Estimate relationship between GDP per capita and democracy.
Fit model using base R lm() with formula syntax
View results with summary()
\[\widehat{Democracy}_{i} = 0.13 + 0.12 * {loggdppc}_{i}\]
Call:
lm(formula = lib_dem ~ log_wealth, data = modelData)
Residuals:
Min 1Q Median 3Q Max
-0.58981 -0.14940 0.04111 0.18360 0.41129
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.008248 0.047553 0.173 0.862
log_wealth 0.129576 0.014481 8.948 5.66e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2171 on 172 degrees of freedom
(5 observations deleted due to missingness)
Multiple R-squared: 0.3176, Adjusted R-squared: 0.3137
F-statistic: 80.07 on 1 and 172 DF, p-value: 5.657e-16
\[\widehat{Democracy}_{i} = 0.13 + 0.12 * {loggdppc}_{i}\]
How do we get the “best” values for the slope and intercept?
Residual for each point is: \(e_i = y_i - \hat{y}_i\)
Least squares regression line minimizes \(\sum_{i = 1}^n e_i^2\).
Why not take absolute value?
What should the slope and intercept be?
\(\hat{Y} = 0 + 1*X\)
What is the sum of squared residuals?
What is sum of squared residuals for \(y = 0 + 0*X\)?
What is sum of squared residuals for \(y = 0 + 0*X\)?
What is sum of squared residuals for \(y = 0 + 2*X\)?
What is sum of squared residuals for \(y = 0 + 2*X\)?
What is sum of squared residuals for \(y = 0 + -1*X\)?
What is sum of squared residuals for \(y = 0 + -1*X\)?
Sum of Squared Residuals as function of possible values of \(b\)
When we estimate a least squares regression, it is looking for the line that minimizes sum of squared residuals
In the simple example, I set \(a=0\) to make it easier. More complicated when searching for combination of \(a\) and \(b\) that minimize, but same basic idea
There is a way to solve for this analytically for linear regression (i.e., by doing math…)
– They made us do this in grad school…
Are democracies less corrupt?
V-Dem includes a Political Corruption Index, which aggregates corruption in a number of spheres (see codebook for details).
The variable name is: v2x_corr : lower values mean less corruption
See started code HERE
Are democracies less corrupt?