How does it work

\[ Y = \beta_0 + \beta_1 X + \epsilon \]

This equation is used to create a line. That line is the minimized sum of squares of this equation, commonly referred to as “fitting the line”.

\[ \begin{align*} & Y \text{ represents the dependent variable} \\ & \beta_0 \text{ is the intercept} \\ & \beta_1 \text{ is the slope} \\ & X \text{ represents the independent variable} \\ & \epsilon \text{ represents the error (there are several different types)} \end{align*} \]

Basic Example Data

Basic Example Explained

This graph shows a fitted line that results from the simple linear regression method. In this example:

\[ \begin{align*} & \beta_0 \text{, the intercept, = 26.28} \\ & \beta_1 \text{, the slope, = -0.17} \\ & \epsilon \text{, the error, = 13.73} \end{align*} \]

As this data is random, it makes sense that this relationship is not very robust.

Economics Example

data(economics)
plot_ly(x = ~economics$pce, y = ~economics$unemploy, type = 'scatter',
        mode = 'markers', width = 600, height = 300) %>% 
  layout(title = "Personal Consumption versus Unemployed Workers", 
         xaxis = list(title = "Unemployed Workers"), 
         yaxis = list(title = "Personal Consumption"))

Economics Example with Fitted Line

data(economics)
lm_fit <- lm(economics$unemploy ~ economics$pce)
plot_ly(x = ~economics$pce, y = ~economics$unemploy, type = 'scatter',
        mode = 'markers', width = 800, height = 300) %>% 
  layout(title = "Personal Consumption versus Unemployed Workers", 
         xaxis = list(title = "Unemployed Workers"), 
         yaxis = list(title = "Personal Consumption")) %>%
  add_lines(x = economics$pce, y = predict(lm_fit),
            line = list(color = '#FF7F7F'),
            name = "Linear Regression Fit")

Economics Example Explained

This graph shows a fitted line that results from the simple linear regression method. In this example:
\[ \begin{align*} & \beta_0 \text{, the intercept, = 5571.14} \\ & \beta_1 \text{, the slope, = 0.46} \\ & \epsilon \text{, the error, = 2086.07} \end{align*} \]
This means that for every 1 unit increase in unemployed workers, personal consumption increases 0.46

Economics Example Continued

\[ \begin{align*} & \beta_1 \text{, the slope, = 10.18} \\ \end{align*} \]
For every 1 thousand increase in population, personal consumption increases $10.18B.

Considering Correlation vs. Causation

\(R^2\) is a measure of how much of the variation in the dependent variable can be explained by the independent variable. The closer it is to 1, the more causation it has.

In considering the previous two examples:

The \(R^2\) of population vs. pce = 0.9746469.

The \(R^2\) of unempoyment vs. pce = 0.3776319.

This shows how the first interaction has more causation between the two as compared to the second interaction.