2024-04-04

1

Definition of Linear Regression

  • “Linear regression analysis is used to predict the value of a variable based on the value of another variable.” IBM https://www.ibm.com/topics/linear-regression

  • Can utilize more than one variable

  • Simple Linear Regression only uses one variable to predict another

  • One independent variable and one dependent variable

Least Squares Regression Line Equation

Least Squares Regression Line Equation (continued)

  • \(\bar{x}={\sum x \over n}\)

  • \(\bar{y}={\sum y \over n}\)

  • These equations together with the equations on the previous slide show how to calculate simple linear regression

  • The fitted line is a prediction of what the y value would be given an x value

  • The x value is the independent variable, the y value is the dependent variable

Example of Line of Best Fit (Plotly)

Here is an example of a line of best fit using the wait time between eruptions of Old Faithful to predict how long the geyser will erupt.

Example of Line of Best Fit (ggplot)

Here is the Old Faithful data presented again this time in ggplot. The black dots represent the data points, with the blue line being the line of best fit. The gray area around the line is the confidence band where y values are likely to be found.

Core Samples

In this plot of core samples, the perimeter of pores is measured against permeability. The confidence band is larger, meaning that perimeter is a relatively weaker predictor of permeability. However, perimeter would predict the area of the pores well, and this is demonstrated by the color gradient getting lighter as one travels across the x axis.

Core Sample Variable Swap

Now, variables will be swapped on the core sample plot. The perimeter of the pores will remain on the x axis, while the area of the pores will be plotted on the y axis. Note how the confidence band shrinks compared to the previous slide. Here is the code for this plot which can be found on the next slide.

csvs <- ggplot(data = rock, aes(x=peri, y=area)) + 
  geom_point(aes(color=perm)) + geom_smooth(formula = 'y~x', 
  method="lm")+ggtitle("Core Samples")+xlab("Perimeter of Pores")+
  ylab("Area of Pores")
fig <- ggplotly(csvs)

Core Sample Variable Swap