Spearman Correlation Testing in R Programming Last Updated : 28 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Spearman Correlation Testing in R programming is a statistical method used to evaluate the strength and direction of a monotonic relationship between two ranked variables. Unlike Pearson correlation, it does not assume normal distribution or linearity, making it ideal for ordinal data and non-linear associations.Spearman’s correlation, often denoted as Spearman’s rho (\rho), measures the strength and direction of the monotonic relationship between two ranked variables. It ranges from -1 to +1:+1: A perfect positive monotonic relationship. 0: No monotonic relationship.-1: A perfect negative monotonic relationship.Formula: [\rho = 1 - \frac{6 \sum d_i^2}{n(n^2 - 1)}]Where:\rho is the Spearman Correlation coefficient d_i is the difference between the ranks of corresponding variables.n is the number of observations.Implementation of Spearman Correlation Testing in RWe calculate the Spearman correlation using two methods in R programming language.1. Calculating Spearman Correlation Using cor() FunctionWe calculate the Spearman correlation coefficient between two numeric vectors using cor() to get only the correlation coefficient.cor: Calculates the correlation coefficient between two numeric vectors.method: Specifies the type of correlation method (here, it is "spearman").cat: Used to concatenate and print the final correlation value. R x = c(15, 18, 21, 15, 21) y = c(25, 25, 27, 27, 27) result = cor(x, y, method = "spearman") cat("Spearman correlation coefficient is:", result) Output:Spearman correlation coefficient is: 0.45643552. Calculating Spearman Correlation Using cor.test() FunctionWe compute the Spearman correlation coefficient using cor.test() to get both the coefficient and p-value for hypothesis testing.cor.test: Performs a test of association or correlation between two numeric vectors.method: Specifies the type of correlation method (here, it is "spearman"). R x = c(15, 18, 21, 15, 21) y = c(25, 25, 27, 27, 27) result = cor.test(x, y, method = "spearman") print(result) Output:OutputS is the value of the test statistic (S = 10.871)p-value is the significance level of the test statistic (p-value = 0.4397).alternative hypothesis is a character string describing the alternative hypothesis (true rho is not equal to 0).sample estimates is the correlation coefficient. For Spearman correlation coefficient it’s named as rho (Cor.coeff = 0.4564). Spearman Correlation Testing in R Programming Comment More infoAdvertise with us A AmiyaRanjanRout Follow Improve Article Tags : R Language data-science R Machine-Learning Explore R Tutorial | Learn R Programming Language 4 min read IntroductionR Programming Language - Introduction 4 min read Interesting Facts about R Programming Language 4 min read R vs Python 5 min read Environments in R Programming 3 min read Introduction to R Studio 4 min read How to Install R and R Studio? 4 min read Creation and Execution of R File in R Studio 5 min read Clear the Console and the Environment in R Studio 2 min read Hello World in R Programming 2 min read Fundamentals of RBasic Syntax in R Programming 3 min read Comments in R 3 min read R-Operators 5 min read R-Keywords 2 min read R-Data Types 5 min read VariablesR Variables - Creating, Naming and Using Variables in R 5 min read Scope of Variable in R 5 min read Dynamic Scoping in R Programming 5 min read Lexical Scoping in R Programming 4 min read Input/OutputTaking Input from User in R Programming 7 min read Printing Output of an R Program 4 min read Print the Argument to the Screen in R Programming - print() Function 2 min read Control FlowControl Statements in R Programming 4 min read Decision Making in R Programming - if, if-else, if-else-if ladder, nested if-else, and switch 3 min read Switch case in R 2 min read For loop in R 5 min read R - while loop 5 min read R - Repeat loop 2 min read goto statement in R Programming 2 min read Break and Next statements in R 3 min read FunctionsFunctions in R Programming 5 min read Function Arguments in R Programming 4 min read Types of Functions in R Programming 6 min read Recursive Functions in R Programming 4 min read Conversion Functions in R Programming 4 min read Data StructuresData Structures in R Programming 4 min read R Strings 6 min read R-Vectors 4 min read R-Lists 6 min read R - Array 7 min read R-Matrices 10 min read R-Factors 4 min read R-Data Frames 6 min read Object Oriented ProgrammingR-Object Oriented Programming 7 min read Classes in R Programming 3 min read R-Objects 3 min read Encapsulation in R Programming 3 min read Polymorphism in R Programming 6 min read R - Inheritance 7 min read Abstraction in R Programming 3 min read Looping over Objects in R Programming 5 min read S3 class in R Programming 8 min read Explicit Coercion in R Programming 3 min read Error HandlingHandling Errors in R Programming 3 min read Condition Handling in R Programming 5 min read Debugging in R Programming 3 min read Like