Fisher's Exact test

A/B Testing in R

Lauryn Burleigh

Data Scientist

Specifications

  • Non-parametric of categorical data
    • Whether Cheese or Pepperoni pizza eaten again
  • Sample < 1000
  • Frequency < 5 for at least 20%
  • Use Fisher's Exact test for exact p-value
  • 2x2 frequency table

Hypergeometric Distribution

  • Likelihood of frequency table
table(Pizza$Topping, Pizza$EatAgain)
              No Yes
  Cheese     140 360
  Pepperoni   80 420
A/B Testing in R

Hypotheses

  • Null hypothesis: No relationship between eating pizza again and topping group

Photograph of pizza slices being picked up by various people's hands.

A/B Testing in R

Sample

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
table(Pizza$Topping, Pizza$EatAgain)
              No Yes
  Cheese     140 360
  Pepperoni   80 420
A/B Testing in R

Test

freqtbl <- table(Pizza$Topping, 
                 Pizza$Time)
fisher.test(freqtbl) 
    Fisher's Exact Test for Count Data
data:  freqtbl
p-value = 0.001809
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 0.4569013 0.8417208
sample estimates:
odds ratio 
 0.6209987 
A/B Testing in R

Effect size

freqtbl <- table(Pizza$Topping, 
                 Pizza$Time)
fisher.test(freqtbl) 
  • Small: 1.5
  • Medium: 2.5
  • Large: 4
  • Pepperoni pizza x 0.62 than Cheese pizza
Fisher's Exact Test for Count Data
data:  freqtbl
p-value = 0.001809
alternative hypothesis: true odds 
ratio is not equal to 1
95 percent confidence interval:
 0.4569013 0.8417208
sample estimates:
odds ratio 
 0.6209987  
A/B Testing in R

Power

library(pwr)
pwr.2p.test(h = 0.62, n = 500, 
            sig.level = 0.002) 
    Difference of proportion power 
 calculation for binomial distribution

              h = 0.62
              n = 500
      sig.level = 0.002
          power = 1
    alternative = two.sided

NOTE: same sample sizes
A/B Testing in R

Let's practice!

A/B Testing in R

Preparing Video For Download...