2026-09-16

Simple Linear Regression

Definition: a statistical method that uses a single independent variable to predict or explain the value of a dependent variable.

Mathematical equation: \(y = \beta_0 + \beta_1 \cdot x +\varepsilon\), where \(\varepsilon \sim \mathbb{N} (\mu = 0; \,\,\sigma^2)\)

Equation Description

Mathematical equation: \(y = \beta_0 + \beta_1 \cdot x +\varepsilon\)

y = the predicted value

\(\beta_0\) = the y-intercept

\(\beta_1\) = the slope

x = the independent variable/what is changing

\(\varepsilon\) = the random error term

Example

This code gives the base scatter plot of data set iris, showing the relationship between sepal length and petal length on various observations of irises:

g = ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point()

And this code gives the fitted line of this graph based on simple linear regression:

g = g + geom_smooth(method = "lm", se = TRUE, color = "red")

The Graph that Code Creates:

This graph shows a fairly strong positive correlation between these two variables.

Standard Error

The shaded area around the linear regression line represents the standard error; the average distance that observed data points fall from the regression line

When variables have a stronger relationship, standard error decreases, and vice versa.

The next slide has an example of how standard error varies based on correlation of variables.

Example of Standard Error

Graph 1 shows a stronger correlation of variables and a smaller standard error, while Graph 2 shows the opposite

Predicting y-values Based on Linear Regression

Linear regression can be used to predict variables. The stronger the correlation between variables, the more accurate the linear regression line is in predicting coordinate points. The interactive graph on the next slide shows both the linear regression line and the points on the scatter plot to compare:

Predicting y-values Based on Linear Regression Example:

Example Explanation

Because the two variables compared in the graph have a strong negative correlation, the linear regression line is quite accurate in predicting coordinate points. This image shows and example of a very accurate prediction from the graph: