1

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 Answers1

1

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
Terru_theTerror
  • 4,918
  • 2
  • 20
  • 39
  • Thank you so much for your quick reply! However, I do get this reply; "> item values Error: unexpected symbol in "item values" > 1 item0 1 Error: unexpected symbol in "1 item0" and so forth... –  Mar 12 '18 at 10:52
  • Add a sample of you input data. – Terru_theTerror Mar 12 '18 at 10:54
  • Please see the image file I attached just now. I am terrible at this :) In your example, I don't understand how to use the "Your data"-codes. –  Mar 12 '18 at 11:03
  • Have a look here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Terru_theTerror Mar 12 '18 at 11:22