How to Calculate Point-Biserial Correlation in R?
Last Updated :
24 Dec, 2021
In this article, we will discuss how to calculate Point Biserial correlation in R Programming Language.
Correlation measures the relationship between two variables. we can say the correlation is positive if the value is 1, the correlation is negative if the value is -1, else 0. Point biserial correlation returns the correlated value that exists between a binary variable and a continuous variable. we can calculate the point biserial correlation using the cor.test() function.
Syntax:
cor.test(data1,data2)
Parameters:
Example 1:
In this example, we will be using the cor.test() function with two vectors containing different data points to get the correlation between them in the R language.
R
data1= c (1:20)
data2= c (23:42)
print ( cor.test (data1,data2))
|
Output:
Pearson's product-moment correlation
data: data1 and data2
t = Inf, df = 18, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
1 1
sample estimates:
cor
1
Example 2:
In this example, we will be using the cor.test() function with the different columns of the given data frame get the correlation between them in the R language.
R
data= data.frame (col1= c (1,34,56,32,23),
col2= c (21,34,56,32,34))
print ( cor.test (data$col1,data$col2))
|
Output:
Pearson's product-moment correlation
data: data$col1 and data$col2
t = 4.7383, df = 3, p-value = 0.01782
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.3323372 0.9960865
sample estimates:
cor
0.9392161
Share your thoughts in the comments
Please Login to comment...