Rmd source

Loading the libraries

library("tidyverse") ## !!!!!!!!
library("caret")

load ("marketing.rda")

Define training and test data sets:

training.samples <- marketing$sales %>%
  createDataPartition(p=0.8, list = F)

train.data <- marketing[training.samples, ]
test.data <- marketing[ -training.samples, ]

The plot

plot(train.data)

Model

## 
## Call:
## lm(formula = sales ~ youtube, data = train.data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.7106 -2.3657 -0.2705  2.5006  8.6251 
## 
## Coefficients:
##             Estimate Std. Error t value            Pr(>|t|)    
## (Intercept) 8.427642   0.637167   13.23 <0.0000000000000002 ***
## youtube     0.047710   0.003119   15.30 <0.0000000000000002 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.012 on 160 degrees of freedom
## Multiple R-squared:  0.5939, Adjusted R-squared:  0.5914 
## F-statistic:   234 on 1 and 160 DF,  p-value: < 0.00000000000000022

Veryfying assumptions:

## 
##  studentized Breusch-Pagan test
## 
## data:  model1
## BP = 36.646, df = 1, p-value = 0.000000001416