Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Fisher’s F-Test in R Programming
Next article icon

Fisher’s F-Test in R Programming

Last Updated : 25 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will delve into the fundamental concepts of the F-Test, its applications, assumptions, and how to perform it using R programming. We will also provide a step-by-step guide with examples and visualizations to help you master the F-Test in the R Programming Language.

What is Fisher’s F-Test?

Fisher's F-test is a statistical method used to compare the variances of two independent samples to determine if they come from populations with the same variance. It tests the ratio of two sample variances to see if they differ significantly. The F-test is the foundation for other advanced statistical tests, such as ANOVA (Analysis of Variance).

F = Larger Sample Variance / Smaller Sample Variance

When to Use the F-Test?

  • To compare the variability between two groups.
  • To test for homogeneity of variances, which is an essential assumption in various statistical methods, like ANOVA or t-tests.

Assumptions of the F-Test

Before performing the F-Test, certain assumptions must be met:

  1. Normality: Both samples should be normally distributed.
  2. Independence: The two samples should be independent of each other.
  3. Ratio Scale: Data should be measured on an interval or ratio scale.

Now we will discuss How to perform Fisher’s F-Test in R Programming Langauge.

Approach 1: Using the var.test() Function

R provides a built-in function var.test() that performs the F-Test easily.

var.test(x, y, alternative = "two.sided")

Where,

  • x, y: numeric vectors
  • alternative: a character string specifying the alternative hypothesis.

Suppose we have two samples of data representing the weights of two different groups of individuals:

r
# Sample data group1 <- c(15.2, 16.5, 14.8, 16.9, 15.5, 15.8) group2 <- c(14.0, 13.8, 15.2, 13.9, 14.1, 14.5)  # Perform the F-Test f_test_result <- var.test(group1, group2)  # Display the result print(f_test_result) 

Output:

	F test to compare two variances

data: group1 and group2
F = 2.2897, num df = 5, denom df = 5, p-value = 0.3844
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.3203995 16.3630488
sample estimates:
ratio of variances
2.289697

The var.test() function output provides:

  • The F statistic value
  • Degrees of freedom (df)
  • p-value

If the p-value is less than the chosen significance level (commonly 0.05), we reject the null hypothesis, indicating a significant difference in variances.

Approach 2: Manual Calculation of F-Test in R

You can calculate the F-Test manually using R to understand the process more deeply.

r
# Calculate variances var_group1 <- var(group1) var_group2 <- var(group2)  # Calculate F statistic f_value <- var_group1 / var_group2  # Display F statistic cat("F Statistic:", f_value, "\n") 

Output:

F Statistic: 2.289697 
  • F-value: Indicates the ratio of variances. Higher F-values suggest more considerable differences.
  • p-value: The probability of observing the F statistic under the null hypothesis. If the p-value is low (< 0.05), reject H₀.

Visualizing the F-Test Distribution

You can visualize the F distribution using R's plotting functions to better understand the test's results.

R
# Visualize F-distribution curve(df(x, df1 = 5, df2 = 5), from = 0, to = 5, col = "blue", lwd = 2,       xlab = "F-value", ylab = "Density", main = "F-Distribution with df1=5, df2=5") 

Output:

gh
Fisher’s F-Test in R Programming

Conclusion

Fisher’s F-Test is a powerful statistical method for comparing variances between two groups. It is easy to implement in R using the var.test() function or manually calculating it. However, it's essential to meet the assumptions and be cautious of its limitations to ensure accurate results.


Next Article
Fisher’s F-Test in R Programming

A

akashpatil242000
Improve
Article Tags :
  • R Language
  • R Machine-Learning

Similar Reads

    Bartlett’s Test in R Programming
    In statistics, Bartlett's test is used to test if k samples are from populations with equal variances. Equal variances across populations are called homoscedasticity or homogeneity of variances. Some statistical tests, for example, the ANOVA test, assume that variances are equal across groups or sam
    5 min read
    Levene’s Test in R Programming
    Levene's test is an inferential statistic used to assess whether the variances of a variable are equal across two or more groups, especially when the data comes from a non-normal distribution. This test checks the assumption of homoscedasticity (equal variances) before conducting tests like ANOVA. I
    3 min read
    Fligner-Killeen Test in R Programming
    The Fligner-Killeen test is a non-parametric test for homogeneity of group variances based on ranks. It is useful when the data are non-normally distributed or when problems related to outliers in the dataset cannot be resolved. It is also one of the many tests for homogeneity of variances which is
    3 min read
    T-Test Approach in R Programming
    The T-Test is a statistical method used to determine whether there is a significant difference between the means of two groups or between a sample and a known value.For Example: businessman who owns two sweet shops in a town. He wants to know if there's a significant difference in the average number
    5 min read
    Hypothesis Testing in R Programming
    A hypothesis is made by the researchers about the data collected for any experiment or data set. A hypothesis is an assumption made by the researchers that are not mandatory true. In simple words, a hypothesis is a decision taken by the researchers based on the data of the population collected. Hypo
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences