## Simulate Responses according to the two-parameter ## Normal Ogive or Logistic 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 sim2PNO <- function(N,K) { theta <- rnorm(N) theta <- (theta - mean(theta))/sqrt(var(theta)) alpha <- rnorm(K,mean=1,sd=.1) beta <- rnorm(K,sd=.5) beta <- beta - mean(beta) par <- theta %*% matrix(alpha,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,alpha,beta)) } #Example N <- 1000 K <- 20 sim <- sim2PNO(N,K) Y <- matrix(sim[[1]],ncol=K,nrow=N) theta <- matrix(sim[[2]],ncol=1,nrow=N) alpha <- matrix(sim[[3]],ncol=1,nrow=K) beta <- matrix(sim[[4]],ncol=1,nrow=K)