#install.packages("readr")
library(readr)
data <- read_csv("abtesting.csv")
## Parsed with 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      113
## 2     0       83
## 3     0       52
## 4     1      119
## 5     1      188
## 6     0       99
# 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 0 1 1 0 0 1 1 1 0 0 0 1 0
## Levels: 0 1
#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 
## -57.000 -23.250   3.071  22.643  51.000 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   95.429      6.441  14.816  < 2e-16 ***
## Ads1          41.571      9.630   4.317 0.000118 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 29.52 on 36 degrees of freedom
## Multiple R-squared:  0.3411, Adjusted R-squared:  0.3228 
## F-statistic: 18.64 on 1 and 36 DF,  p-value: 0.0001184
#now we do an analysis for a predictor with 4 different levels
display <- read_csv("abtesting.csv")
## Parsed with column specification:
## cols(
##   Ads = col_double(),
##   Purchase = col_double()
## )
ls(display) # list the variables in the dataset
## [1] "Ads"      "Purchase"
head(display)
## # A tibble: 6 x 2
##     Ads Purchase
##   <dbl>    <dbl>
## 1     1      113
## 2     0       83
## 3     0       52
## 4     1      119
## 5     1      188
## 6     0       99
# creating the factor variable
display$Ads <- factor(display$Ads)
is.factor(display$Ads)
## [1] TRUE
# showing the first 15 rows of the variable "Ads"
display$Ads[1:15]
##  [1] 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0
## Levels: 0 1
#now we do a regression analysis for a predictor with 4 different levels
summary(lm(Purchase~Ads, data = display))
## 
## Call:
## lm(formula = Purchase ~ Ads, data = display)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -57.000 -23.250   3.071  22.643  51.000 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   95.429      6.441  14.816  < 2e-16 ***
## Ads1          41.571      9.630   4.317 0.000118 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 29.52 on 36 degrees of freedom
## Multiple R-squared:  0.3411, Adjusted R-squared:  0.3228 
## F-statistic: 18.64 on 1 and 36 DF,  p-value: 0.0001184