How to Calculate Polychoric Correlation in R?
Last Updated :
19 Dec, 2021
In this article, we will discuss how to calculate polychoric correlation in R Programming Language.
Calculate Polychoric Correlation in R
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. Polychoric correlation is used to calculate the correlation between ordinal variables. It is similar to actual correlation conditions. We can calculate it by using polychor() method. It is available in polychor library so we need to import it.
Syntax: polychor(data1,data2)
where, data is the two input data
Example 1: Calculate polychoric correlation in two vectors
In this example, we will Calculate Polychoric Correlation between two vectors
R
library (polycor)
data1 = c (1, 2, 1, 2, 3, 4, 2, 3, 4, 5, 6)
data2 = c (1, 2, 1, 2, 3, 6, 7, 8, 6, 5, 5)
polychor (data1, data2)
|
Output:
[1] 0.5673752
Example 2: Calculate polychoric correlation in two columns of the dataframe
R
library (polycor)
data = data.frame ( data1= c (1, 2,1,2,3,4,2),
data2= c (3,6,7,8,6,5,5))
polychor (data$data1,data$data2)
|
Output:
[1] 0.02894605
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...