Fisher’s test

By Data Tricks, 28 July 2020

What is Fisher’s test?

Fisher’s test is a good alternative to a chi-square test of independence when the expected value in any one of the cells in a contingency table is less than 5.

One of the main differences between a chi-square test of independence and a Fisher’s test is that the p-value in a chi-square test is an approximation which tends towards the exact value as the sample size goes towards infinity. In a Fisher’s test, the p-value is exact and not an approximation, which is why it is sometimes called Fisher’s exact test.

Example in R

Let’s create some nominal data:

set.seed(150)
data <- data.frame(sampleA = sample(c("Positive","Positive","Negative"), 30, replace = TRUE),
sampleB = sample(c("Positive","Positive","Negative"), 30, replace = TRUE))
frequencies <- table(data$sampleA, data$sampleB)

Look at the contingency table, we have one cell less than 5:

         Negative Positive
Negative        3        9
Positive        9        9

Perform the Fisher’s test using the fisher.test function:

test <- fisher.test(x = data$sampleA, y = data$sampleB)

Analyse the result:

> test

       Fisher's Exact Test for Count Data

data: data$sampleA and data$sampleB
p-value = 0.2599
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 0.04497001 2.03461029
sample estimates:
odds ratio
 0.3458827

p-value

The p-value is 0.26, which is above the 5% significance level and therefore the null hypothesis cannot be rejected.

Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Please note that your first comment on this site will be moderated, after which you will be able to comment freely.