1
votes

I would very much want help with the following - I have this SPSS dataset (.sav), where I have tested a 22-item scale (likert, 5 options from "totally disagree" to "totally agree"). I have 1,500 respondents, and I would like to do a POLYCHORIC CORRELATION MATRIX in the program 'R'.

I have read a few posts about this, but doesn't seem to get it right. I have named my 22 items "item1, item2, item3...", and the values are either 0, 1, 2, 3 or 4. I have installed both the "psych" and the "polycor" package.

Please help! Many thanks in advance!

1

1 Answers

1
votes

Try to adapt this code:

Your data

item<-paste0("item",seq(0,22,1))
df<-data.frame(item=rep(item,1000),
               values=round(runif(1000,0,4),0))
head(df)
   item values
1 item0      1
2 item1      1
3 item2      3
4 item3      1
5 item4      0
6 item5      4

Create correlation matrix

groups = unique(df$item)
cor_matrix<-sapply(1:length(groups), function(i)
  sapply(1:length(groups), function(j)
    cor(x = df$values[df$item == groups[i]], y = df$values[df$item == groups[j]])))

Plot correlation matrix

corrplot(cor_matrix, type = "upper", order = "hclust", 
         tl.col = "black", tl.srt = 45) #Visual approach

corrplot(cor_matrix, method = "number", col = "black", cl.pos = "n") #Numeric approach