Skip to main content
added 747 characters in body
Source Link
philchalmers
  • 3.1k
  • 1
  • 18
  • 23

Finally, (arbitrarily) estimate this model by using pars = sv, and use the returned object to calculate the factor scores. If you included the response patterns you are interested in then using fscores() directly work, otherwise use the response.vectorpattern option to estimate the patterns directly.

  mod <- mirt(dat, 1, pars = sv)
  fscores(mod)
  #more interested in pattern: 0, 1, 1, 0, 1
  fscores(mod, response.vectorpattern = c(0,1,1,0,1))

Hope that's helpful.

EDIT: Since I posted this answer a while back, the mirtCAT package was developed as an extension to mirt and contains a helper function called generate.mirt_object() for setting up a suitable mirt model with known coefficients.

Here's how that can be done using the parameters above.

 library(mirtCAT)
 pars <- data.frame(a1 = c(1,.9,.8,1,1.1),
                    d = c(-1,0,1.5,-1.5,0),
                    g = c(.2,.15,.17,.19,.15))
 mod <- generate.mirt_object(pars, itemtype = '3PL')
 
 # trait scores for pattern: 0, 1, 1, 0, 1
 fscores(mod, response.pattern = c(0,1,1,0,1))

I think the wrapper version is less error prone, and certainly nicer to look at and understand.

Finally, (arbitrarily) estimate this model by using pars = sv, and use the returned object to calculate the factor scores. If you included the response patterns you are interested in then using fscores() directly work, otherwise use the response.vector option to estimate the patterns directly.

  mod <- mirt(dat, 1, pars = sv)
  fscores(mod)
  #more interested in pattern: 0, 1, 1, 0, 1
  fscores(mod, response.vector = c(0,1,1,0,1))

Hope that's helpful.

Finally, (arbitrarily) estimate this model by using pars = sv, and use the returned object to calculate the factor scores. If you included the response patterns you are interested in then using fscores() directly work, otherwise use the response.pattern option to estimate the patterns directly.

  mod <- mirt(dat, 1, pars = sv)
  fscores(mod)
  #more interested in pattern: 0, 1, 1, 0, 1
  fscores(mod, response.pattern = c(0,1,1,0,1))

Hope that's helpful.

EDIT: Since I posted this answer a while back, the mirtCAT package was developed as an extension to mirt and contains a helper function called generate.mirt_object() for setting up a suitable mirt model with known coefficients.

Here's how that can be done using the parameters above.

 library(mirtCAT)
 pars <- data.frame(a1 = c(1,.9,.8,1,1.1),
                    d = c(-1,0,1.5,-1.5,0),
                    g = c(.2,.15,.17,.19,.15))
 mod <- generate.mirt_object(pars, itemtype = '3PL')
 
 # trait scores for pattern: 0, 1, 1, 0, 1
 fscores(mod, response.pattern = c(0,1,1,0,1))

I think the wrapper version is less error prone, and certainly nicer to look at and understand.

added 43 characters in body
Source Link
philchalmers
  • 3.1k
  • 1
  • 18
  • 23

I can't find a way to do this in the ltm package, though it's relatively straightforward if you are willing to use the mirt package.

First, write out some arbitrary matrix or data frame consisting of possible but random response patterns. You can include the actual response patterns you are interested in as well for later use.

  dat <- matrix(sample(c(0,1), 10000, TRUE), ncol = 5)
  colnames(dat) <- paste0('item', 1:5)

Use this as the data input and to mirt() and give the option pars = 'values' to return a data frame containing parameter names, numbers, starting values, etc. Edit this object to contain the values you want for the intercepts, slopes, or whatever else, and set all the estimation logical to FALSE. This will cause the model to instantly converge with the parameters that you want.

  library(mirt)
  sv <- mirt(dat, 1, itemtype = '2PL''3PL', pars = 'values')
  #custom discrimination, andeasiness, itemand easinessguessing values
  sv$value[sv$name == 'a1'] <- c(1,.9,.8,1,1.1)
  sv$value[sv$name == 'd'] <- c(-1,0,1.5,-1.5,0)
  sv$value[sv$name == 'g'] <- c(.2,.15,.17,.19,.15)
  #set the parameters as fixed
  sv$est <- FALSE

Finally, (arbitrarily) estimate this model by using pars = sv, and use the returned object to calculate the factor scores. If you included the response patterns you are interested in then using fscores() directly work, otherwise use the response.vector option to estimate the patterns directly.

  mod <- mirt(dat, 1, itemtype = '2PL', pars = sv)
  fscores(mod)
  #more interested in pattern: 0, 1, 1, 0, 1
  fscores(mod, response.vector = c(0,1,1,0,1))

Hope that's helpful.

I can't find a way to do this in the ltm package, though it's relatively straightforward if you are willing to use the mirt package.

First, write out some arbitrary matrix or data frame consisting of possible but random response patterns. You can include the actual response patterns you are interested in as well for later use.

  dat <- matrix(sample(c(0,1), 10000, TRUE), ncol = 5)
  colnames(dat) <- paste0('item', 1:5)

Use this as the data input and to mirt() and give the option pars = 'values' to return a data frame containing parameter names, numbers, starting values, etc. Edit this object to contain the values you want for the intercepts, slopes, or whatever else, and set all the estimation logical to FALSE. This will cause the model to instantly converge with the parameters that you want.

  library(mirt)
  sv <- mirt(dat, 1, itemtype = '2PL', pars = 'values')
  #custom discrimination and item easiness values
  sv$value[sv$name == 'a1'] <- c(1,.9,.8,1,1.1)
  sv$value[sv$name == 'd'] <- c(-1,0,1.5,-1.5,0)
  #set the parameters as fixed
  sv$est <- FALSE

Finally, (arbitrarily) estimate this model by using pars = sv, and use the returned object to calculate the factor scores. If you included the response patterns you are interested in then using fscores() directly work, otherwise use the response.vector option to estimate the patterns directly.

  mod <- mirt(dat, 1, itemtype = '2PL', pars = sv)
  fscores(mod)
  #more interested in pattern: 0, 1, 1, 0, 1
  fscores(mod, response.vector = c(0,1,1,0,1))

Hope that's helpful.

I can't find a way to do this in the ltm package, though it's relatively straightforward if you are willing to use the mirt package.

First, write out some arbitrary matrix or data frame consisting of possible but random response patterns. You can include the actual response patterns you are interested in as well for later use.

  dat <- matrix(sample(c(0,1), 10000, TRUE), ncol = 5)
  colnames(dat) <- paste0('item', 1:5)

Use this as the data input and to mirt() and give the option pars = 'values' to return a data frame containing parameter names, numbers, starting values, etc. Edit this object to contain the values you want for the intercepts, slopes, or whatever else, and set all the estimation logical to FALSE. This will cause the model to instantly converge with the parameters that you want.

  library(mirt)
  sv <- mirt(dat, 1, itemtype = '3PL', pars = 'values')
  #custom discrimination, easiness, and guessing values
  sv$value[sv$name == 'a1'] <- c(1,.9,.8,1,1.1)
  sv$value[sv$name == 'd'] <- c(-1,0,1.5,-1.5,0)
  sv$value[sv$name == 'g'] <- c(.2,.15,.17,.19,.15)
  #set the parameters as fixed
  sv$est <- FALSE

Finally, (arbitrarily) estimate this model by using pars = sv, and use the returned object to calculate the factor scores. If you included the response patterns you are interested in then using fscores() directly work, otherwise use the response.vector option to estimate the patterns directly.

  mod <- mirt(dat, 1, pars = sv)
  fscores(mod)
  #more interested in pattern: 0, 1, 1, 0, 1
  fscores(mod, response.vector = c(0,1,1,0,1))

Hope that's helpful.

Source Link
philchalmers
  • 3.1k
  • 1
  • 18
  • 23

I can't find a way to do this in the ltm package, though it's relatively straightforward if you are willing to use the mirt package.

First, write out some arbitrary matrix or data frame consisting of possible but random response patterns. You can include the actual response patterns you are interested in as well for later use.

  dat <- matrix(sample(c(0,1), 10000, TRUE), ncol = 5)
  colnames(dat) <- paste0('item', 1:5)

Use this as the data input and to mirt() and give the option pars = 'values' to return a data frame containing parameter names, numbers, starting values, etc. Edit this object to contain the values you want for the intercepts, slopes, or whatever else, and set all the estimation logical to FALSE. This will cause the model to instantly converge with the parameters that you want.

  library(mirt)
  sv <- mirt(dat, 1, itemtype = '2PL', pars = 'values')
  #custom discrimination and item easiness values
  sv$value[sv$name == 'a1'] <- c(1,.9,.8,1,1.1)
  sv$value[sv$name == 'd'] <- c(-1,0,1.5,-1.5,0)
  #set the parameters as fixed
  sv$est <- FALSE

Finally, (arbitrarily) estimate this model by using pars = sv, and use the returned object to calculate the factor scores. If you included the response patterns you are interested in then using fscores() directly work, otherwise use the response.vector option to estimate the patterns directly.

  mod <- mirt(dat, 1, itemtype = '2PL', pars = sv)
  fscores(mod)
  #more interested in pattern: 0, 1, 1, 0, 1
  fscores(mod, response.vector = c(0,1,1,0,1))

Hope that's helpful.