Question about running latent regression for mirt

416 views
Skip to first unread message

Tongyun

unread,
May 1, 2015, 2:23:01 PM5/1/15
to mirt-p...@googlegroups.com
Hi Phil,

I want to run a 2-dimensional IRT model with latent regression, two covariates for each latent trait. In this case, how do I format covdata and how shall I specify formula?

It seems that your example in the manual only applies to unidimensional cases.
X1 <- rnorm(N); X2 <- rnorm(N)
covdata <- data.frame(X1, X2)
mod1 <- mirt(dat, 1, 'Rasch', covdata=covdata, formula = ~ X1 + X2)

Thank you in advance!

Tongyun

Phil Chalmers

unread,
May 1, 2015, 3:12:36 PM5/1/15
to Tongyun, mirt-package

Hi Tongyun,

Just replace the 1 with something defined by mirt.model() representing a two dimensional pattern, and the rest will work. Cheers.

Phil

>
> Thank you in advance!
>
> Tongyun
>

> --
> You received this message because you are subscribed to the Google Groups "mirt-package" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mirt-package...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Tongyun

unread,
May 1, 2015, 5:00:08 PM5/1/15
to mirt-p...@googlegroups.com, tongy...@gmail.com
Thanks Phil! It works, but I have two follow-up questions:

1) I ran a confirmatory simple-structure 2-dimensional MIRT, everything worked until the last step when I requested for plausible values, I got error message saying Error in `colnames<-`(`*tmp*`, value = "SE_") : length of 'dimnames' [2] not equal to array extent". I wonder if there is anything wrong in my use of fscore() function. Below is my code:

#Model
Q=matrix(c(rep(1,34),rep(0,39),rep(0,34),rep(1,39)), ncol=2,byrow=F, dimnames = list(NULL, c('V1', 'V2')))
COV=matrix(c(FALSE, TRUE, TRUE, FALSE), 2)
model=mirt.model(Q, COV=COV)
#Covariate
N <- 5000

X1 <- rnorm(N); X2 <- rnorm(N)
covdata <- data.frame(X1, X2)
#Latent Regression
mod1 = mirt(data, model, covdata=covdata, formula = ~ X1 + X2)
pv = fscores(mod1, plausible.draws = 5)

2) My second question is, can I do a two-step estimation? Basically, I used the same model but fixed all the item parameters using item parameter estimates from a previous run, but I got an error message in the last step: "in UpdatePrepList(PrepList, pars, random = mixed.design$random,  :Rows in supplied and starting value data.frame objects do not match. Were the data or itemtype input arguments modified?" Did I do something wrong? Below is my code:

model=mirt.model(Q, COV=COV)
mod=mirt(data,model,pars='values')
mod$value[mod$name == 'a1']=a1
mod$value[mod$name == 'a2']=a2
mod$value[mod$name == 'd']=d
mod$est=FALSE
mod$est[mod$item == 'GROUP']=TRUE
mod2=mirt(data, model, pars=mod, covdata=covdata, formula = ~ X1 + X2)


Thank you very much for your help!

Phil Chalmers

unread,
May 1, 2015, 5:33:45 PM5/1/15
to Tongyun, mirt-package
Hi Tongyun,


On Fri, May 1, 2015 at 5:00 PM, Tongyun <tongy...@gmail.com> wrote:
Thanks Phil! It works, but I have two follow-up questions:

1) I ran a confirmatory simple-structure 2-dimensional MIRT, everything worked until the last step when I requested for plausible values, I got error message saying Error in `colnames<-`(`*tmp*`, value = "SE_") : length of 'dimnames' [2] not equal to array extent". I wonder if there is anything wrong in my use of fscore() function. Below is my code:

#Model
Q=matrix(c(rep(1,34),rep(0,39),rep(0,34),rep(1,39)), ncol=2,byrow=F, dimnames = list(NULL, c('V1', 'V2')))
COV=matrix(c(FALSE, TRUE, TRUE, FALSE), 2)
model=mirt.model(Q, COV=COV)
#Covariate
N <- 5000
X1 <- rnorm(N); X2 <- rnorm(N)
covdata <- data.frame(X1, X2)
#Latent Regression
mod1 = mirt(data, model, covdata=covdata, formula = ~ X1 + X2)
pv = fscores(mod1, plausible.draws = 5)

Sorry about this, it looks like I added a label too early which caused this crash. I've fixed it on the dev version, so feel free to install it for the fix (https://github.com/philchalmers/mirt).
 


2) My second question is, can I do a two-step estimation? Basically, I used the same model but fixed all the item parameters using item parameter estimates from a previous run, but I got an error message in the last step: "in UpdatePrepList(PrepList, pars, random = mixed.design$random,  :Rows in supplied and starting value data.frame objects do not match. Were the data or itemtype input arguments modified?" Did I do something wrong? Below is my code:

model=mirt.model(Q, COV=COV)
mod=mirt(data,model,pars='values')
mod$value[mod$name == 'a1']=a1
mod$value[mod$name == 'a2']=a2
mod$value[mod$name == 'd']=d
mod$est=FALSE
mod$est[mod$item == 'GROUP']=TRUE
mod2=mirt(data, model, pars=mod, covdata=covdata, formula = ~ X1 + X2)

This is close, but try using the mod2values() function first; this can be passed to pars.
E.g.,

oldmod <- mirt(...)
sv <- mod2values(oldmod) #starting values equal to last model
sv$values[1] <- 1 # make some edits if you want other values
newmod <- mirt(..., pars = sv)

Cheers.

Phil

Phil Chalmers

unread,
May 1, 2015, 5:45:52 PM5/1/15
to Tongyun, mirt-package
Oh I see why this didn't work now, the starting values are different for the two models (the first model makes no reference to the latent regression parameters, so the starting value data frames are a different size). Make the changes to the new starting values data frame, not the old one.

oldmod <- mirt(....)
sv <- mod2values()

newsv <- mirt(...., covdata, formula = ~ ....)
newsv$values[] # make changes here based on old parameters
newmod <- mirt(..., pars = newsv, covdata, formula = ~ ....)

Tongyun

unread,
May 4, 2015, 2:57:18 PM5/4/15
to mirt-p...@googlegroups.com, tongy...@gmail.com
Both worked! Thank you so much!
Reply all
Reply to author
Forward
0 new messages