Introduction

Equation of Linear Regression

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

Example Data

library(ggplot2)
library(plotly)

set.seed(42)
data <- data.frame(X = 1:100, Y = 3 + 2 * (1:100) + rnorm(100, mean = 0, sd = 10))
head(data)

Scatter Plot

ggplot(data, aes(x = X, y = Y)) +
  geom_point() +
  geom_smooth(method = "lm", col = "red") +
  labs(title = "Scatter Plot with Regression Line", x = "X", y = "Y")

3D Plot with Plotly

library(plotly)
plot_ly(data, x = ~X, y = ~Y, type = "scatter", mode = "markers")

Model Fitting

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

Conclusion