philchalmers / mirt

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

fscore method="plausible" with fewer than 2 plausible.draws fails #178

Closed jessekps closed 4 years ago

jessekps commented 4 years ago

Hi,

I have an object of type 'multipleGroup', created like so:

est = multipleGroup(data = dat, itemtype = '2PL', model = 1, group = attr(dat, "booklet_id"), invariance = c("free_means", "free_var", "slopes", "intercepts"), pars = m)

I want 1 plausible value for each student, which I try to get like this:

pv = fscores(est,'plausible')

This fails with error message:

Error in matrix(NA, nrow(est@Data$data), ncol(ret[[1L]][[1L]])) : non-numeric matrix extent

As far as I can tell this is because in fscores.internal.R around line 590

ret <- vector('list', length(pars))
for(g in seq_len(ngroups)){
            tmp_obj <- MGC2SC(object, g)
            ret[[g]] <- fscores(tmp_obj, rotate = rotate, full.scores=full.scores, method=method,
                           quadpts=quadpts, returnER=returnER, verbose=verbose, theta_lim=theta_lim,
                                mean=gmean[[g]], cov=gcov[[g]], MI=MI, plausible.draws=plausible.draws,
                           full.scores.SE=full.scores.SE, return.acov=return.acov, QMC=QMC, ...)
}

the call

fscores(tmp_obj,... returns a matrix instead of a list when plausible.draws < 2 or when method='plausible' and a few lines further, this

colnames(out) <- colnames(ret[[1L]][[1L]])

retuires the elements of ret to be lists.

So this works:

pv = fscores(est,plausible.draws=2)

and my problem is solved but I thought you might like to know nonetheless.

philchalmers commented 4 years ago

Thanks, this was definitely not intended. I've patched this so that passing pv = fscores(est,'plausible') will return a matrix of values for MG models, whereas pv = fscores(est,plausible.draws=2) will still return a list of matrices.