0

I’m an R convert from a graduate program that taught exclusively SPSS, so I’m having to constantly fill in knowledge gaps when it comes to R packages. Apologies, therefore, for what may be a very simple question.

I’m currently using the “mirt” package from Chalmers to simulate dichotomous item response data based on previously published item parameters. I’d like to create, say, 500 simulated datasets (using the simdata and mirt functions). Based on those simulated datasets, I’d also like to generate latent trait scores from each one (using the fscores function). Is there some way that I can have those processes run all 500 times automatically (i.e., I’m really not wanting to have to run the same code 500 times by manually pressing up and enter again and again)?

Ideally, at the end of all 500 sample generations, I’d have a dataset consisting of just the latent trait scores and raw number of correctly answered items for each simulated dataset and another dataset consisting of a pooled tertachoric correlation matrix of each test item (40 item test) from the simulated data. For the latter I’m looking at “metaSEM” package from Cheung for this latter step.

I’ve tried using the rep() function only to get the same parameters entered into a data frame 500 times, so I figure that I must be doing something wrong. Any help is welcome!

pogibas
  • 27,303
  • 19
  • 84
  • 117
Goette
  • 13
  • 4
  • Sounds like you're looking to learn how to iterate in R. Here's some [helpful material](http://r4ds.had.co.nz/iteration.html) you could check out. – Mikko Marttila Nov 01 '17 at 05:13
  • If you're looking for more detailed or specific advice, you should show us what you've tried (your code), preferably in [a minimal reproducible example](https://stackoverflow.com/q/5963269/4550695). – Mikko Marttila Nov 01 '17 at 05:16
  • You could also try the `SimDesign` package in R to do such replications and summaries. There are even some examples that use `mirt` on the associated Github wiki page. – philchalmers Jun 12 '18 at 14:10

0 Answers0