#setwd("C:/Users/zxu3/Documents/R/ab_testing")
#Please install the following package if the package "readr" is not installed.
#install.packages("readr")
library(readr)
data <- read_csv("ab_testing.csv")
## Rows: 80 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (2): Ads, Purchase
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ls(data) # list the variables in the dataset
## [1] "Ads" "Purchase"
head(data) #list the first 6 rows of the dataset
## # A tibble: 6 × 2
## Ads Purchase
## <dbl> <dbl>
## 1 1 152
## 2 0 21
## 3 3 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 3 0 1 1 2 2 2 0 3 3 0 2 3
## Levels: 0 1 2 3
#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
## -50.095 -27.891 -0.227 24.773 65.905
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 55.381 6.472 8.557 9.41e-13 ***
## Ads1 75.714 9.152 8.273 3.31e-12 ***
## Ads2 36.557 9.842 3.715 0.000386 ***
## Ads3 -2.654 9.048 -0.293 0.770096
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 29.66 on 76 degrees of freedom
## Multiple R-squared: 0.5624, Adjusted R-squared: 0.5452
## F-statistic: 32.56 on 3 and 76 DF, p-value: 1.216e-13