# Load necessary libraries
library(ggplot2)
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
# Creating the dataset
ab_testing <- data.frame(
Ads = c(1,0,2,0,1,1,2,2,2,0,2,2,0,2,2,0,2,0,0,2,0,1,1,2,1,0,1,0,2),
Purchase = c(152,21,77,65,183,87,121,104,116,82,53,91,85,53,51,25,81,23,42,54,84,124,106,14,61,24,118,39,70)
)
# View first few rows
head(ab_testing)
## Ads Purchase
## 1 1 152
## 2 0 21
## 3 2 77
## 4 0 65
## 5 1 183
## 6 1 87
# Summary statistics
summary(ab_testing)
## Ads Purchase
## Min. :0.000 Min. : 14.00
## 1st Qu.:0.000 1st Qu.: 51.00
## Median :1.000 Median : 77.00
## Mean :1.069 Mean : 76.07
## 3rd Qu.:2.000 3rd Qu.:104.00
## Max. :2.000 Max. :183.00
# Boxplot
ggplot(ab_testing, aes(x = factor(Ads), y = Purchase, fill = factor(Ads))) +
geom_boxplot() +
labs(title = "Distribution of Purchases by Ad Type", x = "Ad Type", y = "Number of Purchases") +
theme_minimal()
# Running a linear regression model
model <- lm(Purchase ~ factor(Ads), data = ab_testing)
summary(model)
##
## Call:
## lm(formula = Purchase ~ factor(Ads), data = ab_testing)
##
## 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 ***
## factor(Ads)1 69.71 15.91 4.383 0.000171 ***
## factor(Ads)2 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
# Extracting model coefficients, p-value, and R-squared value
coefficients <- summary(model)$coefficients
p_values <- coefficients[,4]
r_squared <- summary(model)$r.squared
# Display results
coefficients
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 49.00000 10.20740 4.800438 5.691154e-05
## factor(Ads)1 69.71429 15.90709 4.382592 1.714257e-04
## factor(Ads)2 24.75000 13.82089 1.790768 8.498177e-02
p_values
## (Intercept) factor(Ads)1 factor(Ads)2
## 5.691154e-05 1.714257e-04 8.498177e-02
r_squared
## [1] 0.4262103
Coefficients Interpretation: On average Ad 1 increases purchases by 69.71 compared to the control group. The p-value (0.00017) is very low, indicating a statistically significant impact. On average, using Ad 2 increases purchases by 24.75 compared to the control group. However, the p-value (0.08498) is above 0.05, meaning this effect is not statistically significant.
R-Squared Interpretation: Intercept p = 5.69e-05= Significant, confirming that the baseline purchases, are not zero.
Managerial Recommendations: