ggplot(modelData, aes(x = wealth, y = lib_dem)) +geom_point() +geom_smooth(method ="lm", color ="#E48957", se =FALSE) +labs(x ="GPD per capita", 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(label = scales::label_dollar(suffix ="k")) +labs(title ="Wealth and Democracy, 2019",x ="GPD per capita", 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 = a + bX\)
\(Y\) is the outcome variable
\(X\) is the explanatory variable
\(a\) is the intercept: the predicted value of \(Y\) when \(X\) is equal to 0
\(b\) 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} = a + b \times X\)
\(\hat{Y} = 0.13 + 0.12 \times X\)
Linear Model: Interpretation
\(\hat{Y} = a + b \times X\) \(\hat{Y} = 0.13 + 0.12 \times X\)
What is the interpretation of our estimate of \(a\)?
\(b\) 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 \(a\) and \(b\) as follows:
\(\hat{Y} = 9 + 1.60*{YrsEdu}\)
1. Interpret \(a\) and \(b\)
2. What is the predicted hourly wage for those with 10 years of education?
Next step
Linear model with one predictor: \(Y = a + bX\)
For any given data…
How do we figure out what the best values are for \(a\) and \(b\)??