2024-10-21

Simple Linear Regression

Simple Linear Regression is a statistical model used to define the relationship between x as an independent variable and y as a dependent variable so that x is a variable that can predict the value of y.

Linear Regression Formula

The linear regression formula is: \[ y = \beta_0 + \beta_1 x + \epsilon \]. This equation denotes three variables, \[ \beta_0 \] as the intercept, \[ \beta_1\ \] as slope, and there is also an error term that can be added to account for as well, \[ \epsilon\ \].

Example of Linear Regression

An example of linear regression would be price of an airbnb based on the square footage. In this example the independent variable, or y is the square footage and the dependent variable x is the price of the airbnb. y is our predictor variable as we can use linear regression on y to predict the price of the airbnb or x.

Plotly Plot Of Linear Regression

Using the “mtcars” dataset from R Studio I will perform linear regression to create a plot using horsepower to predict the mpg of a car.

The equation I will use is: \[ \text{mpg} = \beta_0 + \beta_1 \times \text{hp} + \epsilon \]

Using GGPlot On MTCars Linear Regression

I will apply the same linear regression to MTCars and create a ggplot instead of a plotly plot.

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

Another Example Of GGPlot Linear Regression Using Trees Dataset

In this example of Linear Regression I will be using GGPlot to create a regression graph in which the x, the girth of the tree, will predict the total volume of the tree, or the y.

## geom_smooth: na.rm = FALSE, orientation = NA, se = FALSE
## stat_smooth: na.rm = FALSE, orientation = NA, se = FALSE, method = lm
## position_identity
## NULL

Conclusion

Overall Linear Regression is one of the most important skills to have in data analytics and data science. Practical uses of Linear Regression could be predicting the price of real estate based on location, square footage, and all sorts of other factors. Making tools for accurate prediction of data is very helpful and important for buissnesses. Thank you for reading my presentation :)