February 4, 2024

Linear Regression with True Parameters(LATEX)

\[Y = \beta_0 + \beta_1X + \varepsilon\]

In this equation, \(Y\) is a dependent variable, \(X\) is an independent variable, \(\beta_0\) is the intercept, \(\beta_1\) is the slope, \(\varepsilon\) is the error.

This formula represents the mathematical foundation of Simple Linear Regression. The goal of a simple linear regression is to predict the value of a dependent variable based on an independent variable. The linear relationship between the independent variable and the dependent variable determines the accuracy of the prediction.

Linear Regression with Estimated Values(LATEX)

\[\hat{Y} = b_0 + b_1X\]

In this equation, \(\hat{Y}\) is a predicted or fitted value, \(X\) is an independent variable, \(b_0\) is the estimated intercept, and \(b_1\) is the estimated slope.

This formula is a mathematical representation of the regression line that the Simple Linear Regression model is trying to fit. The coefficients \(b_0\) and \(b_1\) are derived from the data and offer valuable insights into both the magnitude and direction of the linear relationship.

US Arrests Scatter Plots with Fitted Linear Regression Line

We can demonstrate Simple Linear Regression through scatter plots and finding a line that fits the data. Let’s use the US Arrests data to demonstrate. We can determine the correlation between 2 variables and how strongly the data correlates. We will cover the following variables:

  • Assault vs Murder in the 50 states

  • Rape vs UrbanPop in the 50 states

  • Murder vs UrbanPop in the 50 states

Assault vs Murder in the US (ggplot)

The fitted line indicates a strong correlation between Assault and Murder.

## `geom_smooth()` using formula = 'y ~ x'

Rape vs UrbanPop in the US (plotly)

The fitted line indicates a somewhat strong correlation between Rape and Urban Population.

Murder vs UrbanPop in the US (ggplot)

The fitted line does not indicate a strong correlation between Murder and Urban Population.

## `geom_smooth()` using formula = 'y ~ x'

R Code

In order to understand a data set we can use Simple Linear Regression. We can analyze data and transform it into a plot and a linear regression line. The graph in the previous slide was execute by the following code in R.

## ggplot(USArrests, aes(x = Murder, y = UrbanPop)) + #set up data
##    geom_point() + #display data points
##    geom_smooth(method = "lm", se = FALSE, color = "green") + #add line
##    labs(title = "Scatter Plot of Murder vs UrbanPop",
##         x = "Murder",
##         y = "UrbanPop") + #add labels
##    theme_minimal() #theme