The Friedman Test is a non-parametric statistical test used to detect differences in treatments across multiple test attempts. It is often used when the data is in the form of rankings or ordinal data, and when you have more than two related groups or repeated measures. The Friedman test is the non-parametric alternative to the repeated measures ANOVA and is useful when the assumptions of normality and homogeneity of variances are not met
The Friedman test is used to compare three or more related groups or repeated measures. It analyzes the ranks of the data rather than the raw values, which makes it ideal for non-parametric data.
Elements of Friedman Test
- One group measured across multiple conditions: A single group is measured on three or more conditions or over time.
- One dependent variable: The dependent variable can be ordinal, interval, or ratio data.
Assumptions of Friedman Test
Null and Alternate Hypothesis of Friedman Test
Null Hypothesis: There is no significant difference between the given conditions of measurement OR the probability distributions for all the conditions are the same. (Medians are same)
Alternate Hypothesis: At least 2 of them differ from each other.
H0 : M1 = M2 = M3 = ..... Mk ; M= Median
H1 : At least two of them show significant difference.
Friedman Test Formula
To calculate the test statistic for the Friedman test
F_{R}=\frac{12}{n k(k+1)} \sum R_{i}^{2}-3 n(k+1)
Where:
- n = The number of participants or observations (individuals).
- k = The number of conditions or measurements (groups or samples).
- Ri = The sum of ranks for each group or condition.
Decision Rule for Friedman Test
You can make the decision on the basis of the below-mentioned rules-
- Calculated Value vs Table Value: If FR is greater than the critical value limits reject the Null Hypothesis. Otherwise, accept the Null Hypothesis.
- P-Value Approach: Compare the P-Value with Alpha ( Level of Significance). If the p-value is less than or equal to alpha then reject the Null Hypothesis.
Post Hoc Analysis
If the null hypothesis is rejected in the Friedman test, post hoc analysis helps identify which specific pairs of experimental conditions differ. This can be done using tests like the Wilcoxon signed-rank test or Conover's test.
For the Wilcoxon signed-rank test, results for all pairs can be obtained, but a Bonferroni correction is necessary. This correction adjusts the significance level to (Given significance level / total number of pairs) to control for Type I errors.
Steps to perform Friedman Test
Let us take an example to understand how to perform this test.
Example: random people were given 3 different drugs and for each person, the reaction time corresponding to the drugs were noted. Test the claim at the 5% significance level that all the 3 drugs have the same probability distribution.
| Drug A | Drug B | Drug C |
---|
1 | 1.24 | 1.50 | 1.62 |
---|
2 | 1.71 | 1.85 | 2.05 |
---|
3 | 1.37 | 2.12 | 1.68 |
---|
4 | 2.53 | 1.87 | 2.62 |
---|
5 | 1.23 | 1.34 | 1.51 |
---|
6 | 1.94 | 2.33 | 2.86 |
---|
7 | 1.72 | 1.43 | 2.86 |
---|
Step 1: Define NULL and Alternate Hypothesis
- H0 : All three drugs have the same probability distribution. MA = MB = MC
- H1 : At least two of them differ from each other.
Step 2: State Alpha (Level of Significance)
Step 3: Calculate Degrees of Freedom
- DF = K-1
- K = number of blocks to be measured.
- Here , DF = 3-1 =2.
Step 4: Find out the Critical Chi-Square Value.
Step 5: State Decision Rule
You can check for any of the two rules:
- If FR > 5.991, reject the Null Hypothesis (H0).
- If FR ≤ 5.991, fail to reject H0.
Step 6: Assign Ranks for the drugs corresponding to each person and find the sum.
- Ranks will be in Ascending order.
| Ranks |
---|
| Drug A | Drug B | Drug C |
---|
1 | 1 | 2 | 3 |
---|
2 | 1 | 2 | 3 |
---|
3 | 1 | 3 | 2 |
---|
4 | 2 | 1 | 3 |
---|
5 | 1 | 2 | 3 |
---|
6 | 1 | 2 | 3 |
---|
7 | 2 | 1 | 3 |
---|
| ∑ = 9 | ∑ = 13 | ∑ = 20 |
---|
Note: If in the same row 2 or more columns have the same value then the rank assigned to them is the average of the ranks they get. For example: If a row has 2 columns with value x and the ranks which they get are 4 and 5. Then both the columns will be assigned with a rank of (4+5)/2 which is 4.5.
Step 7: Calculate Test Statistic
The Friedman test statistic formula is:
F_R = \frac{12}{nK(K+1)} \sum R_j^2 - 3n(K+1)
Where:
- n = 7 (Number of people)
- K = 3 (Number of drugs)
- R_j^2 are the squared rank sums:
F_R = \frac{12}{7(3)(3+1)} [(9^2 + 13^2 + 20^2)] - 3(7)(4)
F_R = \frac{12}{7(3)(4)} [81 + 169 + 400] - 84
F_R = \frac{12}{84} [650] - 84
F_R = \frac{7800}{84} - 84
F_R = 8.857
Step 8: State Results
Since FR is greater than 5.991 , We reject the Null Hypothesis.
Step 9: State Conclusion
- All the three drugs do not have the same probability distribution.
- You can apply the Post Hoc analysis with Wilcoxon Test to know which pairs have a significant difference between them.
Here,
Total number of pairs can be 3 (Drug A - Drug B , Drug B - Drug C , Drug A - Drug C).
The new level of significance to be considered for each pair will be 0.05/3 = 0.0166.
Implementation of Friedman Test using R
R
# R program to illustrate
# Friedman Test
#input the data
y <- matrix(c(1.24,1.50,1.62,
1.71,1.85,2.05,
1.37,2.12,1.68,
2.53,1.87,2.62,
1.23,1.34,1.51,
1.94,2.33,2.86,
1.72,1.43,2.86),
nrow = 7, byrow = TRUE,
dimnames = list(Person= as.character(1:7),Drugs = c("Drug A","Drug B","Drug C")))
#display the sample data
print(y)
Output:
R
#perform friedman test on the sample
result = friedman.test(y)
print(result)
Output:

As the p-value is less than the significance level (5%) it can be concluded that there are significant differences in the probability distribution.
Similar Reads
Basics & Prerequisites
Data Structures
Array Data StructureIn this article, we introduce array, implementation in different popular languages, its basic operations and commonly seen problems / interview questions. An array stores items (in case of C/C++ and Java Primitive Arrays) or their references (in case of Python, JS, Java Non-Primitive) at contiguous
3 min read
String in Data StructureA string is a sequence of characters. The following facts make string an interesting data structure.Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.Strings are immut
2 min read
Hashing in Data StructureHashing is a technique used in data structures that efficiently stores and retrieves data in a way that allows for quick access. Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash function. It enables fast retrieval of information based on its key. The
2 min read
Linked List Data StructureA linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays. Like arrays, it is also used to implement other data structures like stack, queue and deque. Hereâs the comparison of Linked List vs Arrays Linked List:
2 min read
Stack Data StructureA Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first
2 min read
Queue Data StructureA Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order. It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. It is used as a buffer in computer systems
2 min read
Tree Data StructureTree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes. Types of TreeBinary Tree : Every node has at most two childrenTernary Tree : Every node has at most
4 min read
Graph Data StructureGraph Data Structure is a collection of nodes connected by edges. It's used to represent relationships between different entities. If you are looking for topic-wise list of problems on different topics like DFS, BFS, Topological Sort, Shortest Path, etc., please refer to Graph Algorithms. Basics of
3 min read
Trie Data StructureThe Trie data structure is a tree-like structure used for storing a dynamic set of strings. It allows for efficient retrieval and storage of keys, making it highly effective in handling large datasets. Trie supports operations such as insertion, search, deletion of keys, and prefix searches. In this
15+ min read
Algorithms
Searching AlgorithmsSearching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input
2 min read
Sorting AlgorithmsA Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ
3 min read
Introduction to RecursionThe process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. A recursive algorithm takes one step toward solution and then recursively call itself to further move. The algorithm stops once we reach the solution
14 min read
Greedy AlgorithmsGreedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get
3 min read
Graph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net
3 min read
Dynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of
3 min read
Bitwise AlgorithmsBitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift.BasicsIntroduction to Bitwise Algorit
4 min read
Advanced
Segment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree
3 min read
Pattern SearchingPattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data. Patten SearchingImportant Pattern Searching Algorithms:Naive String Matching : A Simple Algorithm that works i
2 min read
GeometryGeometry is a branch of mathematics that studies the properties, measurements, and relationships of points, lines, angles, surfaces, and solids. From basic lines and angles to complex structures, it helps us understand the world around us.Geometry for Students and BeginnersThis section covers key br
2 min read
Interview Preparation
Practice Problem