#setwd("C:/Users/zxu3/Documents/R/ab_testing1")
#Please install the following package if the package "readr" is not installed.
#install.packages("readr")
library(readr)
data <- read_csv("ab_testing1.csv")
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## Ads = col_double(),
## Purchase = col_double()
## )
ls(data) # list the variables in the dataset
## [1] "Ads" "Purchase"
head(data) #list the first 6 rows of the dataset
## # A tibble: 6 x 2
## Ads Purchase
## <dbl> <dbl>
## 1 1 152
## 2 0 21
## 3 2 77
## 4 0 65
## 5 1 183
## 6 1 87
# creating the factor variable
data$Ads <- factor(data$Ads)
is.factor(data$Ads)
## [1] TRUE
# showing the first 15 rows of the variable "Ads"
data$Ads[1:15]
## [1] 1 0 2 0 1 1 2 2 2 0 2 2 0 2 2
## Levels: 0 1 2
#now we do the regression analysis and examine the results
summary(lm(Purchase~Ads, data = data))
##
## Call:
## lm(formula = Purchase ~ Ads, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.75 -22.75 -3.75 30.25 64.29
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 49.00 10.21 4.800 5.69e-05 ***
## Ads1 69.71 15.91 4.383 0.000171 ***
## Ads2 24.75 13.82 1.791 0.084982 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 32.28 on 26 degrees of freedom
## Multiple R-squared: 0.4262, Adjusted R-squared: 0.3821
## F-statistic: 9.656 on 2 and 26 DF, p-value: 0.0007308
#Our null hypothesis (denoted as H0) is that there is no relationship between advertising exposures and product purchases using regression analysis. The alternative hypothesis (usually denoted as H1) is that there is a relationship between advertising exposures and product purchases. The hypothesis test can be represented by the following notation:
Null Hypothesis: H0: β1 = 0 Alternative Hypothesis: H1: β1 ≠ 0
#Findings
Much more sales were obtained when customers were exposed to version 1 of the ads. Less sales were made with version 2 than if the customer was exposed to no ads at all. My managerial recommendation would be to eliminate version 2 of the ad from circulation completely and move forward with version 1 of the ad as the main form of advertising during this campaign.