How to Find Correlation Coefficient p value in R

How to Find Correlation Coefficient p value in R, linear relationship between two variables can be quantified using the Pearson correlation coefficient.

The value of this correlation coefficient is always between -1 and 1, where:

-1: A linear correlation between two variables that is perfectly negative
0: The pair of variables do not correlate linearly.
+1: The variables have a perfect positive linear connection with the other.
A correlation coefficient’s corresponding t-score and p-value can be computed to see if it is statistically significant.

R Error Continuous value supplied to discrete scale » finnstats

The correlation coefficient (r) t-score can be computed using the following formula:

t = r√n-2 / √1-r2

The corresponding two-sided p-value for the t-distribution with n-2 degrees of freedom is used to determine the p-value.

You can use the cor.test() function in R to get the p-value for a Pearson correlation coefficient.

cor.test(x, y)

An example of how to utilize this function in real life is provided below.

Example: Use R to get the P-Value for the correlation coefficient.

The code below demonstrates how to determine the p-value for the correlation coefficient between two variables in R using the cor.test() function:

x <- c(710, 718, 920, 817, 834, 886, 951, 474, 683, 485)
y <- c(490, 594, 279, 286, 284, 283, 888, 392, 276, 275)

#calculate correlation coefficient and corresponding p-value
cor.test(x, y)
earson's product-moment correlation

data:  x and y
t = 0.74819, df = 8, p-value = 0.4758
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.4456532  0.7625712
sample estimates:
      cor 
0.2557295 

From the output we can see:

The Pearson correlation coefficient is 0.2557295.
The corresponding p-value is 0.4758.

There is a positive linear relationship between the two variables, as indicated by the positive correlation coefficient.

Nevertheless, the association is not statistically significant because the p-value of the correlation coefficient is not less than 0.05.

To extract simply the p-value for the correlation coefficient, note that we may also enter cor.test(x, y)$p.value:

How to Check if a Directory Exists in R » Data Science Tutorials

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

five × 3 =