2024-01-25

My Topic: Simple Linear Regression

THERE IS LOTS OF IMPORANT STATS DEVICES

BUT Simple Linear Regression is one of the

most important ones to know

WHAT IS Simple Linear Regression

DEFINITION by scribbr is used to estimate the relationship between two quantitative variables. You can use simple linear regression when you want to know: How strong the relationship is between two variables (e.g., the relationship between rainfall and soil erosion).

EQUATION: \[ y = \beta_0 + \beta_1 x + \varepsilon \]

What the Equation Means

\[ y = \beta_0 + \beta_1 x + \varepsilon \]

  • \(y\): Dependent variable (response variable).
  • \(x\): Independent variable (predictor variable).
  • \(\beta_0\): Intercept term, the value of \(y\) when \(x = 0\).
  • \(\beta_1\): Slope coefficient, representing the change in \(y\) for a one-unit change in \(x\).
  • \(\varepsilon\): Error term, representing the unobserved factors that affect \(y\) but are not included in the model.

Real Scenario

Lets say given this data

Monthly_Sales = c(368, 340, 665, 954, 331, 556, 376), Advertising_Dollars = c(1.7, 1.5, 2.8, 5, 1.3, 2.2, 1.3)

Real Scenario Part 2

This line shows us the rough connection between the data set given.

Real Scenario Part 3 (Showing code to solve and graph)

library(ggplot2)
#THIS IS OUR DATA
store_data <- data.frame(
  Store = 1:12,
  Monthly_Sales = c(368, 340, 665, 954, 331, 556, 376, 231, 341, 652, 562, 724),
  Advertising_Dollars = c(1.7, 1.5, 2.8, 5, 1.3, 2.2, 1.3,2, 1.3, 3.2, 1.4, 2.3)
)
#THIS SOLVES FOR LINE
model <- lm(Advertising_Dollars ~ Monthly_Sales, data = store_data)
#THIS GRAPHS
ggplot(store_data, aes(x = Monthly_Sales, y = Advertising_Dollars)) +
  geom_point(size = 3, color = "blue") +
  geom_abline(intercept = coef(model)[1], slope = coef(model)[2], color = "red") +
  labs(title = "Scatter Plot w Simple Linear Regression",
       x = "Monthly E-commerce Sales (in 1000s)",
       y = "Online Advertising Dollars (in 1000s)")

### This is all the code

Slide 7: Mathematical Formulas

Simple Linear Regression Formulas

\[ \hat{y} = \hat{\beta}_0 + \hat{\beta}_1 x \]

Where: - \(\hat{y}\) is the predicted value of the dependent variable, - \(\hat{\beta}_0\) is the intercept, - \(\hat{\beta}_1\) is the slope, - \(x\) is the independent variable.

Slide 8: Continue

Slope Formula

\[ \hat{\beta}_1 = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n}(x_i - \bar{x})^2} \]

Intercept Formula

\[ \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x} \]

Where: - \(\bar{x}\) is the mean of the independent variable, - \(\bar{y}\) is the mean of the dependent variable. ##Test

thats its

Thanks for reading

###HAVE A GOSH DARN GOOD DAY