## Simulate Responses according to the Rasch Model. J.-P. Fox, University of Twente, Augustus 2010. # normal ogive or logistic Rasch Model # K: number of items # N: number of items # theta : latent variable # beta : difficulty parameter simRasch <- function(N,K) { theta <- rnorm(N) theta <- (theta - mean(theta))/sqrt(var(theta)) beta <- rnorm(K,sd=.5) beta <- beta - mean(beta) par <- theta %*% matrix(1,nrow=1,ncol=K) - t( matrix(beta,nrow=K,ncol=N) ) #Normit probs <- matrix(pnorm(par),ncol = K,nrow = N) #Logit #probs <- matrix(1/(1+exp(-par)),ncol = K,nrow = N) Y <- matrix(runif(N*K),nrow = N, ncol = K) Y <- ifelse(Y < probs,1,0) return(list(Y,theta,beta)) } #example N = 1000 K= 10 sim <- simRasch(N,K) Y <- matrix(sim[[1]],ncol=K,nrow=N) #simulated responses theta <- matrix(sim[[2]],ncol=1,nrow=N) #simulated theta beta <- matrix(sim[[3]],ncol=1,nrow=K) #simulated beta