Chi-Square test of independence

A/B Testing in R

Lauryn Burleigh

Data Scientist

Frequency tables

  • Whether nominal variables are related
    • Eating the pizza topping again
  • Frequency table - number of times each of the named conditions co-occurs
    • One-topping pizza: variable 1
    • Would eat again: variable 2
table(Pizza$Topping, Pizza$EatAgain)
             Maybe  No Yes
  Cheese       207  90 703
  Pepperoni    147 101 752
A/B Testing in R

Hypotheses

  • Null hypothesis: Topping and interest in eating again have no relationship
  • Alternative hypothesis: Topping and interest in eating again have a relationship

 

Cannot conclude cause

Photograph of pizza slices.

A/B Testing in R

Sample size

library(pwr)
pwr.chisq.test(w = 0.1, df = 2, 
               power = 0.80, 
               sig.level = 0.05)
     Chi squared power calculation 
              w = 0.1
              N = 963.4689
             df = 2
      sig.level = 0.05
          power = 0.8
NOTE: N is the number of observations
  • w:
    • Small: 0.10
    • Medium: 0.30
    • Large: 0.50
  • Degrees of freedom:
    • (Conditions-of-variable-1 - 1) * (Conditions-of-variable-2 - 1)
    • (2-1) * (3-1) = 2

 

Minimum of five values at each variable combination

A/B Testing in R

Chi-square test

freqtbl <- table(Pizza$Topping, 
                 Pizza$EatAgain) 
chisq.test(freqtbl)
    Pearson's Chi-squared test

data:  freqtbl
X-squared = 12.453, df = 2, 
p-value = 0.001976

 

Large sample sizes: over 1000

A/B Testing in R

Effect size

  • Effect size: w
  • Probabilities
probtbl <- freqtbl/sum(freqtbl) 

library(pwr)
ES.w2(probtbl)
  • Small: 0.10
  • Medium: 0.30
  • Large: 0.50
[1] 0.07890872
A/B Testing in R

Power

pwr.chisq.test(w = 0.079, df = 2, 
               N = 1000, 
               sig.level = 0.002)
     Chi squared power calculation 

              w = 0.079
              N = 1000
             df = 2
      sig.level = 0.002
          power = 1

NOTE: N is the number of observations
A/B Testing in R

Let's practice!

A/B Testing in R

Preparing Video For Download...