(This article was first published on

**R Snippets for IRT**, and kindly contributed to R-bloggers)### 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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...