Introduction to Simple Linear Regression

  • Simple Linear Regression is a statistical method to model the relationship between two variables: one independent variable and one dependent variable.
  • Both variables should be quantitative.
  • Predicts the value of unknown data by using another related and known data value

Assumptions of Simple Linear Regression

  1. Linearity: The relationship between X and the mean of Y is linear
  2. Independence: The variance of residual is the same for any value of X.
  3. Homoscedasticity: Observations are independent of each other.
  4. Normality: For any fixed value of X, Y is normally distributed.

Visualization of the Regression Line using ploty plot 3D model.

## A marker object has been specified, but markers is not in the mode
## Adding markers to the mode...

Visualization of the Regression Line using ggplot2 #1

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

Visualization of the Regression Line using ggplot2 #2

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

Linear Regression Equation with text written in Latex

The equation of a simple linear regression model can be written as:

\[ Y = \beta_0 + \beta_1 X + \varepsilon \]

where: - \(Y\) is the dependent variable, - \(X\) is the independent variable, - \(\beta_0\) is the intercept, - \(\beta_1\) is the slope coefficient, and - \(\varepsilon\) is the error term.

This equation represents the relationship between the independent variable \(X\) and the dependent variable \(Y\) in the context of linear regression.

Linear Regression Equation with the text written in Latex 2nd example

The probability density function (PDF) of the normal distribution is given by:

\[ f(x|\mu,\sigma^2) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp \left( -\frac{(x-\mu)^2}{2\sigma^2} \right) \]

where: - \(x\) represents the random variable, - \(\mu\) is the mean of the distribution, and - \(\sigma^2\) is the variance.

This equation describes the shape of the normal distribution curve, which is symmetric and bell-shaped.

Lastly the code that I used for writing my 3D Model

suppressMessages(library(plotly)) # Load necessary libraries

hours <- c(2, 3, 4, 5, 6, 7, 8) # Example dataset (2D)
scores <- c(56, 67, 75, 82, 88, 93, 97)

data <- data.frame(hours, scores) # Create a dataframe

model <- lm(scores ~ hours, data = data) # Fit linear regression model

predictions <- predict(model) # Predict scores using the regression model

# Create 3D scatter plot with regression line
plot_ly(data, x = ~hours, y = ~scores, type = "scatter3d", mode = "markers", 
marker = list(size = 5, color = "blue"), text = NULL) %>% 
add_trace(x = ~hours, y = ~predictions, z = ~predictions, type = "scatter3d", 
mode = "lines", line = list(color = "red", width = 2), text = NULL)

Thank you so much for reading my slides about linear regression!