2024-03-18

Simple Linear Regression

Simple linear regression is a statistical method that allows us to summarize and study relationships between two continuous (quantitative) variables:

  1. One variable, denoted x, is regarded as the predictor, explanatory, or independent variable.
  2. The other variable, denoted y, is regarded as the response, outcome, or dependent variable.

The goal of simple linear regression is to find the best-fitting straight line that summarizes the relationship between these two variables.

Source: https://online.stat.psu.edu/stat462/node/91/

Plotly plot

Here is a plotly plot for a sample linear regression model.

R code for plotly plot

Here is the R code for the plotly plot shown on the previous slide

library(plotly)

set.seed(123)
X <- 1:100
beta_0 <- 2
beta_1 <- 3
epsilon <- rnorm(100, mean = 0, sd = 10) 

#Y = beta_0 + beta_1 * X + epsilon
Y <- beta_0 + beta_1 * X + epsilon

model <- lm(Y ~ X)
data <- data.frame(X = X, Y = Y)

scatter_plot <- plot_ly(data, x = ~X, y = ~Y, type = 'scatter', mode = 'markers', marker = list(size = 8))

First ggplot: scatter plot

Here is a ggplot for the same linear regression model as the plotly plot on the last slide.

Second ggplot: line plot

Here is a ggplot for the same linear regression model as the plotly plot and the previous ggplot. This plot is in the form of a line plot.

Simple linear regression equation

Here is the formula for simple linear regression: \(Y = \beta_0 + \beta_1 X + \varepsilon\)

The above equation represents the following:

  • \(Y\) is the predicted value of the response variable.

  • \(X\) is the value of the predictor variable.

  • \(\beta_0\) is the intercept.

  • \(\beta_1\) is the slope.

  • \(\varepsilon\) is the error term.

More equations

Here are a couple of more formulae for simple linear regression.

The formula for predicted values is given by:

\[ \hat{Y} = \hat{\beta}_0 + \hat{\beta}_1 X \]

And the formula for residuals is:

\[ e_i = Y_i - \hat{Y}_i \]

Some applications of simple linear regression

  • Market analysis by using some marketing strategies and maximising sales.

  • Financial study through linear models for evaluating an establishment’s operational performance.

  • Sports analysis by predicting game attendance depending on the team’s status as well as market size.

  • Predicts the impact of water and air pollution on the environment Recognizes high-risk patients and improves healthy lifestyles.

Source: https://herovired.com/learning-hub/blogs/what-is-linear-regression/