Skip to content

Commit cf8bd41

Browse files
committed
fix and test bracket notation for special syntax inputs
1 parent d9f4404 commit cf8bd41

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

R/03-estimation.R

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,24 @@ ESTIMATION <- function(data, model, group, itemtype = NULL, guess = 0, upper = 1
262262
customGroup=customGroup[[1L]], spline_args=spline_args, monopoly.k=monopoly.k,
263263
fulldata=opts$PrepList[[1L]]$fulldata, key=key, opts=opts,
264264
gpcm_mats=gpcm_mats, internal_constraints=opts$internal_constraints,
265-
dcIRT_nphi=opts$dcIRT_nphi, dentype=opts$dentype, item.Q=opts$item.Q)
265+
dcIRT_nphi=opts$dcIRT_nphi, dentype=opts$dentype, item.Q=opts$item.Q,
266+
groupName=Data$groupNames[1])
267+
if(length(unique(Data$model$x[,'OptionalGroups'])) > 1){
268+
for(g in 2:Data$ngroups)
269+
PrepList[[g]] <-
270+
PrepData(data=Data$data, model=Data$model, itemtype=itemtype, guess=guess,
271+
upper=upper, parprior=parprior, verbose=opts$verbose,
272+
technical=opts$technical, parnumber=1L, BFACTOR=opts$dentype == 'bfactor',
273+
grsm.block=Data$grsm.block, rsm.block=Data$rsm.block,
274+
mixed.design=mixed.design, customItems=customItems,
275+
customItemsData=customItemsData,
276+
customGroup=customGroup[[1L]], spline_args=spline_args, monopoly.k=monopoly.k,
277+
fulldata=opts$PrepList[[1L]]$fulldata, key=key, opts=opts,
278+
gpcm_mats=gpcm_mats, internal_constraints=opts$internal_constraints,
279+
dcIRT_nphi=opts$dcIRT_nphi, dentype=opts$dentype, item.Q=opts$item.Q,
280+
groupName=Data$groupNames[g])
281+
282+
}
266283
if(!is.null(dots$Return_PrepList)) return(PrepListFull)
267284
if(!is.null(itemtypefull)){
268285
for(g in 2L:nrow(itemtypefull)){
@@ -276,7 +293,8 @@ ESTIMATION <- function(data, model, group, itemtype = NULL, guess = 0, upper = 1
276293
customGroup=customGroup[[1L]], spline_args=spline_args, monopoly.k=monopoly.k,
277294
fulldata=opts$PrepList[[1L]]$fulldata, key=key, opts=opts,
278295
gpcm_mats=gpcm_mats, internal_constraints=opts$internal_constraints,
279-
dcIRT_nphi=opts$dcIRT_nphi, dentype=opts$dentype, item.Q=opts$item.Q)
296+
dcIRT_nphi=opts$dcIRT_nphi, dentype=opts$dentype, item.Q=opts$item.Q,
297+
groupName=Data$groupNames[g])
280298
}
281299
}
282300
}
@@ -291,7 +309,7 @@ ESTIMATION <- function(data, model, group, itemtype = NULL, guess = 0, upper = 1
291309
matrix(sapply(PrepListFull$pars, function(y) length(y@parnum)), nrow=1L)
292310
for(g in seq_len(Data$ngroups)){
293311
if(g != 1L){
294-
if(is.null(itemtypefull))
312+
if(is.null(itemtypefull) && length(unique(Data$model$x[,'OptionalGroups'])) == 1)
295313
PrepList[[g]] <- list(pars=PrepList[[1L]]$pars)
296314
else attr(PrepList[[g]]$pars, 'nclasspars') <-
297315
sapply(PrepList[[g]]$pars, function(y) length(y@parnum))

R/04-PrepData.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ PrepData <- function(data, model, itemtype, guess, upper, gpcm_mats, opts,
22
parprior, verbose, technical, parnumber = 1, BFACTOR = FALSE,
33
grsm.block = NULL, rsm.block = NULL, mixed.design, customItems,
44
customGroup, customItemsData, fulldata = NULL, key,
5-
spline_args, internal_constraints, monopoly.k, dentype, dcIRT_nphi, item.Q)
5+
spline_args, internal_constraints, monopoly.k, dentype, dcIRT_nphi, item.Q,
6+
groupName)
67
{
8+
pick <- sapply(strsplit(model$x[,'OptionalGroups'], ','), \(x) any(x == groupName))
9+
model$x <- model$x[pick, , drop=FALSE]
710
if(is.null(grsm.block)) grsm.block <- rep(1, ncol(data))
811
if(is.null(rsm.block)) rsm.block <- rep(1, ncol(data))
912
grsm.block[!itemtype %in% c('grsm', 'grsmIRT')] <- NA

R/05-model.elements.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ model.elements <- function(model, factorNames, itemtype, nfactNames, nfact, J, K
22
itemloc, data, N, guess, upper, itemnames, exploratory, parprior,
33
parnumber, BFACTOR = FALSE, mixed.design, customItems, customItemsData,
44
dentype, item.Q, customGroup, key, gpcm_mats, spline_args,
5-
monopoly.k, dcIRT_nphi = NULL)
5+
monopoly.k, dcIRT_nphi = NULL, groupName)
66
{
77
hasProdTerms <- ifelse(nfact == nfactNames, FALSE, TRUE)
88
prodlist <- NULL

tests/testthat/test-09-mirt.model.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ test_that('syntax', {
4545
FIXED = (1-5, a1)
4646
START = (1-5, a1, 1.0)
4747
FREE = (GROUP, COV_11)")
48+
model15 <- mirt.model("F = 1-5
49+
FIXED [female] = (1-5, a1)
50+
START [female] = (1-5, a1, 1.0)
51+
FREE [male] = (GROUP, COV_11)
52+
MEAN [male] = F")
4853

4954
mod0 <- mirt(data, model0, verbose=FALSE, calcNull=FALSE)
5055
expect_equal(mod2values(mod0)$value, c(0.9879254,1.85606,0,1,1.080885,0.8079786,0,1,1.705801,1.804219,0,1,0.7651853,0.4859966,0,1,0.735798,1.854513,0,1,0,1),
@@ -91,6 +96,10 @@ test_that('syntax', {
9196
mod14 <- mirt(data, model14, verbose = FALSE)
9297
expect_equal(mod2values(mod14)$value, c(1,1.868016,0,1,1,0.7908857,0,1,1,1.46078,0,1,1,0.5214175,0,1,1,1.99271,0,1,0,1.021912),
9398
tolerance = 1e-2)
99+
mod15 <- multipleGroup(data, model15, group=group, verbose = FALSE)
100+
101+
expect_equal(as.integer(mod2values(mod15)$est), c(0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1))
102+
94103

95104
data(data.read, package = 'sirt')
96105
dat <- data.read

0 commit comments

Comments
 (0)