R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com. Note: this analysis was performed using the open source software R and Rstudio.

install.packages("dplyr")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.2'
## (as 'lib' is unspecified)
## also installing the dependencies 'cli', 'fansi', 'pkgconfig', 'withr', 'utf8', 'generics', 'lifecycle', 'tibble', 'tidyselect', 'vctrs', 'pillar'
install.packages("ggplot2")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.2'
## (as 'lib' is unspecified)
## also installing the dependencies 'colorspace', 'farver', 'labeling', 'munsell', 'RColorBrewer', 'viridisLite', 'gtable', 'isoband', 'scales'
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
display <- read.csv("Display_data.csv")
# plot the data to see what it looks like
plot(display$spend, display$revenue)

ggplot(display, aes(x = spend,
                    y = revenue)) +
  geom_point() +
  geom_smooth(method = "lm")   # add trendline using linear model
## `geom_smooth()` using formula 'y ~ x'

## Build a linear regression model with one predictor only

lm_mod1 <- lm(revenue ~ spend, data = display)# look at our model with summary function
summary(lm_mod1)
## 
## Call:
## lm(formula = revenue ~ spend, data = display)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -145.210  -54.647    1.117   67.780  149.476 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  10.9397    37.9668   0.288    0.775    
## spend         4.8066     0.7775   6.182 1.31e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 86.71 on 27 degrees of freedom
## Multiple R-squared:  0.586,  Adjusted R-squared:  0.5707 
## F-statistic: 38.22 on 1 and 27 DF,  p-value: 1.311e-06

Build a multiple regression model including two predictors, display and spend

lm_mod2 <- lm(revenue ~ spend + display, data = display)# look at our model with summary function
summary(lm_mod2)
## 
## Call:
## lm(formula = revenue ~ spend + display, data = display)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -176.730  -35.020    8.661   56.440  129.231 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -50.8612    40.3336  -1.261  0.21850    
## spend         5.5473     0.7415   7.482 6.07e-08 ***
## display      93.5856    33.1910   2.820  0.00908 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 77.33 on 26 degrees of freedom
## Multiple R-squared:  0.6829, Adjusted R-squared:  0.6586 
## F-statistic:    28 on 2 and 26 DF,  p-value: 3.271e-07

Ref: Zhenning “Jimmy”Xu, Marketing Research using R. https://bookdown.org/utjimmyx/marketing_research/basic-regression-analysis.html Linear Regression.An Introduction to Statistical Learning, with Applications in R. By Gareth James, Daniela Witten, Trevor Hastie, Robert Tibshirani 2021. https://web.stanford.edu/~hastie/ISLR2/ISLRv2_website.pdf.