How do I conduct Fisher’s Exact Test in R?

Fisher’s Exact Test is a statistical test used to analyze the relationship between two categorical variables. It is commonly used when the sample size is small and the assumptions for other tests, such as chi-square, are not met. In order to conduct Fisher’s Exact Test in R, the first step is to import the data into R and organize it into a contingency table. Next, the “fisher.test” function is used to calculate the p-value and test statistic. This function requires the contingency table as input and can also be used to specify the alternative hypothesis. The results of the test can then be interpreted to determine the significance of the relationship between the two variables. Overall, conducting Fisher’s Exact Test in R involves properly formatting the data and using the appropriate function to obtain the necessary statistical information.

Conduct Fisher’s Exact Test in R


is used to determine whether or not there is a significant association between two categorical variables.

It is typically used as an alternative to the when one or more of the cell counts in a 2×2 table is less than 5.

Fisher’s Exact Test uses the following null and alternative hypotheses:

  • H0: (null hypothesis) The two variables are independent.
  • HA: (alternative hypothesis) The two variables are not independent.

The following example shows how to conduct Fisher’s Exact Test in R.

Example: Fisher’s Exact Test in R

In order to conduct Fisher’s Exact Test in R, you simply need a 2×2 dataset.

For example, let’s generate a 2×2 dataset to use as an example:

#create 2x2 dataset
data = matrix(c(2,5,9,4), nrow = 2)

#view dataset
data
# 2 9
# 5 4

To conduct Fisher’s Exact Test, we simply use the following code:

fisher.test(data)

 This produces the following output:

In Fisher’s Exact Test, the null hypothesis is that the two columns are independent (or equivalently, that the odds ratio is equal to 1).

To determine if the two columns are independent, we can look at the p-value of the test.

In this case the p-value is 0.1597, which tells us we do not have sufficient evidence to reject the null hypothesis.

Thus, we cannot say that there is any statistically significant difference between the two columns.

The output of the test also gives us a 95% confidence interval for the odds ratio, which is:

95% Confidence Interval for Odds Ratio: (0.0130943, 1.8397543)

Since the number 1 is within this ratio, it confirms that the odds ratio is not significantly different than 1 (assuming we use alpha level 0.05).

Additional Resources

The following tutorials provide additional information about Fisher’s Exact Test:

x