Fisher’s exact test in R and Interpretation – R tutorial

8093

R provides several methods of testing the independence of the categorical variables. In my tutorial, I will show three tests such as the chi-square test of independence, the Fisher exact test, and the Cochran-Mantel–Haenszel test. This article shows you about Fisher’s exact test in R and how to interpret the results.

Fisher’s exact test is named after its inventor, Ronald Fisher, and is one of a class of exact tests, so-called because the significance of the deviation from a null hypothesis (e.g., P-value) can be calculated exactly, rather than relying on an approximation that becomes exact in the limit as the sample size grows to infinity, as with many statistical tests.

The test is useful for categorical data to examine the significance of the association (contingency) between the two kinds of classification.

The function fisher.test() is used to perform this operation. I will show an example with builtin data on vcd package. You can always import data into R using CSV, Excel or SPSS data file. Also, we will see how to interpret the results.

Hypotheses of Fisher’s exact test

Null hypothesis – Assumes that there is no association between the two variables.

Alternative hypothesis – Assumes that there is an association between the two variables.

Let us see an example now.

Example

To install vcd package use the command install.packages("vcd"). Then use the following code to performs Fisher’s exact test in R for two different sets of variables and to understand when to accept and when to reject the hypothesis.

> library(vcd)
> fisher.test(Arthritis$Treatment,Arthritis$Improved)
     Fisher's Exact Test for Count Data

data: Arthritis$Treatment and Arthritis$Improved
p-value = 0.001393
alternative hypothesis: two.sided

From the result of fisher.test(Arthritis$Treatment,Arthritis$Improved), there appears to be a relationship between treatment received and level of improvement, We come to this conclusion because the p-value is less than 0.01. i.e, p < 0.01. Hence, we reject the null hypothesis and accept the alternative hypothesis.

So, this is how you can perform a Fisher’s exact test in R and interpret the result.

Previous articleChi-Square Test in R and Interpretation – R tutorial
Next articleCochran–Mantel–Haenszel test in R and Interpretation – R tutorial
A.Sulthan, Ph.D.,
Author and Assistant Professor in Finance, Ardent fan of Arsenal FC. Always believe "The only good is knowledge and the only evil is ignorance - Socrates"
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments