Skip to content

Data Science Tutorials

For Data Science Learners

  • How to do Pairwise Comparisons in R?
    How to do Pairwise Comparisons in R? R
  • How to Add Superscripts and Subscripts to Plots in R?, The basic syntax for adding superscripts or subscripts to charts in R is as follows:
    How to Add Superscripts and Subscripts to Plots in R? R
  • Checking Missing Values in R
    Checking Missing Values in R R
  • How to Calculate Lag by Group in R
    How to Calculate Lag by Group in R? R
  • How to copy files in R
    How to copy files in R R
  • How to Use Gather Function in R
    How to Use Gather Function in R?-tidyr Part2 R
  • Correlation Coefficient p value in R
    Correlation Coefficient p value in R R
  • Get the first value in each group in R
    Get the first value in each group in R? R
Fisher’s exact test in R

Fisher’s exact test in R

Posted on September 17September 14 By Admin No Comments on Fisher’s exact test in R

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 used when the sample size is small and the expected counts of the contingency table are less than 5.

In this article, we will demonstrate how to conduct Fisher’s exact test in R with examples.

Formulation of the Hypothesis:

Before conducting Fisher’s exact test, it is necessary to formulate the null and alternative hypotheses.

The null hypothesis (H0) assumes that there is no significant association between two categorical variables. It is usually written as:

H0: The two variables are independent.

The alternative hypothesis (H1) assumes that there is a significant association between two categorical variables.

It can be either one-tailed or two-tailed and is usually written as:

H1: The two variables are dependent.

In the following sections, we will provide examples of how to conduct Fisher’s exact test in R.

Jr. Investment Data Analyst-Omaha, NE (hybrid) »

Example 1: Two-Tailed Fisher’s Exact Test

In this example, we will use a dataset that contains information about the type of car owned and whether or not the owner has a valid driver’s license.

We want to test the hypothesis that the type of car and having a valid driver’s license are independent.

First, we need to load the dataset:

car_data <- read.csv("car_data.csv")

Next, we can create a contingency table to visualize the relationship between the two categorical variables:

cont_table <- table(car_data$Car_Type, car_data$License)

Then, we can conduct the two-tailed Fisher’s exact test using the ‘fisher.test’ function:

fisher_test <- fisher.test(cont_table, alternative = "two.sided")

Finally, we can extract the test statistic, p-value, confidence interval, and a conclusion based on the test results using the ‘summary’ function:

summary(fisher_test)

The output will display the test statistic, the p-value, the confidence interval, and a conclusion based on the test results.

In this case, because the p-value is greater than 0.05, we fail to reject the null hypothesis and conclude that there is no significant association between the type of car and having a valid driver’s license.

Example 2: One-Tailed Fisher’s Exact Test

In this example, we will use a dataset that contains information about the age of a person and whether or not they have a valid driver’s license.

We want to test the hypothesis that people over the age of 50 are more likely to have a valid driver’s license.

Let’s load the dataset:

age_data <- read.csv("age_data.csv")

Next, we can create a contingency table to visualize the relationship between the two categorical variables:

cont_table <- table(age_data$License, age_data$Age > 50)

Then, we can conduct the one-tailed Fisher’s exact test using the ‘fisher.test’ function:

fisher_test <- fisher.test(cont_table, alternative = "greater")

Finally, we can extract the test statistic, p-value, confidence interval, and a conclusion based on the test results using the ‘summary’ function:

summary(fisher_test)

The output will display the test statistic, the p-value, the confidence interval, and a conclusion based on the test results.

In this case, because the p-value is less than 0.05, we reject the null hypothesis and conclude that people over the age of 50 are significantly more likely to have a valid driver’s license.

Conclusion:

In this article, we have demonstrated how to conduct Fisher’s exact test in R using both the ‘fisher.test’ function.

Fisher’s exact test is a statistical test used to analyze the relationship between two categorical variables when the sample size is small and the expected counts of the contingency table are less than 5.

By utilizing the examples provided in this article, researchers can use Fisher’s exact test to test hypotheses related to categorical variables in their datasets.

ggpairs in R » Data Science Tutorials

R

Post navigation

Previous Post: One proportion Z Test in R
Next Post: Jarque-Bera Test in R With Examples

Related Posts

  • Random Forest Machine Learning
    Random Forest Machine Learning Introduction R
  • How to Find the Size of a Data Frame in R R
  • How to Get a Job as a Data Engineer
    How to Get a Job as a Data Engineer? R
  • Interactive 3d plot in R
    Interactive 3d plot in R-Quick Guide R
  • Crosstab calculation in R
    Crosstab calculation in R R
  • Check whether any values of a logical vector are TRUE
    Check whether any values of a logical vector are TRUE R

Leave a Reply Cancel reply

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

  • Best Prompt Engineering Books
  • Understanding Machine Learning and Data Science
  • Best Git Books
  • Top 5 Books to Learn Data Engineering
  • Mastering R Programming for Data Science: Tips and Tricks
  • About Us
  • Contact
  • Disclaimer
  • Privacy Policy

https://www.r-bloggers.com

  • YouTube
  • Twitter
  • Facebook
  • Course
  • Excel
  • Machine Learning
  • Opensesame
  • R
  • Statistics

Check your inbox or spam folder to confirm your subscription.

  • AI in Delivery Management
    AI in Delivery Management Machine Learning
  • How to create a heatmap in R
    How to create a heatmap in R R
  • Best Data Science YouTube Tutorials
    Best Data Science YouTube Tutorials Free to Learn Course
  • How To Become a Business Intelligence Analyst
    How To Become a Business Intelligence Analyst Course
  • How to add Axes to Plot in R R
  • Replace NA with Zero in R
    Replace NA with Zero in R R
  • Survival Plot in R
    How to Perform a Log Rank Test in R R
  • Duplicate and concatenate in R R

Privacy Policy

Copyright © 2025 Data Science Tutorials.

Powered by PressBook News WordPress theme