2023-02-06

What is Simple Linear Regression?

Is is A statistical method that we can use to summarize and also study relationships between two continuous variables:

One variable, denoted by x, is independent variable. Another variable, denoted by y, is dependent variable.

Simple Linear Regression using ggplot

This is a scatter plot with a regression line made using ggplot. “stat_smooth(method =”lm”, col = “purple”)” was used to create the line plus the color purple for the line.

Simple Linear Regression using ggplot

This is a scatter plot with a regression line made using ggplot. This example has a random data set.

Simple Linear Regression using Plotly

3D scatter plot using Plotly.This example is Sepal length vs Petal length vs Sepal Width with Species being the color map.

R Code for ggplot of Simple Linear Regression

library(ggplot2) a <- data.frame(y=c(7, 8, 8, 9, 12, 13, 14, 15, 16, 21, 22, 23, 24, 25, 26), x=c(2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13))

ggplot(a,aes(x, y)) + geom_point() + geom_smooth(method =‘lm’)

Math text written in Latex

Best fitting line can be found using the least squares criterion:

\[ \displaystyle SS_{residual}= \sum_{i=1}^n{(Y_i-\hat{Y}_i})^2\ \]

Math text written in Latex

The simple linear regression for n observations can be written as this:

$$

y_i = _0 + _1 x_i + _2 x_i^2 + e_i

$$