Logistic regression

A/B Testing in R

Lauryn Burleigh

Data Scientist

Log in logistic

  • Binary
    • Eat pizza again - yes/no
  • Derive probability of category
  • Predicted dependent variable
    • Odds = P / 1-P
    • Linear to independent variable
  • log(P / 1-P) = β₀ + β₁X₁
    • error within log odds

Scatter plot with enjoy on the x-axis and eat again on the y-axis with points at 0 or 1, and a curved logistic regression line.

A/B Testing in R

Logistic regression model

logistic <- glm(EatAgain ~ Enjoy, 
                data = Pizza, 
                family = binomial)
summary(logistic)
chival <- logistic$null.deviance - logistic$deviance
dfval <- logistic$df.null - logistic$df.residual
pchisq(q = chival, df = dfval, lower.tail = FALSE)
[1] 7.472441e-16
Call:
glm(formula = EatAgain ~ Enjoy, family = binomial, 
data = pizza)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.9677   0.0116   0.0297   0.0885   0.9446  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -4.2361     1.4757  -2.871 0.004097 ** 
Enjoy         0.9611     0.2533   3.794 0.000148 ***

Null deviance: 96.204  on 199  degrees of freedom
Residual deviance: 31.199  on 198  degrees of freedom
AIC: 35.199
Number of Fisher Scoring iterations: 9
A/B Testing in R

Predicting data

Enjoy  <- c(12, 14)
topredict <-  data.frame(Enjoy) 
predict(logistic, topredict, 
        type = "response") 
        1         2 
0.9993229 0.9999009 
A/B Testing in R

Including groups

grplogistic <- glm(EatAgain ~ Enjoy + 
                   Topping, 
                   data = pizza, 
                   family = binomial)
summary(grplogistic)
Call:
glm(formula = EatAgain ~ Enjoy + Topping, family = binomial, 
    data = pizza)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.8557   0.0058   0.0222   0.0862   0.8887  

Coefficients:
                 Estimate Std. Error z value Pr(>|z|)   
(Intercept)       -9.4498     3.8806  -2.435  0.01489 * 
Enjoy              1.3402     0.4118   3.255  0.00114 **
ToppingCheese   3.4652     2.0499   1.690  0.09095 . 

Null deviance: 96.204  on 199  degrees of freedom
Residual deviance: 28.232  on 197  degrees of freedom
AIC: 34.232

Number of Fisher Scoring iterations: 9
A/B Testing in R

Let's practice!

A/B Testing in R

Preparing Video For Download...