1. Import and view the data

library(readxl)
ad <- read_excel("ad.xlsx")
knitr::kable(head(ad, 14),booktabs = TRUE)
State AdEx Sales
NJ 5.0 432.0
NY 7.0 723.0
AK 6.0 578.0
HI 6.5 600.0
FL 8.0 950.0
CA 3.5 106.0
OR 4.0 282.0
WA 4.5 232.6
NV 6.5 746.0
AZ 7.0 812.4
CO 7.5 800.0
CT 7.5 929.0
DE 8.5 1004.0
SC 7.0 632.0

2. Visualize the data as a scatter plot

library(ggplot2)
scatter01 <- ggplot(ad, aes(x=AdEx, y=Sales)) + geom_point(color='#4cbea3') + labs(title = "Simple scatter plot", subtitle = "Sales (in 1000's of dollars)", caption = "Kristen Sosulski | Source: Rohit Deo (2018)", x = "Advertising expenditures", y =" ") + theme(text=element_text(family="Avenir")) + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "gray"), axis.ticks.x=element_blank(), axis.ticks.y=element_blank()) 

scatter01

3. Visualize the regression plot

scatter01 + geom_smooth(method = "lm", se = FALSE, color="gray")

4. The regression equation

The regression equation is Sales = -495 + 178 AdEx

linearMod <- lm(Sales ~ AdEx, data=ad) 
print(linearMod)
## 
## Call:
## lm(formula = Sales ~ AdEx, data = ad)
## 
## Coefficients:
## (Intercept)         AdEx  
##      -495.3        178.1
summary(linearMod)
## 
## Call:
## lm(formula = Sales ~ AdEx, data = ad)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -119.346  -37.380   -4.869   54.998   88.609 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -495.28      77.06  -6.427 3.27e-05 ***
## AdEx          178.09      11.87  15.000 3.89e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 65.36 on 12 degrees of freedom
## Multiple R-squared:  0.9494, Adjusted R-squared:  0.9451 
## F-statistic:   225 on 1 and 12 DF,  p-value: 3.888e-09