- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to avoid the warning “Cannot compute exact p-value with ties” while perform correlation test for Spearman’s correlation in R?
When the variables are not continuous but could be ranked then we do not use pearson correlation coefficient to find the linear relationship, in this case spearman correlation coefficient comes into the scene. Since the spearman correlation coefficient considers the rank of values, the correlation test ignores the same ranks to find the p-values as a result we get the warning “Cannot compute exact p-value with ties”. This can be avoided by using exact = FALSE inside the cor.test function.
Example
Consider the below vectors and perform spearman correlation test to check the relationship between them −
x1<-rpois(20,2) y1<-rpois(20,5) cor.test(x1,y1,method="spearman")
Output
Spearman's rank correlation rho data: x1 and y1 S = 1401.7, p-value = 0.8214 alternative hypothesis: true rho is not equal to 0 sample estimates: rho -0.05390585 Warning message: In cor.test.default(x1, y1, method = "spearman") : Cannot compute exact p-value with ties
Here, we have the warning for ties, this can be avoided by using exact=FALSE as shown below −
Example
cor.test(x1,y1,method="spearman",exact=FALSE)
Output
Spearman's rank correlation rho data: x1 and y1 S = 1401.7, p-value = 0.8214 alternative hypothesis: true rho is not equal to 0 sample estimates: rho -0.05390585
Let’s have a look at some more examples −
Example
x2<-sample(1:100,500,replace=TRUE) y2<-sample(1:50,500,replace=TRUE) cor.test(x2,y2,method="spearman")
Output
Spearman's rank correlation rho data: x2 and y2 S = 20110148, p-value = 0.4387 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.03470902 Warning message: In cor.test.default(x2, y2, method = "spearman") : Cannot compute exact p-value with ties
Example
cor.test(x2,y2,method="spearman",exact=FALSE)
Output
Spearman's rank correlation rho data: x2 and y2 S = 20110148, p-value = 0.4387 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.03470902
Example
x3<-sample(101:110,5000,replace=TRUE) y3<-sample(501:510,5000,replace=TRUE) cor.test(x3,y3,method="spearman")
Output
Spearman's rank correlation rho data: x3 and y3 S = 2.0642e+10, p-value = 0.5155 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.009199129 Warning message: In cor.test.default(x3, y3, method = "spearman") : Cannot compute exact p-value with ties
Example
cor.test(x3,y3,method="spearman",exact=FALSE)
Output
Spearman's rank correlation rho data: x3 and y3 S = 2.0642e+10, p-value = 0.5155 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.009199129
- Related Articles
- How to extract correlation coefficient value from correlation test in R?
- How to find p-value for correlation coefficient in R?
- How to find the correlation matrix with p-values for an R data frame?
- How to change the size of correlation coefficient value in correlation matrix plot using corrplot in R?
- How to round correlation values in the correlation matrix to zero decimal places in R?
- How to create correlation matrix plot in R?
- How to find the groupwise correlation matrix for an R data frame?
- How to convert a correlation matrix into a logical matrix based on correlation coefficient in R?
- How to deal with missing values to calculate correlation matrix in R?
- How to find the group-wise correlation coefficient in R?
- How to find the correlation matrix for rows of an R data frame?
- Find the combination of columns for correlation coefficient greater than a certain value in R
- How to find the correlation matrix of groups for a data.table object in R?
- How to find the significant correlation in an R data frame?
- How to create normal random variables with specific correlation between them in R?

Advertisements