# Simple data simulator for the Rasch Model

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**R Snippets for IRT**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

### The function:

This is a **very simple** data simulator for the Rasch Model.This is just to get you started, from here is easy to add function parameters for indicating item locations or person distribution characteristics.

- The function accepts only two parameters:
- The number of items
- The number of persons

- The function creates a list containing three objects:
- A vector of item locations
- A vector of person locations
- A matrix of simulated responses

### The code:

```
rasch.sim <- function( nitem = 20, npers = 100 ) {
i.loc <- rnorm( nitem )
p.loc <- rnorm( npers )
temp <- matrix( rep( p.loc, length( i.loc ) )
, ncol = length( i.loc ) )
logits <- t( apply( temp, 1, '-', i.loc) )
probabilities <- 1 / ( 1 + exp( -logits ) )
resp.prob <- matrix( probabilities, ncol = nitem)
obs.resp <- matrix( sapply( c(resp.prob), rbinom, n = 1, size = 1), ncol = length(i.loc) )
output <- list()
output$i.loc <- i.loc
output$p.loc <- p.loc
output$resp <- obs.resp
output
}
```

### Example:

This is a simple example that uses the Extending the Rasch Model (eRm) package to estimate the model parameters after simulating the data. Do try this at home!

```
###### Loading Libraries ######
# install.packages('eRm')
library(eRm)
###### Running Simulation ######
sim1 <- rasch.sim( npers = 10000)
sim.parameters <- sim1$i.loc
###### Estimation Using eRm ######
analysis.eRm <- RM(sim1$resp)
eRm.estimates <- (analysis.eRm$betapar) * -1
plot(sim.parameters, eRm.estimates)
```

To

**leave a comment**for the author, please follow the link and comment on their blog:**R Snippets for IRT**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.