- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 extract correlation coefficient value from correlation test in R?
To perform the correlation test in R, we need to use cor.test function with two variables and it returns so many values such as test statistic value, degrees of freedom, the p-value, the confidence interval, and the correlation coefficient value. If we want to extract the correlation coefficient value from the correlation test output then estimate function could be used as shown in below examples.
Example
x1<-rnorm(20,5,2) y1<-rnorm(20,5,1) cor.test(x1,y1)
Output
Pearson's product-moment correlation data: x1 and y1 t = -0.13423, df = 18, p-value = 0.8947 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.4675990 0.4167308 sample estimates: cor -0.03162132
cor.test(x1,y1)$estimate cor -0.08194057
Example
x2<-runif(5000,2,5) y2<-runif(5000,2,10) cor.test(x2,y2)
Output
Pearson's product-moment correlation data: x2 and y2 t = -1.4823, df = 4998, p-value = 0.1383 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.048653479 0.006760764 sample estimates: cor -0.02096246
cor.test(x2,y2)$estimate cor 0.01301688
Example
x3<-runif(50,2,5) y3<-runif(50,2,10) cor.test(x3,y3)
Output
Pearson's product-moment correlation data: x3 and y3 t = -0.80709, df = 48, p-value = 0.4236 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: -0.3817626 0.1680496 sample estimates: cor -0.1157106
cor.test(x3,y3)$estimate cor 0.1031475
Example
x4<-rexp(500,2.1) y4<-rexp(500,5.75) cor.test(y4,y4)
Output
Pearson's product-moment correlation data: y4 and y4 t = Inf, df = 498, p-value < 2.2e-16 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 1 1 sample estimates: cor 1
cor.test(y4,y4)$estimate cor 1
Example
x5<-rpois(100000,2) y5<-rpois(100000,5) cor.test(y5,y5)
Output
Pearson's product-moment correlation data: y5 and y5 t = 1.5006e+10, df = 99998, p-value < 2.2e-16 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 1 1 sample estimates: cor 1
cor.test(y5,y5)$estimate cor 1
- Related Articles
- How to find p-value for correlation coefficient in R?
- How to change the size of correlation coefficient value in correlation matrix plot using corrplot in R?
- How to convert a correlation matrix into a logical matrix based on correlation coefficient in R?
- How to find the group-wise correlation coefficient in R?
- How to avoid the warning “Cannot compute exact p-value with ties” while perform correlation test for Spearman’s correlation in R?
- How to find the correlation coefficient between two data frames in R?
- Program to find correlation coefficient in C++
- Karl Pearson Coefficient Of Correlation
- How to find the correlation coefficient between rows of two data frames in R?
- Find the combination of columns for correlation coefficient greater than a certain value 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 extract the p-value from t test in R?
- How to find the significant correlation in an R data frame?
- How to create correlation matrix plot without variables labels in R?

Advertisements