philchalmers / mirt

Multidimensional item response theory
https://philchalmers.github.io/mirt/
200 stars 75 forks source link

Fit statistics in multigroup models with missing data #39

Closed tzoltak closed 9 years ago

tzoltak commented 9 years ago

When I try to compute fit statistics for multigroup model with missing data I encounter an error: Error in mod2values(x) : cannot get a slot ("est") from an object of type "S4"

The problem does not occur in multigroup models without missing data nor in in single-group models with missing data, but coincidence of this two features (multigroup and missing data) causes problems.

See:

# code from examples in help for itemfit()
set.seed(1234)
a <- matrix(rlnorm(20, meanlog=0, sdlog = .1),ncol=1)
d <- matrix(rnorm(20),ncol=1)
items <- rep('dich', 20)
data <- simdata(a,d, 2000, items)

# further part of the example in which missing data is added
data[sample(1:prod(dim(data)), 500)] <- NA
raschfit <- mirt(data, 1, itemtype='Rasch')

Theta <- fscores(raschfit, method = 'ML', full.scores=TRUE)
itemfit(raschfit, impute = 10, Theta=Theta)

# new code - multigroup Rasch model (with full measurement invariance)
raschGrFit = multipleGroup(data, 1,
                           group = c(rep("gr1", 1000), rep("gr2", 1000)),
                           invariance = c("free_means", "free_var",
                                          "slopes", "intercepts"),
                           itemtype = "Rasch")
# trying to compute itemfit (causes an error...)
ThetaGr <- fscores(raschGrFit, method = 'ML', full.scores=TRUE)
itemfit(raschGrFit, impute = 10, Theta=ThetaGr)
philchalmers commented 9 years ago

Thanks for the report, should be fixed now.

tzoltak commented 9 years ago

It works actually :) Many thanks!