philchalmers / mirt

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

BFGS related Errors #205

Closed seonghobae closed 3 years ago

seonghobae commented 3 years ago

Hello, Can you check these errors?

Best, Seongho

> mirt::mirt(mirt::Science, 1, method = 'MHRM', optimizer = 'L-BFGS-B')
Error in ave.h[estpars & !redun_constr, estpars & !redun_constr]
  (subscript) logical subscript too long
> mirt::mirt(mirt::Science, 1, method = 'MHRM', optimizer = 'BFGS')
Error in ave.h[estpars & !redun_constr, estpars & !redun_constr]
  (subscript) logical subscript too long
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 21.04

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.13.so

locale:
 [1] LC_CTYPE=ko_KR.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=ko_KR.UTF-8        LC_COLLATE=ko_KR.UTF-8
 [5] LC_MONETARY=ko_KR.UTF-8    LC_MESSAGES=ko_KR.UTF-8
 [7] LC_PAPER=ko_KR.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=ko_KR.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6            lattice_0.20-44       permute_0.9-5
 [4] MASS_7.3-54           grid_4.1.0            nlme_3.1-152
 [7] stats4_4.1.0          vegan_2.5-7           Matrix_1.3-4
[10] splines_4.1.0         tools_4.1.0           dcurver_0.9.2
[13] Deriv_4.1.3           GPArotation_2014.11-1 parallel_4.1.0
[16] compiler_4.1.0        cluster_2.1.2         mgcv_1.8-36
[19] mirt_1.34
seonghobae commented 3 years ago

https://github.com/philchalmers/mirt/blob/b7150f0b7ae09cf284dcbfc2f2e37b45d799380e/R/MHRM.utils.R#L79 I guess this line has an error to do this.

philchalmers commented 3 years ago

Thanks, this was related to a recent change that avoided computing the Hessian when it was not used. Should be patched now.

seonghobae commented 3 years ago

I guess need to fix again for vertical scaling.

library('mirt')
set.seed(12345)
a <- matrix(abs(rnorm(15,1,.3)), ncol=1)
d <- matrix(rnorm(15,0,.7),ncol=1)
itemtype <- rep('2PL', nrow(a))
N <- 1000
dataset1 <- simdata(a, d, N, itemtype)
dataset2 <- simdata(a, d, N, itemtype, mu = .1, sigma = matrix(1.5))
dat <- rbind(dataset1, dataset2)
group <- c(rep('D1', N), rep('D2', N))
# vertical scaling (i.e., equating when groups answer items others do not)
dat2 <- dat
dat2[group == 'D1', 1:2] <- dat2[group != 'D1', 14:15] <- NA
head(dat2)
tail(dat2)

# items with missing responses need to be constrained across groups for identification
nms <- colnames(dat2)
mod_anchor <- multipleGroup(dat2, 1, group,
                            invariance = c(nms[c(1:5, 14:15)], 'free_means', 'free_var'), method = 'MHRM', optimizer = 'BFGS')
Error in L %*% h :
  Cholmod error 'X and/or Y have wrong dimensions' at file ../MatrixOps/cholmod_sdmult.c, line 88 
13.
L %*% h 
12.
L %*% h 
11.
updateHess(-h, L) 
10.
MHRM.deriv(pars = pars, gtheta = gtheta, lrPars = lrPars, OffTerm = OffTerm, 
    longpars = longpars, USE.FIXED = USE.FIXED, list = list, 
    ngroups = ngroups, LR.RAND = LR.RAND, DERIV = DERIV, gstructgrouppars = gstructgrouppars, 
    nfact = nfact, CUSTOM.IND = CUSTOM.IND, RAND = RAND, cycles = cycles,  ... 
9.
gr(par, ...) 
8.
(function (par) 
gr(par, ...))(c(a1 = 0.858029762402287, d = -0.705355822796004, 
a1 = 0.92646214777839, d = -0.0918796487849519, a1 = 1.10939589619799, 
d = -0.220129304877892, a1 = 0.943033886461536, d = 0.100905450181409,  ... 
7.
optim(shortpars, MHRM.LL_reload, gr = MHRM.deriv_reload, pars = pars, 
    gtheta = gtheta, lrPars = lrPars, OffTerm = OffTerm, longpars = longpars, 
    USE.FIXED = USE.FIXED, list = list, ngroups = ngroups, LR.RAND = LR.RAND, 
    DERIV = DERIV, has_graded = has_graded, nfact = nfact, CUSTOM.IND = CUSTOM.IND,  ... 
6.
MHRM.Mstep(pars = pars, gtheta = gthetatmp, lrPars = lrPars, 
    OffTerm = OffTerm, longpars = longpars, USE.FIXED = USE.FIXED, 
    list = list, ngroups = ngroups, LR.RAND = LR.RAND, DERIV = DERIV, 
    gstructgrouppars = gstructgrouppars, nfact = nfact, CUSTOM.IND = CUSTOM.IND,  ... 
5.
MHRM.group(pars = pars, constrain = constrain, Ls = Ls, PrepList = PrepList, 
    Data = Data, list = list(NCYCLES = opts$NCYCLES, BURNIN = opts$BURNIN, 
        SEMCYCLES = opts$SEMCYCLES, gain = opts$gain, KDRAWS = opts$KDRAWS, 
        MHDRAWS = opts$MHDRAWS, TOL = opts$TOL, SE = FALSE, SE.type = "none",  ... 
4.
ESTIMATION(data = data, model = model, group = group, invariance = invariance, 
    method = method, itemtype = itemtype, dentype = dentype, 
    ...) 
philchalmers commented 3 years ago

Same problem as before but with equality constraints. Should be patched now. Thanks!