How to incorporate correlation into 2PL model

Hello R expert,
the following is 2PL model to generate dichotomous data. I want correlation of a and b is 0.8. How should I incorporate this correlation information into the twopl.sim function so that I can generate data that I wanted?

item difficulty parameter

item_b <- rnorm(200, mean=0, 2)

transpose item difficulty parameter

item_b1<-t(item_p)

item discrimination parameter

item_a <- rlnorm(200, mean=0, 0.1225)
#transpose item discrimination parameter
item_a1<-t(item_a)

twopl.sim <- function( nitem = 200, npers = 2688 ) {
i.loc <- item_b1
p.loc <- rnorm( npers )
i.slp <- item_a1
temp <- matrix( rep( p.loc, length( i.loc ) ), ncol = length( i.loc ) )
logits <- t( apply( temp , 1, '-', i.loc) )
logits <- t( apply( logits, 1, '*', i.slp) )

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$i.slp <- i.slp
output$p.loc <- p.loc
output$resp <- obs.resp

output
}

Thanks much for any help!

So, here your "a" parameter is item_a <- rlnorm(200, mean=0, 0.1225) and you want to generate "b" as item_b such that correlation of item_a and item_b is 0.8. Or the other way, first b and then generate a? Thanks

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.