To calculate polychoric correlation in R, you can use polycor() function from polycor package. The polychoric correlation measures the association between two ordinal variables by estimating the correlation between the underlying continuous variables.

The following method shows how you can do it with syntax.

Method: Use polycor() Function

library(polycor)

polychor(vector1,vector2)

There is value for polychoric correlation ranges from -1 to 1. -1 :-indicates a perfect negative correlation. 0:- indicates no correlation. 1:- indicates a perfect positive correlation.

The following example shows how to calculate polychoric correlation in R using polycor() function from polycor package.

Using polycor() Function

Let’s see how we can calculate polychoric correlation using polycor() function.

# Import polycor library
library(polycor)

# Create data frames
df1 <- data.frame(Machine_name=c("A1","B1","C1","D1","E1","F1","G1","H1"),
                 Status=c(1,1,2,3,3,2,2,1))

df2 <- data.frame(Machine_name=c("A1","B1","C1","D1","E1","F1","G1","H1"),
                 Status=c(2,1,1,2,1,3,3,1))

# Calculate polychoric correlation
x <- polychor(df1$Status,df2$Status)

# Print polychoric correlation
print(x)

Output:

[1] 0.1838185

Here the output shows polychoric correlation between Status column of both data frame.