1

I'm trying to use cor.ci to obtain polychoric correlations with significance tests, but it keeps giving me an error message. Here is the code:

install.packages("Hmisc")
library(Hmisc)
mydata <- spss.get("S-IAT for R.sav", use.value.labels=TRUE)

install.packages('psych')
library(psych)
poly.example <- cor.ci(mydata(nvar = 10,n = 100)$items,n.iter = 10,poly = TRUE)
poly.example
print(corr.test(poly.example$rho), short=FALSE)

Here is the error message it gives:

> library(psych)  
> poly.example <- cor.ci(mydata(nvar = 10,n = 100)$items,n.iter = 10,poly = TRUE)  
Error in cor.ci(mydata(nvar = 10, n = 100)$items, n.iter = 10, poly = TRUE) :  
  could not find function "mydata"  
> poly.example  
Error: object 'poly.example' not found  
> print(corr.test(poly.example$rho), short=FALSE) 
Error in is.data.frame(x) : object 'poly.example' not found 

How can I make it recognize mydata and/or select certain variables from this dataset for the analysis? I got the above code from here:
Polychoric correlation matrix with significance in R

Thanks!

Community
  • 1
  • 1
Ali
  • 53
  • 1
  • 5
  • I don't know anything about these packages, but you are treating `mydata` as a function here and seem to be trying to using it instead of the `sim.poly` function in the linked example. That's probably not what you're meant to be doing. – ping May 18 '15 at 21:16

1 Answers1

0

You have several problems. 1) As previously commented upon, you are treating mydata as a function, but you need to treat it as a data.frame. Thus the call should be

 poly.example <- cor.ci(mydata,n.iter = 10,poly = TRUE)

If you are trying to just get the first 100 cases and the first 10 variables, then

poly.example <- cor.ci(mydata[1:10,1:100],n.iter = 10,poly = TRUE)

2) Then, you do not want to run corr.test on the resulting correlation matrix. corr.test should be run on the data.

print(corr.test(mydata[1:10,1:100],short=FALSE)   

Note that corr.test is testing the Pearson correlation.

William Revelle
  • 1,200
  • 8
  • 15