0

I am using the following R function for an IRT analysis:

item.diff.rasch(item)

As the manual says, item is a matrix containing information on item responses. I would like to generate this matrix from a txt-file containing a table with test data.

My problem is that I don't know what format this table needs to have so that I can generate a matrix for the R function from it.

Robert Rouhani
  • 14,512
  • 6
  • 44
  • 59
  • I believe it is from `psych` package. Note the the documentation is clear : `Under development. Not recommended for public consumption. See irt.fa and score.irt for far better options.` – agstudy Aug 11 '13 at 10:50
  • Please make your question [fully reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) as it makes it much easier to answer. – geotheory Aug 11 '13 at 13:02
  • Yes, it is from the psych package and as said in the comment by adstudy one can really not properly use the package. So I switched to the ltm package which seems to be a full implementation of the Item Response Theory. Does one of you have experience with the ltm package? – user2672005 Aug 11 '13 at 16:14

1 Answers1

0

Is your question is about how to get the data into R? If you have your raw data in a .txt or .csv file, then you can read it in as follows:

mydata <- as.matrix(read.csv("myfile.txt"))

See ?read.csv for various options, of which header might be the most relevant. read.csv creates a data frame, and then as.matrix converts it to the matrix structure you want. Another good thing to try is str(some_object) which will show you how an object is stored. For instance, you can break the command above into two steps:

mydf <- read.csv("myfile.txt")
str(mydf)
mymat <- as.matrix(mydf)
str(mymat)

To see more clearly what R is doing.

Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78
  • That was already very helpful. Thank you. I have entered a table with the following format: 1 1 1 1 1 0 1 1 1 0 0 1 I executed the follwoing code: library(psych) mydata <- as.matrix(read.csv("item.txt")) difficulty <- irt.item.diff.rasch(mydata) And this error message: Error in colMeans(items, na.rm = TRUE) : 'x' must be numeric Calls: irt.item.diff.rasch -> colMeans Execution halted How can I fix that? There is no non-numeric information in the table. – user2672005 Aug 11 '13 at 15:39
  • Even though it seems numeric, it may have been read in as character for some reason (did Excel touch it?), or integer (more likely), and the functions processing it didn't catch that. `str(mydata)` should tell you how it was stored. If character or integer, use `mydata <- as.numeric(mydata)` and then try it. If that doesn't work, do `dput(head(mydata))` and paste what you get into your original question so we can troubleshoot. – Bryan Hanson Aug 11 '13 at 20:19