Learn R Programming

mirt (version 1.17.1)

mdirt: Multidimensional discrete item response theory

Description

mdirt fits a variety of item response models with discrete latent variables. Posterior classification accuracy for each response pattern may be obtained via the fscores function. The summary() function will display the category probability values given the class membership, which can also be displayed graphically with plot(), while coef() displays the raw coefficient values (and their standard errors, if estimated). Finally, anova() is used to compare nested models.

Usage

mdirt(data, model, itemtype = "lca", nruns = 1, return_max = TRUE,
  group = NULL, GenRandomPars = FALSE, verbose = TRUE, pars = NULL,
  technical = list(), ...)

Arguments

data
a matrix or data.frame that consists of numerically ordered data, with missing data coded as NA
model
number of classes to fit, or alternatively a mirt.model definition
itemtype
item types to use. Can be the 'lca' model for defining ordinal item response models (dichotomous items are a special case), 'nlca' for the unordered latent class model
nruns
a numeric value indicating how many times the model should be fit to the data when using random starting values. If greater than 1, GenRandomPars is set to true by default
return_max
logical; when nruns > 1, return the model that has the most optimal maximum likelihood criteria? If FALSE, returns a list of all the estimated objects
group
a factor variable indicating group membership used for multiple group analyses
GenRandomPars
logical; use random starting values
verbose
logical; turn on messages to the R console
pars
used for modifying starting values; see mirt for details
technical
technical input list, most interesting for discrete latent models by building a customTheta input. The default builds the integration grid for the latent class model with customTheta = diag(nclasses); see
...
additional arguments to be passed to the estimation engine. See mirt for more details and examples

'lca' model definition

The latent class IRT model with two latent classes has the form

$$P(x = k|\theta_1, \theta_2, a1, a2) = \frac{exp(s_k (a1 \theta_1 + a2 \theta_2))}{ \sum_j^K exp(s_j (a1 \theta_1 + a2 \theta_2))}$$

where the $\theta$ values generally take on discrete points (such as 0 or 1), and the $s_k$'s are the scoring values for each category. If the model is selected to be 'lca' then the $s_k$ values are fixed to s_k = 0:(ncat - 1), whereas if the model is 'nlca' the $s_k$ are all fixed to 1. For proper identification, the first category slope parameters ($a1$ and $a2$) are never freely estimated.

See Also

fscores, mirt.model, M2, itemfit, boot.mirt, mirtCluster, wald, coef-method, summary-method, anova-method, residuals-method

Examples

Run this code
#LSAT6 dataset
dat <- expand.table(LSAT6)

# fit with 2-3 latent classes
(mod2 <- mdirt(dat, 2))
(mod3 <- mdirt(dat, 3))
summary(mod2)
residuals(mod2)
residuals(mod2, type = 'exp')
anova(mod2, mod3)
M2(mod2)
itemfit(mod2)

#generate classification plots
plot(mod2)
plot(mod2, facet_items = FALSE)
plot(mod2, profile = TRUE)

# available for polytomous data
mod <- mdirt(Science, 2)
summary(mod)
plot(mod)
plot(mod, profile=TRUE)

# classification based on response patterns
fscores(mod2, full.scores = FALSE)

# classify individuals either with the largest posterior probability.....
fs <- fscores(mod2)
head(fs)
classes <- matrix(1:2, nrow(fs), 2, byrow=TRUE)
class_max <- classes[t(apply(fs, 1, max) == fs)]
table(class_max)

# ... or by probability sampling (closer to estimated class proportions)
class_prob <- apply(fs, 1, function(x) sample(1:2, 1, prob=x))
table(class_prob)

# fit with random starting points (run in parallel to save time)
mirtCluster()
mod <- mdirt(dat, 2, nruns=10)

#--------------------------
# Grade of measurement model

# define a custom Theta grid for including a 'fuzzy' class membership
(Theta <- matrix(c(1, 0, .5, .5, 0, 1), nrow=3 , ncol=2, byrow=TRUE))
(mod_gom <- mdirt(dat, 2, technical = list(customTheta = Theta)))
summary(mod_gom)

#-----------------
# Multidimensional discrete model

dat <- key2binary(SAT12,
     key = c(1,4,5,2,3,1,2,1,3,1,2,4,2,1,5,3,4,4,1,4,3,3,4,1,3,5,1,3,1,5,4,5))

# define Theta grid for three latent classes
(Theta <- matrix(c(0,0,0, 1,0,0, 0,1,0, 0,0,1, 1,1,0, 1,0,1, 0,1,1, 1,1,1),
   ncol=3, byrow=TRUE))
(mod_discrete <- mdirt(dat, 3, technical = list(customTheta = Theta)))
summary(mod_discrete)

Run the code above in your browser using DataLab