set.seed(1234)
n <- 30
N <- 500
# only first 5 items as anchors
model <- mirt.model('F = 1-30
CONSTRAINB = (1-5, a1), (1-5, d)')
a <- matrix(1, n)
d <- matrix(rnorm(n), n)
group <- c(rep('G1', N), rep('G2', N))
## -------------
# groups completely equal
dat1 <- simdata(a, d, N, itemtype = 'dich')
dat2 <- simdata(a, d, N, itemtype = 'dich')
dat <- rbind(dat1, dat2)
mod <- multipleGroup(dat, model, group=group, SE=TRUE, SE.type='crossprod',
invariance=c('free_means', 'free_var'))
plot(mod, type = 'score')
DTF(mod)
mirtCluster()
DTF(mod, MI = 1000) #95% C.I. for sDTI containing 0. uDTF is very small
## -------------
## random slopes and intercepts for 15 items, and latent mean difference
## (no systematic DTF should exist, but DIF will be present)
dat1 <- simdata(a, d, N, itemtype = 'dich', mu=.50, sigma=matrix(1.5))
dat2 <- simdata(a + c(numeric(15), sign(rnorm(n-15))*runif(n-15, .25, .5)),
d + c(numeric(15), sign(rnorm(n-15))*runif(n-15, .5, 1)), N, itemtype = 'dich')
dat <- rbind(dat1, dat2)
mod1 <- multipleGroup(dat, 1, group=group)
plot(mod1, type = 'score') #does not account for group differences! Need anchors
mod2 <- multipleGroup(dat, model, group=group, SE=TRUE, SE.type = 'crossprod',
invariance=c('free_means', 'free_var'))
plot(mod2, type = 'score')
#significant DIF in multiple items....
DIF(mod2, which.par=c('a1', 'd'), items2test=16:30)
DTF(mod2)
DTF(mod2, MI=1000)
## -------------
## systematic differing slopes and intercepts (clear DTF)
dat1 <- simdata(a, d, N, itemtype = 'dich', mu=.50, sigma=matrix(1.5))
dat2 <- simdata(a + c(numeric(15), rnorm(n-15, 1, .25)), d + c(numeric(15), rnorm(n-15, 1, .5)),
N, itemtype = 'dich')
dat <- rbind(dat1, dat2)
mod3 <- multipleGroup(dat, model, group=group, SE=TRUE, SE.type='crossprod',
invariance=c('free_means', 'free_var'))
plot(mod3, type = 'score') #visable DTF happening
DIF(mod3, c('a1', 'd'), items2test=16:30)
DTF(mod3) #unsigned bias. Signed bias indicates group 2 scores generally lower
DTF(mod3, MI=1000)
DTF(mod3, MI=1000, plot=TRUE)
Run the code above in your browser using DataLab