2024-01-25
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)
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
\[ \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.
\[ \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} \]
\[ \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
###HAVE A GOSH DARN GOOD DAY