| Type: | Package |
| Title: | Test Analysis Modules |
| Version: | 4.3-25 |
| Date: | 2025-08-28 18:03:24 |
| Maintainer: | Alexander Robitzsch <robitzsch@ipn.uni-kiel.de> |
| Description: | Includes marginal maximum likelihood estimation and joint maximum likelihood estimation for unidimensional and multidimensional item response models. The package functionality covers the Rasch model, 2PL model, 3PL model, generalized partial credit model, multi-faceted Rasch model, nominal item response model, structured latent class model, mixture distribution IRT models, and located latent class models. Latent regression models and plausible value imputation are also supported. For details see Adams, Wilson and Wang, 1997 <doi:10.1177/0146621697211001>, Adams, Wilson and Wu, 1997 <doi:10.3102/10769986022001047>, Formann, 1982 <doi:10.1002/bimj.4710240209>, Formann, 1992 <doi:10.1080/01621459.1992.10475229>. |
| Depends: | R (≥ 2.15.1), CDM (≥ 6.4-19) |
| Imports: | graphics, methods, Rcpp, stats, utils |
| Suggests: | coda, GPArotation, grDevices, lattice, lavaan, MASS,miceadds, mvtnorm, plyr, psych, sfsmisc, splines, WrightMap |
| LinkingTo: | Rcpp, RcppArmadillo |
| Enhances: | LSAmitR |
| License: | GPL-2 |GPL-3 [expanded from: GPL (≥ 2)] |
| URL: | http://www.edmeasurementsurveys.com/TAM/Tutorials/,https://github.com/alexanderrobitzsch/TAM,https://sites.google.com/view/alexander-robitzsch/software |
| NeedsCompilation: | yes |
| Packaged: | 2025-08-28 16:08:50 UTC; sunpn563 |
| Author: | Alexander Robitzsch |
| Repository: | CRAN |
| Date/Publication: | 2025-08-28 20:40:08 UTC |
Test Analysis Modules
Description
Includes marginal maximum likelihood estimation and joint maximum likelihood estimation for unidimensional and multidimensional item response models. The package functionality covers the Rasch model, 2PL model, 3PL model, generalized partial credit model, multi-faceted Rasch model, nominal item response model, structured latent class model, mixture distribution IRT models, and located latent class models. Latent regression models and plausible value imputation are also supported. For details see Adams, Wilson and Wang, 1997 <doi:10.1177/0146621697211001>, Adams, Wilson and Wu, 1997 <doi:10.3102/10769986022001047>, Formann, 1982 <doi:10.1002/bimj.4710240209>, Formann, 1992 <doi:10.1080/01621459.1992.10475229>.
Details
Seehttp://www.edmeasurementsurveys.com/TAM/Tutorials/ fortutorials of theTAM package.
Author(s)
NA
Maintainer: Alexander Robitzsch <robitzsch@ipn.uni-kiel.de>
References
Adams, R. J., Wilson, M., & Wang, W. C. (1997). The multidimensional random coefficientsmultinomial logit model.Applied Psychological Measurement, 21(1), 1-23.doi:10.1177/0146621697211001
Adams, R. J., Wilson, M., & Wu, M. (1997).Multilevel item response models: An approach to errors invariables regression.Journal of Educational and BehavioralStatistics, 22(1), 47-76.doi:10.3102/10769986022001047
Adams, R. J., & Wu, M. L. (2007). The mixed-coefficients multinomial logit model.A generalized form of the Rasch model. In M. von Davier & C. H. Carstensen (Eds.):Multivariate and mixture distribution Rasch models: Extensions and applications(pp. 55-76). New York: Springer.doi:10.1007/978-0-387-49839-3_4
Formann, A. K. (1982). Linear logistic latent class analysis.Biometrical Journal, 24(2), 171-190.doi:10.1002/bimj.4710240209
Formann, A. K. (1992). Linear logistic latent class analysis for polytomous data.Journal of the American Statistical Association, 87(418), 476-486.doi:10.1080/01621459.1992.10475229
S3 Method for Descriptive Statistics of Objects
Description
S3 method for descriptive statistics of objects
Usage
DescribeBy(object, ...)Arguments
object | An object |
... | Further arguments to be passed |
See Also
Wright Map for Item Response Models by Using theWrightMap Package
Description
This function creates a Wright map and works as a wrapper to thewrightMap function intheWrightMap package. The argumentsthetas andthresholds are automatically generated from fittedobjects inTAM.
Usage
## S3 method for class 'tam.mml'IRT.WrightMap(object, prob.lvl=.5, type="PV", ...)## S3 method for class 'tamaan'IRT.WrightMap(object, prob.lvl=.5, type="PV", ...)Arguments
object | |
prob.lvl | Requested probability level of thresholds. |
type | Type of person parameter estimate. |
... | Further arguments to be passed in the |
Details
A Wright map is only created for models with an assumed normal distribution.Hence, not for all models of thetamaan functionsWright maps are created.
Value
A Wright map generated by theWrightMap package.
Author(s)
TheIRT.WrightMap function is based on theWrightMap::wrightMap functionin theWrightMap package.
See Also
See theWrightMap::wrightMap function intheWrightMap package.
Examples
## Not run: library(WrightMap)############################################################################## EXAMPLE 1: Unidimensional models dichotomous data#############################################################################data(data.sim.rasch)str(data.sim.rasch)dat <- data.sim.rasch# fit Rasch modelmod1 <- TAM::tam.mml(resp=dat)# Wright mapIRT.WrightMap( mod1 )# some customized plotsIRT.WrightMap( mod1, show.thr.lab=FALSE, label.items=c(1:40), label.items.rows=3)IRT.WrightMap( mod1, show.thr.sym=FALSE, thr.lab.text=paste0("I",1:ncol(dat)), label.items="", label.items.ticks=FALSE)#--- direct specification with wrightMap functiontheta <- TAM::tam.wle(mod1)$thetathr <- TAM::tam.threshold(mod1)# default wrightMap plotsWrightMap::wrightMap( theta, thr, label.items.srt=90)WrightMap::wrightMap( theta, t(thr), label.items=c("items") )# stack all items below each otherthr.lab.text <- matrix( "", 1, ncol(dat) )thr.lab.text[1,] <- colnames(dat)WrightMap::wrightMap( theta, t(thr), label.items=c("items"), thr.lab.text=thr.lab.text, show.thr.sym=FALSE )############################################################################## EXAMPLE 2: Unidimensional model polytomous data#############################################################################data( data.Students, package="CDM")dat <- data.Students# fit generalized partial credit model using the tamaan functiontammodel <- "LAVAAN MODEL: SC=~ sc1__sc4 SC ~~ 1*SC "mod1 <- TAM::tamaan( tammodel, dat )# create item level colorslibrary(RColorBrewer)ncat <- 3 # number of category parametersI <- ncol(mod1$resp) # number of itemsitemlevelcolors <- matrix(rep( RColorBrewer::brewer.pal(ncat, "Set1"), I), byrow=TRUE, ncol=ncat)# Wright mapIRT.WrightMap(mod1, prob.lvl=.625, thr.sym.col.fg=itemlevelcolors, thr.sym.col.bg=itemlevelcolors, label.items=colnames( mod1$resp) )############################################################################## EXAMPLE 3: Multidimensional item response model#############################################################################data( data.read, package="sirt")dat <- data.read# fit three-dimensional Rasch modelQ <- matrix( 0, nrow=12, ncol=3 )Q[1:4,1] <- Q[5:8,2] <- Q[9:12,3] <- 1mod1 <- TAM::tam.mml( dat, Q=Q, control=list(maxiter=20, snodes=1000) )summary(mod1)# define matrix with colors for thresholdsc1 <- matrix( c( rep(1,4), rep(2,4), rep(4,4)), ncol=1 )# create Wright map using WLEIRT.WrightMap( mod1, prob.lvl=.65, type="WLE", thr.lab.col=c1, thr.sym.col.fg=c1, thr.sym.col.bg=c1, label.items=colnames(dat) )# Wright map using PV (the default)IRT.WrightMap( mod1, prob.lvl=.65, type="PV" )# Wright map using population distributionIRT.WrightMap( mod1, prob.lvl=.65, type="Pop" )############################################################################## EXAMPLE 4: Wright map for a multi-faceted Rasch model############################################################################## This example is copied from# http://wrightmap.org/post/107431190622/wrightmap-multifaceted-modelslibrary(WrightMap)data(data.ex10)dat <- data.ex10#--- fit multi-faceted Rasch modelfacets <- dat[, "rater", drop=FALSE] # define facet (rater)pid <- dat$pid # define person identifier (a person occurs multiple times)resp <- dat[, -c(1:2)] # item response dataformulaA <- ~item * rater # formulamod <- TAM::tam.mml.mfr(resp=resp, facets=facets, formulaA=formulaA, pid=dat$pid)# person parameterspersons.mod <- TAM::tam.wle(mod)theta <- persons.mod$theta# thresholdsthr <- TAM::tam.threshold(mod)item.labs <- c("I0001", "I0002", "I0003", "I0004", "I0005")rater.labs <- c("rater1", "rater2", "rater3")#--- Plot 1: Item specificthr1 <- matrix(thr, nrow=5, byrow=TRUE)WrightMap::wrightMap(theta, thr1, label.items=item.labs, thr.lab.text=rep(rater.labs, each=5))#--- Plot 2: Rater specificthr2 <- matrix(thr, nrow=3)WrightMap::wrightMap(theta, thr2, label.items=rater.labs, thr.lab.text=rep(item.labs, each=3), axis.items="Raters")#--- Plot 3a: item, rater and item*rater parameterspars <- mod$xsi.facets$xsifacet <- mod$xsi.facets$facetitem.par <- pars[facet=="item"]rater.par <- pars[facet=="rater"]item_rat <- pars[facet=="item:rater"]len <- length(item_rat)item.long <- c(item.par, rep(NA, len - length(item.par)))rater.long <- c(rater.par, rep(NA, len - length(rater.par)))ir.labs <- mod$xsi.facets$parameter[facet=="item:rater"]WrightMap::wrightMap(theta, rbind(item.long, rater.long, item_rat), label.items=c("Items", "Raters", "Item*Raters"), thr.lab.text=rbind(item.labs, rater.labs, ir.labs), axis.items="")#--- Plot 3b: item, rater and item*rater (separated by raters) parameters# parameters item*raterir_rater <- matrix(item_rat, nrow=3, byrow=TRUE)# define matrix of thresholdsthr <- rbind(item.par, c(rater.par, NA, NA), ir_rater)# matrix with threshold labelsthr.lab.text <- rbind(item.labs, rater.labs, matrix(item.labs, nrow=3, ncol=5, byrow=TRUE))WrightMap::wrightMap(theta, thresholds=thr, label.items=c("Items", "Raters", "Item*Raters (R1)", "Item*Raters (R2)", "Item*Raters (R3)"), axis.items="", thr.lab.text=thr.lab.text )#--- Plot 3c: item, rater and item*rater (separated by items) parameters# thresholdsir_item <- matrix(item_rat, nrow=5)thr <- rbind(item.par, c(rater.par, NA, NA), cbind(ir_item, NA, NA))# labelslabel.items <- c("Items", "Raters", "Item*Raters\n (I1)", "Item*Raters \n(I2)", "Item*Raters \n(I3)", "Item*Raters \n (I4)", "Item*Raters \n(I5)")thr.lab.text <- rbind(item.labs, matrix(c(rater.labs, NA, NA), nrow=6, ncol=5, byrow=TRUE))WrightMap::wrightMap(theta, thr, label.items=label.items, axis.items="", thr.lab.text=thr.lab.text )## End(Not run)Cross-Validation of a Fitted IRT Model
Description
This S3 method performs a cross-validation of a fitted item response model.
Usage
IRT.cv(object, ...)Arguments
object | Object |
... | Further arguments to be passed |
Value
Numeric value: the cross-validated deviance value
Extracting Item Response Dataset
Description
Extracts the used data set for modelsfitted inTAM. SeeCDM::IRT.datafor more details.
Usage
## S3 method for class 'tam.mml'IRT.data(object, ...)## S3 method for class 'tam.mml.3pl'IRT.data(object, ...)## S3 method for class 'tamaan'IRT.data(object, ...)Arguments
object | Object of class |
... | Further arguments to be passed |
Value
A dataset with item responses
Examples
## Not run: ############################################################################## EXAMPLE 1: Dichotomous data data.sim.rasch#############################################################################data(data.sim.rasch)dat <- data.sim.rasch# estimate modelmod1 <- TAM::tam.mml(dat)# extract dataset (and weights and group if available)dmod1 <- IRT.data(mod1)str(dmod1)## End(Not run)Function for Drawing Plausible Values
Description
This function draws plausible values of a continuous latent variablebased on a fitted object for which theCDM::IRT.posterior methodis defined.
Usage
IRT.drawPV(object,NPV=5)Arguments
object | Object for which the method |
NPV | Number of plausible values to be drawn. |
Value
Matrix with plausible values
Examples
## Not run: ############################################################################## EXAMPLE 1: Plausible value imputation for Rasch model in sirt#############################################################################library(sirt)data(data.read, package="sirt")dat <- data.read# fit Rasch modelmod <- rasch.mml2(dat)# draw 10 plausible valuespv1 <- TAM::IRT.drawPV(mod, NPV=10)## End(Not run)Extracting Expected Counts
Description
Extracts expected counts for modelsfitted inTAM. SeeCDM::IRT.expectedCountsfor more details.
Usage
## S3 method for class 'tam'IRT.expectedCounts(object, ...)## S3 method for class 'tam.mml'IRT.expectedCounts(object, ...)## S3 method for class 'tam.mml.3pl'IRT.expectedCounts(object, ...)## S3 method for class 'tamaan'IRT.expectedCounts(object, ...)## S3 method for class 'tam.np'IRT.expectedCounts(object, ...)Arguments
object | Object of class |
... | Further arguments to be passed |
Value
Examples
## Not run: ############################################################################## EXAMPLE 1: Dichotomous data data.sim.rasch - extract expected counts#############################################################################data(data.sim.rasch)# 1PL estimationmod1 <- TAM::tam.mml(resp=data.sim.rasch)# extract expected countsIRT.expectedCounts(mod1)## End(Not run)Extracting Factor Scores inTAM
Description
Extracts factor scores for modelsfitted inTAM. SeeCDM::IRT.factor.scoresfor more details.
Usage
## S3 method for class 'tam'IRT.factor.scores(object, type="EAP", ...)## S3 method for class 'tam.mml'IRT.factor.scores(object, type="EAP", ...)## S3 method for class 'tam.mml.3pl'IRT.factor.scores(object, type="EAP", ...)## S3 method for class 'tamaan'IRT.factor.scores(object, type="EAP", ...)Arguments
object | Object of class |
type | Type of factor score to be used. |
... | Further arguments to be passed |
Value
Examples
## Not run: ############################################################################## EXAMPLE 1: data.sim.rasch - Different factor scores in Rasch model#############################################################################data(data.sim.rasch)# 1PL estimationmod1 <- TAM::tam.mml(resp=data.sim.rasch)# EAPpmod1 <- IRT.factor.scores( mod1 )# WLEpmod1 <- IRT.factor.scores( mod1, type="WLE" )# MLEpmod1 <- IRT.factor.scores( mod1, type="MLE" )## End(Not run)Observed and Expected Frequencies for Univariate and Bivariate Distributions
Description
Computes observed and expected frequencies for univariate and bivariate distributionsfor models fitted inTAM. SeeCDM::IRT.frequenciesfor more details.
Usage
## S3 method for class 'tam.mml'IRT.frequencies(object, ...)## S3 method for class 'tam.mml.3pl'IRT.frequencies(object, ...)## S3 method for class 'tamaan'IRT.frequencies(object, ...)Arguments
object | Object of class |
... | Further arguments to be passed |
Value
See Also
Examples
## Not run: ############################################################################## EXAMPLE 1: Dichotomous data data.sim.rasch#############################################################################data(data.sim.rasch)dat <- data.sim.rasch# estimate modelmod1 <- TAM::tam.mml(dat)# compute observed and expected frequenciesfmod1 <- IRT.frequencies(mod1)str(fmod1)## End(Not run)Item and Test Information Curve
Description
An S3 method which computes item and test information curves, see Muraki (1993).
Usage
IRT.informationCurves(object, ...)## S3 method for class 'tam.mml'IRT.informationCurves( object, h=.0001, iIndex=NULL, theta=NULL, ... )## S3 method for class 'tam.mml.2pl'IRT.informationCurves( object, h=.0001, iIndex=NULL, theta=NULL, ... )## S3 method for class 'tam.mml.mfr'IRT.informationCurves( object, h=.0001, iIndex=NULL, theta=NULL, ... )## S3 method for class 'tam.mml.3pl'IRT.informationCurves( object, h=.0001, iIndex=NULL, theta=NULL, ... )## S3 method for class 'IRT.informationCurves'plot(x, curve_type="test", ...)Arguments
object | Object of class |
... | Further arguments to be passed |
h | Numerical differentiation parameter |
iIndex | Indices of items for which test information should be computed.The default is to use all items. |
theta | Optional vector of |
curve_type | Type of information to be plotted. It can be |
x | Object of class |
Value
List with following entries
se_curve | Standard error curves |
test_info_curve | Test information curve |
info_curves_item | Item information curves |
info_curves_categories | Item-category information curves |
theta | Used |
References
Muraki, E. (1993). Information functions of the generalized partial creditmodel.Applied Psychological Measurement, 17(4), 351-363.doi:10.1177/014662169301700403
Examples
## Not run: ############################################################################## EXAMPLE 1: Dichotomous data | data.read#############################################################################data(data.read, package="sirt")dat <- data.read# fit 2PL modelmod1 <- TAM::tam.mml.2pl( dat )summary(mod1)# compute information curves at grid seq(-5,5,length=100)imod1 <- TAM::IRT.informationCurves( mod1, theta=seq(-5,5,len=100) )str(imod1)# plot test informationplot( imod1 )# plot standard error curveplot( imod1, curve_type="se", xlim=c(-3,2) )# cutomized plotplot( imod1, curve_type="se", xlim=c(-3,2), ylim=c(0,2), lwd=2, lty=3)############################################################################## EXAMPLE 2: Mixed dichotomous and polytomous data#############################################################################data(data.timssAusTwn.scored, package="TAM")dat <- data.timssAusTwn.scored# select item response dataitems <- grep( "M0", colnames(dat), value=TRUE )resp <- dat[, items ]#*** Model 1: Partial credit modelmod1 <- TAM::tam.mml( resp )summary(mod1)# information curvesimod1 <- TAM::IRT.informationCurves( mod1, theta=seq(-3,3,len=20) )#*** Model 2: Generalized partial credit modelmod2 <- TAM::tam.mml.2pl( resp, irtmodel="GPCM")summary(mod2)imod2 <- TAM::IRT.informationCurves( mod2 )#*** Model 3: Mixed 3PL and generalized partial credit modelpsych::describe(resp)maxK <- apply( resp, 2, max, na.rm=TRUE )I <- ncol(resp)# specify guessing parameters, including a prior distributionest.guess <- 1:Iest.guess[ maxK > 1 ] <- 0guess <- .2*(est.guess >0)guess.prior <- matrix( 0, nrow=I, ncol=2 )guess.prior[ est.guess > 0, 1] <- 5guess.prior[ est.guess > 0, 2] <- 17# fit modelmod3 <- TAM::tam.mml.3pl( resp, gammaslope.des="2PL", est.guess=est.guess, guess=guess, guess.prior=guess.prior, control=list( maxiter=100, Msteps=10, fac.oldxsi=0.1, nodes=seq(-8,8,len=41) ), est.variance=FALSE )summary(mod3)# information curvesimod3 <- TAM::IRT.informationCurves( mod3 )imod3#*** estimate model in mirt packagelibrary(mirt)itemtype <- rep("gpcm", I)itemtype[ maxK==1] <- "3PL"mod3b <- mirt::mirt(resp, 1, itemtype=itemtype, verbose=TRUE )print(mod3b)## End(Not run)Extracting Item Response Functions
Description
Extracts item response functions for modelsfitted inTAM. SeeCDM::IRT.irfprobfor more details.
Usage
## S3 method for class 'tam'IRT.irfprob(object, ...)## S3 method for class 'tam.mml'IRT.irfprob(object, ...)## S3 method for class 'tam.mml.3pl'IRT.irfprob(object, ...)## S3 method for class 'tamaan'IRT.irfprob(object, ...)## S3 method for class 'tam.np'IRT.irfprob(object, ...)Arguments
object | Object of class |
... | Further arguments to be passed |
Value
SeeCDM::IRT.irfprob.
Examples
############################################################################## EXAMPLE 1: Dichotomous data data.sim.rasch - item response functions#############################################################################data(data.sim.rasch)# 1PL estimationmod1 <- TAM::tam.mml(resp=data.sim.rasch)IRT.irfprob(mod1)RMSD Item Fit Statistics forTAM Objects
Description
Computes the RMSD item fit statistic (formerly labeled as RMSEA;Yamamoto, Khorramdel, & von Davier, 2013) for fitted objects in theTAM package, seeCDM::IRT.itemfit andCDM::IRT.RMSD.
Usage
## S3 method for class 'tam.mml'IRT.itemfit(object, method="RMSD", ...)## S3 method for class 'tam.mml.2pl'IRT.itemfit(object, method="RMSD", ...)## S3 method for class 'tam.mml.mfr'IRT.itemfit(object, method="RMSD", ...)## S3 method for class 'tam.mml.3pl'IRT.itemfit(object, method="RMSD", ...)Arguments
object | Object of class |
method | Requested method for item fit calculation. Currently,only the RMSD fit statistic (formerly labeled as the RMSEA statistic,see |
... | Further arguments to be passed. |
References
Yamamoto, K., Khorramdel, L., & von Davier, M. (2013). Scaling PIAAC cognitive data.In OECD (Eds.).Technical Report of the Survey of Adults Skills (PIAAC) (Ch. 17).Paris: OECD.
See Also
CDM::IRT.itemfit,CDM::IRT.RMSD
Examples
## Not run: ############################################################################## EXAMPLE 1: RMSD item fit statistic data.read#############################################################################library(sirt)data(data.read,package="sirt")dat <- data.read#*** fit 1PL modelmod1 <- TAM::tam.mml( dat )summary(mod1)#*** fit 2PL modelmod2 <- TAM::tam.mml.2pl( dat )summary(mod2)#*** assess RMSEA item fitfmod1 <- IRT.itemfit(mod1)fmod2 <- IRT.itemfit(mod2)# summary of fit statisticssummary( fmod1 )summary( fmod2 )############################################################################## EXAMPLE 2: Simulated 2PL data and fit of 1PL model#############################################################################set.seed(987)N <- 1000 # 1000 personsI <- 10 # 10 items# define item difficulties and item slopesb <- seq(-2,2,len=I)a <- rep(1,I)a[c(3,8)] <- c( 1.7, .4 )# simulate 2PL datadat <- sirt::sim.raschtype( theta=rnorm(N), b=b, fixed.a=a)# fit 1PL modelmod <- TAM::tam.mml( dat )# RMSEA item fitfmod <- IRT.itemfit(mod)round( fmod, 3 )## End(Not run)Extracting Individual Likelihood and Individual Posterior
Description
Extracts individual likelihood and posterior for modelsfitted inTAM. SeeCDM::IRT.likelihoodfor more details.
Usage
## S3 method for class 'tam'IRT.likelihood(object, ...)## S3 method for class 'tam'IRT.posterior(object, ...)## S3 method for class 'tam.mml'IRT.likelihood(object, ...)## S3 method for class 'tam.mml'IRT.posterior(object, ...)## S3 method for class 'tam.mml.3pl'IRT.likelihood(object, ...)## S3 method for class 'tam.mml.3pl'IRT.posterior(object, ...)## S3 method for class 'tamaan'IRT.likelihood(object, ...)## S3 method for class 'tamaan'IRT.posterior(object, ...)## S3 method for class 'tam.latreg'IRT.likelihood(object, ...)## S3 method for class 'tam.latreg'IRT.posterior(object, ...)## S3 method for class 'tam.np'IRT.likelihood(object, ...)## S3 method for class 'tam.np'IRT.posterior(object, ...)Arguments
object | Object of class |
... | Further arguments to be passed |
Value
Examples
############################################################################## EXAMPLE 1: Dichotomous data data.sim.rasch - extracting likelihood/posterior#############################################################################data(data.sim.rasch)# 1PL estimationmod1 <- TAM::tam.mml(resp=data.sim.rasch)lmod1 <- IRT.likelihood(mod1)str(lmod1)pmod1 <- IRT.posterior(mod1)str(pmod1)Linear Approximation of a Confirmatory Factor Analysis
Description
This function approximates a fitted item response model by a linearconfirmatory factor analysis. I.e., given item response functions, theexpectationE(X_i | \theta_1, \ldots, \theta_D) islinearly approximated bya_{i1} \theta _1 + \ldots + a_{iD} \theta_D.See Vermunt and Magidson (2005) for details.
Usage
IRT.linearCFA( object, group=1)## S3 method for class 'IRT.linearCFA'summary(object, ...)Arguments
object | Fitted item response model for which the |
group | Group identifier which defines the selected group. |
... | Further arguments to be passed. |
Value
A list with following entries
loadings | Data frame with factor loadings. |
stand.loadings | Data frame with standardized factor loadings. |
M.trait | Mean of factors |
SD.trait | Standard deviations of factors |
References
Vermunt, J. K., & Magidson, J. (2005). Factor Analysis with categoricalindicators: A comparison between traditional and latent class approaches.In A. Van der Ark, M.A. Croon & K. Sijtsma (Eds.),New Developments in Categorical Data Analysis for the Social andBehavioral Sciences (pp. 41-62). Mahwah: Erlbaum
See Also
Seetam.fa for confirmatory factor analysis inTAM.
Examples
## Not run: library(lavaan)############################################################################## EXAMPLE 1: Two-dimensional confirmatory factor analysis data.Students#############################################################################data(data.Students, package="CDM")# select variablesvars <- scan(nlines=1, what="character") sc1 sc2 sc3 sc4 mj1 mj2 mj3 mj4dat <- data.Students[, vars]# define Q-matrixQ <- matrix( 0, nrow=8, ncol=2 )Q[1:4,1] <- Q[5:8,2] <- 1#*** Model 1: Two-dimensional 2PL modelmod1 <- TAM::tam.mml.2pl( dat, Q=Q, control=list( nodes=seq(-4,4,len=12) ) )summary(mod1)# linear approximation CFAcfa1 <- TAM::IRT.linearCFA(mod1)summary(cfa1)# linear CFA in lavaan packagelavmodel <- " sc=~ sc1+sc2+sc3+sc4 mj=~ mj1+mj2+mj3+mj4 sc1 ~ 1 sc ~~ mj "mod1b <- lavaan::sem( lavmodel, data=dat, missing="fiml", std.lv=TRUE)summary(mod1b, standardized=TRUE, fit.measures=TRUE )############################################################################## EXAMPLE 2: Unidimensional confirmatory factor analysis data.Students#############################################################################data(data.Students, package="CDM")# select variablesvars <- scan(nlines=1, what="character") sc1 sc2 sc3 sc4dat <- data.Students[, vars]#*** Model 1: 2PL modelmod1 <- TAM::tam.mml.2pl( dat )summary(mod1)# linear approximation CFAcfa1 <- TAM::IRT.linearCFA(mod1)summary(cfa1)# linear CFAlavmodel <- " sc=~ sc1+sc2+sc3+sc4 "mod1b <- lavaan::sem( lavmodel, data=dat, missing="fiml", std.lv=TRUE)summary(mod1b, standardized=TRUE, fit.measures=TRUE )## End(Not run)Residuals in an IRT Model
Description
Defines an S3 method for the computation of observed residual values.The computation of residuals is based on weighted likelihood estimates asperson parameters, seetam.wle.IRT.residuals can only be applied for unidimensional IRT models.The methodsIRT.residuals andresiduals are equivalent.
Usage
IRT.residuals(object, ...)## S3 method for class 'tam.mml'IRT.residuals(object, ...)## S3 method for class 'tam.mml'residuals(object, ...)## S3 method for class 'tam.mml.2pl'IRT.residuals(object, ...)## S3 method for class 'tam.mml.2pl'residuals(object, ...)## S3 method for class 'tam.mml.mfr'IRT.residuals(object, ...)## S3 method for class 'tam.mml.mfr'residuals(object, ...)## S3 method for class 'tam.jml'IRT.residuals(object, ...)## S3 method for class 'tam.jml'residuals(object, ...)Arguments
object | Object of class |
... | Further arguments to be passed |
Value
List with following entries
residuals | Residuals |
stand_residuals | Standardized residuals |
X_exp | Expected value of the item response |
X_var | Variance of the item response |
theta | Used person parameter estimate |
probs | Expected item response probabilities |
Note
Residuals can be used to inspect local dependencies in the itemresponse data, for example using principle component analysis orfactor analysis (see Example 1).
See Also
See also theeRm::residuals (eRm) function or themirt:residuals-method in themirt package.
See alsopredict.tam.mml.
Examples
## Not run: ############################################################################## EXAMPLE 1: Residuals data.read#############################################################################library(sirt)data(data.read, package="sirt")dat <- data.read# for Rasch modelmod <- TAM::tam.mml( dat )# extract residualsres <- TAM::IRT.residuals( mod )str(res)## End(Not run)Simulating Item Response Models
Description
Defines an S3 method for simulation of item response models.
Usage
IRT.simulate(object, ...)## S3 method for class 'tam.mml'IRT.simulate(object, iIndex=NULL, theta=NULL, nobs=NULL, ...)## S3 method for class 'tam.mml.2pl'IRT.simulate(object, iIndex=NULL, theta=NULL, nobs=NULL, ...)## S3 method for class 'tam.mml.mfr'IRT.simulate(object, iIndex=NULL, theta=NULL, nobs=NULL, ...)## S3 method for class 'tam.mml.3pl'IRT.simulate(object, iIndex=NULL, theta=NULL, nobs=NULL, ...)Arguments
object | An object of class |
iIndex | Optional vector of item indices |
theta | Optional matrix of |
nobs | Optional numeric containing the number of observations to be simulated. |
... | Further objects to be passed |
Value
Data frame with simulated item responses
Examples
############################################################################## EXAMPLE 1: Simulating Rasch model#############################################################################data(data.sim.rasch)#** (1) estimate modelmod1 <- TAM::tam.mml(resp=data.sim.rasch )#** (2) simulate datasim.dat <- TAM::IRT.simulate(mod1)## Not run: #** (3) use a subset of items with the argument iIndexset.seed(976)iIndex <- sort(sample(ncol(data.sim.rasch), 15)) # randomly select 15 itemssim.dat <- TAM::IRT.simulate(mod1, iIndex=iIndex)mod.sim.dat <- TAM::tam.mml(sim.dat)#** (4) specify number of persons in additionsim.dat <- TAM::IRT.simulate(mod1, nobs=1500, iIndex=iIndex)# Rasch - constraint="items" ----mod1 <- TAM::tam.mml(resp=data.sim.rasch, constraint="items", control=list( xsi.start0=1, fac.oldxsi=.5) )# provide abilitiestheta0 <- matrix( rnorm(1500, mean=0.5, sd=sqrt(mod1$variance)), ncol=1 )# simulate datadata <- TAM::IRT.simulate(mod1, theta=theta0 )# estimate model based on simulated dataxsi.fixed <- cbind(1:nrow(mod1$item), mod1$item$xsi.item)mod2 <- TAM::tam.mml(data, xsi.fixed=xsi.fixed )summary(mod2)############################################################################## EXAMPLE 2: Simulating 2PL model#############################################################################data(data.sim.rasch)# estimate 2PLmod2 <- TAM::tam.mml.2pl(resp=data.sim.rasch, irtmodel="2PL")# simulate 2PLsim.dat <- TAM::IRT.simulate(mod2)mod.sim.dat <- TAM::tam.mml.2pl(resp=sim.dat, irtmodel="2PL")############################################################################## EXAMPLE 3: Simulate multiple group model############################################################################## Multi-Group ----set.seed(6778)N <- 3000theta <- c( stats::rnorm(N/2,mean=0,sd=1.5), stats::rnorm(N/2,mean=.5,sd=1) )I <- 20p1 <- stats::plogis( outer( theta, seq( -2, 2, len=I ), "-" ) )resp <- 1 * ( p1 > matrix( stats::runif( N*I ), nrow=N, ncol=I ) )colnames(resp) <- paste("I", 1:I, sep="")group <- rep(1:2, each=N/2 )mod3 <- TAM::tam.mml(resp, group=group)# simulate datasim.dat.g1 <- TAM::IRT.simulate(mod3, theta=matrix( stats::rnorm(N/2, mean=0, sd=1.5), ncol=1) )sim.dat.g2 <- TAM::IRT.simulate(mod3, theta=matrix( stats::rnorm(N/2, mean=.5, sd=1), ncol=1) )sim.dat <- rbind( sim.dat.g1, sim.dat.g2)# estimate modelmod3s <- TAM::tam.mml( sim.dat, group=group)############################################################################## EXAMPLE 4: Multidimensional model and latent regression#############################################################################set.seed(6778)N <- 2000Y <- cbind( stats::rnorm(N), stats::rnorm(N))theta <- mvtnorm::rmvnorm(N, mean=c(0,0), sigma=matrix(c(1,.5,.5,1), 2, 2))theta[,1] <- theta[,1] + .4 * Y[,1] + .2 * Y[,2] # latent regression modeltheta[,2] <- theta[,2] + .8 * Y[,1] + .5 * Y[,2] # latent regression modelI <- 20p1 <- stats::plogis(outer(theta[, 1], seq(-2, 2, len=I), "-"))resp1 <- 1 * (p1 > matrix(stats::runif(N * I), nrow=N, ncol=I))p1 <- stats::plogis(outer(theta[, 2], seq(-2, 2, len=I ), "-" ))resp2 <- 1 * (p1 > matrix(stats::runif(N * I), nrow=N, ncol=I))resp <- cbind(resp1, resp2)colnames(resp) <- paste("I", 1 : (2 * I), sep="")# (2) define loading MatrixQ <- array(0, dim=c(2 * I, 2))Q[cbind(1:(2*I), c(rep(1, I), rep(2, I)))] <- 1Q# (3) estimate modelsmod4 <- TAM::tam.mml(resp=resp, Q=Q, Y=Y, control=list( maxiter=15))# simulate new item responsestheta <- mvtnorm::rmvnorm(N, mean=c(0,0), sigma=matrix(c(1,.5,.5,1), 2, 2))theta[,1] <- theta[,1] + .4 * Y[,1] + .2 * Y[,2] # latent regression modeltheta[,2] <- theta[,2] + .8 * Y[,1] + .5 * Y[,2] # latent regression modelsim.dat <- TAM::IRT.simulate(mod4, theta=theta)mod.sim.dat <- TAM::tam.mml(resp=sim.dat, Q=Q, Y=Y, control=list( maxiter=15))## End(Not run)Thurstonian Thresholds and Wright Map for Item Response Models
Description
The functionIRT.threshold computes Thurstonian thresholdsfor item response models. It is only based on fitted modelsfor which theIRT.irfprob class does exist.
The functionIRT.WrightMap creates a Wright map and works as a wrapper to thewrightMap function intheWrightMap package. Wright maps operateon objects of classIRT.threshold.
Usage
IRT.threshold(object, prob.lvl=.5, type="category")## S3 method for class 'IRT.threshold'print(x, ...)IRT.WrightMap(object, ...)## S3 method for class 'IRT.threshold'IRT.WrightMap(object, label.items=NULL, ...)Arguments
object | Object of fitted models for whichIRT.irfprobexists. |
prob.lvl | Requested probability level of thresholds. |
type | Type of thresholds to be calculated. The default iscategory-wise calculation. If only one threshold per item shouldbe calculated, then choose |
x | Object of class |
label.items | Vector of item labels |
... | Further arguments to be passed. |
Value
FunctionIRT.threshold:
Matrix with Thurstonian thresholds
FunctionIRT.WrightMap:
A Wright map generated by theWrightMap package.
Author(s)
TheIRT.WrightMap function is based on thewrightMap functionin theWrightMap package.
References
Ali, U. S., Chang, H.-H., & Anderson, C. J. (2015).Location indices for ordinalpolytomous items based on item response theory (ResearchReport No. RR-15-20). Princeton, NJ: Educational Testing Service.doi:10.1002/ets2.12065
See Also
See thewrightMap function intheWrightMap package.
Examples
## Not run: ############################################################################## EXAMPLE 1: Fitted unidimensional model with gdm#############################################################################data(data.Students)dat <- data.Students# select part of the datasetresp <- dat[, paste0("sc",1:4) ]resp[ paste(resp[,1])==3,1] <- 2psych::describe(resp)# Model 1: Partial credit model in gdmtheta.k <- seq( -5, 5, len=21 ) # discretized abilitymod1 <- CDM::gdm( dat=resp, irtmodel="1PL", theta.k=theta.k, skillspace="normal", centered.latent=TRUE)# compute thresholdsthresh1 <- TAM::IRT.threshold(mod1)print(thresh1)IRT.WrightMap(thresh1)############################################################################## EXAMPLE 2: Fitted mutidimensional model with gdm#############################################################################data( data.fraction2 )dat <- data.fraction2$dataQmatrix <- data.fraction2$q.matrix3# Model 1: 3-dimensional Rasch Model (normal distribution)theta.k <- seq( -4, 4, len=11 ) # discretized abilitymod1 <- CDM::gdm( dat, irtmodel="1PL", theta.k=theta.k, Qmatrix=Qmatrix, centered.latent=TRUE, maxiter=10 )summary(mod1)# compute thresholdsthresh1 <- TAM::IRT.threshold(mod1)print(thresh1)############################################################################## EXAMPLE 3: Item-wise thresholds#############################################################################data(data.timssAusTwn.scored)dat <- data.timssAusTwn.scoreddat <- dat[, grep("M03", colnames(dat) ) ]summary(dat)# fit partial credit modelmod <- TAM::tam.mml( dat )# compute thresholds with tam.threshold functiont1mod <- TAM::tam.threshold( mod )t1mod# compute thresholds with IRT.threshold functiont2mod <- TAM::IRT.threshold( mod )t2mod# compute item-wise thresholdst3mod <- TAM::IRT.threshold( mod, type="item")t3mod## End(Not run)Converts a\theta Score into a True Score\tau ( \theta)
Description
Converts a\theta score into an unweighted true score\tau ( \theta)=\sum_i \sum_h h P_i ( \theta ).In addition, a weighted true score\tau ( \theta)=\sum_i \sum_h q_{ih} P_i ( \theta )can also be computed by specifying item-category weightsq_{ih} in the matrixQ.
Usage
IRT.truescore(object, iIndex=NULL, theta=NULL, Q=NULL)Arguments
object | Object for which the |
iIndex | Optional vector with item indices |
theta | Optional vector with |
Q | Optional weighting matrix |
Value
Data frame containing\theta values and correspondingtrue scores\tau( \theta ).
See Also
See alsosirt::truescore.irtfor a conversion function for generalized partial credit models.
Examples
############################################################################## EXAMPLE 1: True score conversion for a test with polytomous items#############################################################################data(data.Students, package="CDM")dat <- data.Students[, paste0("mj",1:4) ]# fit partial credit modelmod1 <- TAM::tam.mml( dat,control=list(maxiter=20) )summary(mod1)# true score conversiontmod1 <- TAM::IRT.truescore( mod1 )round( tmod1, 4 )# true score conversion with user-defined theta gridtmod1b <- TAM::IRT.truescore( mod1, theta=seq( -8,8, len=33 ) )# plot resultsplot( tmod1$theta, tmod1$truescore, type="l", xlab=expression(theta), ylab=expression(tau( theta ) ) )points( tmod1b$theta, tmod1b$truescore, pch=16, col="brown" )## Not run: ############################################################################## EXAMPLE 2: True scores with different category weightings#############################################################################data(data.timssAusTwn.scored)dat <- data.timssAusTwn.scored# extract item response datadat <- dat[, grep("M03", colnames(dat) ) ]# select items with do have maximum score of 2 (polytomous items)ind <- which( apply( dat, 2, max, na.rm=TRUE )==2 )I <- ncol(dat)# define Q-matrix with scoring variantQ <- matrix( 1, nrow=I, ncol=1 )Q[ ind, 1 ] <- .5 # score of 0.5 for polyomous items# estimate modelmod1 <- TAM::tam.mml( dat, Q=Q, irtmodel="PCM2", control=list( nodes=seq(-10,10,len=61) ) )summary(mod1)# true score with scoring (0,1,2) which is the default of the functiontmod1 <- TAM::IRT.truescore(mod1)# true score with user specified weighting matrixQ <- mod1$B[,,1]tmod2 <- TAM::IRT.truescore(mod1, Q=Q)## End(Not run)Individual Likelihood for Confirmatory Factor Analysis
Description
This function computes the individual likelihood evaluatedat atheta grid for confirmatory factor analysisunder the normality assumption of residuals. Eitherthe item parameters (item loadingsL, iteminterceptsnu and residual covariancespsi)or a fittedcfa object from thelavaanpackage can be provided. The individual likelihoodcan be used for drawing plausible values.
Usage
IRTLikelihood.cfa(data, cfaobj=NULL, theta=NULL, L=NULL, nu=NULL, psi=NULL, snodes=NULL, snodes.adj=2, version=1)Arguments
data | Dataset with item responses |
cfaobj | Fitted |
theta | Optional matrix containing the |
L | Matrix of item loadings (if |
nu | Vector of item intercepts (if |
psi | Matrix with residual covariances(if |
snodes | Number of |
snodes.adj | Adjustment factor for quasi monte carlo nodes formore than two latent variables. |
version | Function version. |
Value
Individual likelihood evaluated attheta
See Also
Examples
## Not run: ############################################################################## EXAMPLE 1: Two-dimensional CFA data.Students#############################################################################library(lavaan)library(CDM)data(data.Students, package="CDM")dat <- data.Studentsdat2 <- dat[, c(paste0("mj",1:4), paste0("sc",1:4)) ]# lavaan model with DO operatorlavmodel <- "DO(1,4,1) mj=~ mj% sc=~ sc%DOEND mj ~~ sc mj ~~ 1*mj sc ~~ 1*sc "lavmodel <- TAM::lavaanify.IRT( lavmodel, data=dat2 )$lavaan.syntaxcat(lavmodel)mod4 <- lavaan::cfa( lavmodel, data=dat2, std.lv=TRUE )summary(mod4, standardized=TRUE, rsquare=TRUE )# extract item parametersres4 <- TAM::cfa.extract.itempars( mod4 )# create theta gridtheta0 <- seq( -6, 6, len=15)theta <- expand.grid( theta0, theta0 )L <- res4$Lnu <- res4$nupsi <- res4$psidata <- dat2# evaluate likelihood using item parameterslike2 <- TAM::IRTLikelihood.cfa( data=dat2, theta=theta, L=L, nu=nu, psi=psi )# The likelihood can also be obtained by direct evaluation# of the fitted cfa object "mod4"like4 <- TAM::IRTLikelihood.cfa( data=dat2, cfaobj=mod4 )attr( like4, "theta")# the theta grid is automatically created if theta is not# supplied as an argument## End(Not run)Computes Individual Likelihood from Classical Test Theory Estimates
Description
Computes individual likelihood from classical test theory estimatesunder a unidimensional normal distribution of measurement errors.
Usage
IRTLikelihood.ctt(y, errvar, theta=NULL)Arguments
y | Vector of observed scores |
errvar | Vector of error variances |
theta | Optional vector for |
Value
Object of classIRT.likelihood
Examples
############################################################################## EXAMPLE 1: Individual likelihood and latent regression in CTT#############################################################################set.seed(75)#--- simulate dataN <- 2000x1 <- stats::rnorm(N)x2 <- .7 * x1 + stats::runif(N)# simulate true scoretheta <- 1.2 + .6*x1 + .3 *x2 + stats::rnorm(N, sd=sqrt(.50) )var(theta)# simulate measurement error varianceserrvar <- stats::runif( N, min=.6, max=.9 )# simulate observed scoresy <- theta + stats::rnorm( N, sd=sqrt( errvar) )#--- create likelihood objectlike1 <- TAM::IRTLikelihood.ctt( y=y, errvar=errvar, theta=NULL )#--- estimate latent regressionX <- data.frame(x1,x2)mod1 <- TAM::tam.latreg( like=like1, Y=X )## Not run: #--- draw plausible valuespv1 <- TAM::tam.pv( mod1, normal.approx=TRUE )#--- create datalistdatlist1 <- TAM::tampv2datalist( pv1, pvnames="thetaPV", Y=X )#--- statistical inference on plausible values using mitools packagelibrary(mitools)datlist1a <- mitools::imputationList(datlist1)# fit linear regression and apply Rubin formulasmod2 <- with( datlist1a, stats::lm( thetaPV ~ x1 + x2 ) )summary( mitools::MIcombine(mod2) )## End(Not run)S3 Method for Standardizations and Transformations of Variables
Description
S3 method for standardizations and transformations of variables
Usage
Scale(object, ...)Arguments
object | An object |
... | Further arguments to be passed |
See Also
DefunctTAM Functions
Description
These functions have been removed or replaced in thetam.jml2package.
Usage
tam.jml2(...)Arguments
... | Arguments to be passed. |
Details
Thetam.jml2 is included as the default intam.jml.
Utility Functions inTAM
Description
Utility functions inTAM.
Usage
## RISE item fit statistic of two modelsIRT.RISE( mod_p, mod_np, use_probs=TRUE )## model-implied meanstam_model_implied_means(mod)## information about used package versiontam_packageinfo(pack)## call statement in a string formattam_print_call(CALL)## information about R sessiontam_rsessinfo()## grep list of arguments for a specific variabletam_args_CALL_search(args_CALL, variable, default_value)## requireNamespace with message of needed installationrequire_namespace_msg(pkg)## add leading zeroesadd.lead(x, width=max(nchar(x)))## round some columns in a data frametam_round_data_frame(obji, from=1, to=ncol(obji), digits=3, rownames_null=FALSE)## round some columns in a data frame and print this data frametam_round_data_frame_print(obji, from=1, to=ncol(obji), digits=3, rownames_null=FALSE)## copy of CDM::osinktam_osink(file, suffix=".Rout")## copy of CDM::csinktam_csink(file)## base::matrix function with argument value byrow=TRUEtam_matrix2(x, nrow=NULL, ncol=NULL)## more efficient base::outer functions for operations "*", "+" and "-"tam_outer(x, y, op="*")## row normalization of a matrixtam_normalize_matrix_rows(x)## row normalization of a vectortam_normalize_vector(x)## aggregate function for mean and sum based on base::rowsumtam_aggregate(x, group, mean=FALSE, na.rm=TRUE)## column index when a value in a matrix is exceeded (used in TAM::tam.pv)tam_interval_index(matr, rn)## cumulative sum of row entries in a matrixtam_rowCumsums(matr)## extension of mvtnorm::dmvnorm to matrix entries of meantam_dmvnorm(x, mean, sigma, log=FALSE )## Bayesian bootstrap in TAM (used in tam.pv.mcmc)tam_bayesian_bootstrap(N, sample_integers=FALSE, do_boot=TRUE)## weighted covariance matrixtam_cov_wt(x, wt=NULL, method="ML")## weighted correlation matrixtam_cor_wt(x, wt=NULL, method="ML")## generalized inversetam_ginv(x, eps=.05)## generalized inverse with scaled matrix using MASS::ginvtam_ginv_scaled(x, use_MASS=TRUE)## remove items or persons with complete missing entriestam_remove_missings( dat, items, elim_items=TRUE, elim_persons=TRUE )## compute AXsi given A and xsitam_AXsi_compute(A, xsi)## fit xsi given A and AXsitam_AXsi_fit(A, AXsi)## maximum absolute difference between objectstam_max_abs( list1, list2, label )tam_max_abs_list( list1, list2)## trimming increments in iterationstam_trim_increment(increment, max.increment, trim_increment="cut", trim_incr_factor=2, eps=1E-10, avoid_na=FALSE)## numerical differentiation by central differencetam_difference_quotient(d0, d0p, d0m, h)## assign elements of a list in an environmenttam_assign_list_elements(x, envir)Arguments
mod_p | Fitted model |
mod_np | Fitted model |
mod | Fitted model |
use_probs | Logical |
pack | AnR package |
CALL | AnR call |
args_CALL | Arguments obtained from |
variable | Name of a variable |
default_value | Default value of a variable |
pkg | String |
x | Vector or matrix or list |
width | Number of zeroes before decimal |
obji | Data frame or vector |
from | Integer |
to | Integer |
digits | Integer |
rownames_null | Logical |
file | File name |
suffix | Suffix for file name of summary output |
nrow | Number of rows |
ncol | Number of columns |
y | Vector |
op | An operation |
group | Vector of grouping identifiers |
mean | Logical indicating whether mean should be calculated or the sum orvector or matrix |
na.rm | Logical indicating whether missing values should be removed |
matr | Matrix |
sigma | Matrix |
log | Logical |
N | Integer |
sample_integers | Logical indicating whether weights for complete casesshould be sampled in bootstrap |
do_boot | Logical |
wt | Optional vector containing weights |
method | Method, see |
rn | Vector |
dat | Data frame |
items | Vector |
elim_items | Logical |
elim_persons | Logical |
A | Array |
xsi | Vector |
AXsi | Matrix |
increment | Vector |
max.increment | Numeric |
trim_increment | One of the methods |
trim_incr_factor | Factor of trimming in method |
eps | Small number preventing from division by zero |
use_MASS | Logical indicating whetherMASS package should be used. |
avoid_na | Logical indicating whether missing values should be set to zero. |
d0 | Vector |
d0p | Vector |
d0m | Vector |
h | Vector |
envir | Environment variable |
list1 | List |
list2 | List |
label | Element of a list |
Reliability Estimation inTAM
Description
Functions for computing reliability estimates.
Usage
WLErel(theta, error, w=rep(1, length(theta)), select=NULL)EAPrel(theta, error, w=rep(1, length(theta)), select=NULL)Arguments
theta | Vector with theta estimates |
error | Vector with standard errors of theta estimates |
w | Optional vector of person weights |
select | Optional vector for selecting cases |
Details
The reliability formulas follow Adams (2005). Letv denotethe variance oftheta estimates and lets denotethe average of the squarederror. Then, the WLE reliability isdefined as1-s/v=(v-s)/v while the EAP reliability is defined as1 - s/(s+v)=v/(s+v).
Value
Numeric value
References
Adams, R. J. (2005). Reliability as a measurement design effect.Studies in Educational Evaluation, 31(2), 162-172.doi:10.1016/j.stueduc.2005.05.008
Examples
############################################################################## EXAMPLE 1: Toy example for reliability functions#############################################################################set.seed(9897)N <- 100# simulate theta and error SDsx <- stats::rnorm(N,sd=2)error <- stats::runif(N, .7, 1.3)# compute WLE reliabilityWLErel(x,error)# compute EAP reliailityEAPrel(x,error)Likelihood Ratio Test for Model Comparisons and Log-Likelihood Value
Description
Theanova function compares two models estimated of classtam,tam.mml ortam.mml.3pl using a likelihood ratio test.ThelogLik function extracts the value of the log-Likelihood.
The function can be applied for values oftam.mml,tam.mml.2pl,tam.mml.mfr,tam.fa,tam.mml.3pl,tam.latreg ortamaan.
Usage
## S3 method for class 'tam'anova(object, ...)## S3 method for class 'tam'logLik(object, ...)## S3 method for class 'tam.mml'anova(object, ...)## S3 method for class 'tam.mml'logLik(object, ...)## S3 method for class 'tam.mml.3pl'anova(object, ...)## S3 method for class 'tam.mml.3pl'logLik(object, ...)## S3 method for class 'tamaan'anova(object, ...)## S3 method for class 'tamaan'logLik(object, ...)## S3 method for class 'tam.latreg'anova(object, ...)## S3 method for class 'tam.latreg'logLik(object, ...)## S3 method for class 'tam.np'anova(object, ...)## S3 method for class 'tam.np'logLik(object, ...)Arguments
object | Object of class |
... | Further arguments to be passed |
Value
A data frame containing the likelihood ratio test statistic andinformation criteria.
Examples
############################################################################## EXAMPLE 1: Dichotomous data sim.rasch - 1PL vs. 2PL model#############################################################################data(data.sim.rasch)# 1PL estimationmod1 <- TAM::tam.mml(resp=data.sim.rasch)logLik(mod1)# 2PL estimationmod2 <- TAM::tam.mml.2pl(resp=data.sim.rasch, irtmodel="2PL")logLik(mod2)# Model comparisonanova( mod1, mod2 ) ## Model loglike Deviance Npars AIC BIC Chisq df p ## 1 mod1 -42077.88 84155.77 41 84278.77 84467.40 54.05078 39 0.05508 ## 2 mod2 -42050.86 84101.72 80 84341.72 84709.79 NA NA NA## Not run: ############################################################################## EXAMPLE 2: Dataset reading (sirt package): 1- vs. 2-dimensional model#############################################################################data(data.read, package="sirt")# 1-dimensional modelmod1 <- TAM::tam.mml.2pl(resp=data.read )# 2-dimensional modelmod2 <- TAM::tam.fa(resp=data.read, irtmodel="efa", nfactors=2, control=list(maxiter=150) )# Model comparisonanova( mod1, mod2 ) ## Model loglike Deviance Npars AIC BIC Chisq df p ## 1 mod1 -1954.888 3909.777 24 3957.777 4048.809 76.66491 11 0 ## 2 mod2 -1916.556 3833.112 35 3903.112 4035.867 NA NA NA## End(Not run)Extracting Item Parameters from a Fittedcfa Object inlavaan
Description
This function extract item parameters from a fittedlavaan::cfa object inlavaan. Itextract item loadings, item intercepts and the meanand covariance matrix of latent variables in aconfirmatory factor analysis model.
Usage
cfa.extract.itempars(object)Arguments
object | Fitted |
Value
List with following entries
L | Matrix of item loadings |
nu | Vector of item intercepts |
psi | Residual covariance matrix |
Sigma | Covariance matrix of latent variables |
nu | Vector of means of latent variables |
... | Further values |
See Also
SeeIRTLikelihood.cfa for extracting theindividual likelihood from fitted confirmatoryfactor analyses.
Examples
############################################################################## EXAMPLE 1: CFA data.Students#############################################################################library(lavaan)library(CDM)data(data.Students, package="CDM")dat <- data.Studentsdat1 <- dat[, paste0( "mj", 1:4 ) ]#*** Model 1: Unidimensional model scale mjlavmodel <- " mj=~ mj1 + mj2 + mj3 + mj4 mj ~~ mj "mod1 <- lavaan::cfa( lavmodel, data=dat1, std.lv=TRUE )summary(mod1, standardized=TRUE, rsquare=TRUE )# extract parametersres1 <- TAM::cfa.extract.itempars( mod1 )## Not run: #*** Model 2: Scale mj - explicit modelling of item interceptslavmodel <- " mj=~ mj1 + mj2 + mj3 + mj4 mj ~~ mj mj1 ~ 1 "mod2 <- lavaan::cfa( lavmodel, data=dat1, std.lv=TRUE )summary(mod2, standardized=TRUE, rsquare=TRUE )res2 <- TAM::cfa.extract.itempars( mod2 )#*** Model 3: Tau-parallel measurements scale mjlavmodel <- " mj=~ a*mj1 + a*mj2 + a*mj3 + a*mj4 mj ~~ 1*mj mj1 ~ b*1 mj2 ~ b*1 mj3 ~ b*1 mj4 ~ b*1 "mod3 <- lavaan::cfa( lavmodel, data=dat1, std.lv=TRUE )summary(mod3, standardized=TRUE, rsquare=TRUE )res3 <- TAM::cfa.extract.itempars( mod3 )#*** Model 4: Two-dimensional CFA with scales mj and scdat2 <- dat[, c(paste0("mj",1:4), paste0("sc",1:4)) ]# lavaan model with shortage "__" operatorlavmodel <- " mj=~ mj1__mj4 sc=~ sc1__sc4 mj ~~ sc mj ~~ 1*mj sc ~~ 1*sc "lavmodel <- TAM::lavaanify.IRT( lavmodel, data=dat2 )$lavaan.syntaxcat(lavmodel)mod4 <- lavaan::cfa( lavmodel, data=dat2, std.lv=TRUE )summary(mod4, standardized=TRUE, rsquare=TRUE )res4 <- TAM::cfa.extract.itempars( mod4 )## End(Not run)More Datasets and Examples (Similar to ConQuest Examples)
Description
Datasets and examples similar to the ones in the ConQuest manual(Wu, Adams, Wilson, & Haldane, 2007).
Usage
data(data.cqc01)data(data.cqc02)data(data.cqc03)data(data.cqc04)data(data.cqc05)Format
data.cqc01contains 512 persons on12 dichotomous items of following format'data.frame': 512 obs. of 12 variables:$ BSMMA01: int 1 1 0 1 1 1 1 1 0 0 ...$ BSMMA02: int 1 0 1 1 0 1 1 1 0 0 ...$ BSMMA03: int 1 1 0 1 1 1 1 1 1 0 ...[...]$ BSMSA12: int 0 0 0 0 1 0 1 1 0 0 ...data.cqc02contains 431 persons on 8 polytomousvariables of following format'data.frame': 431 obs. of 8 variables:$ It1: int 1 1 2 0 2 1 2 2 2 1 ...$ It2: int 3 0 1 2 2 3 2 2 1 1 ...$ It3: int 1 1 1 0 1 1 0 0 1 0 ...[...]$ It8: int 3 1 0 0 3 1 3 0 3 0 ...data.cqc03contains 11200 observations for5600 persons, 16 raters and 2 items (crit1andcrit2)'data.frame': 11200 obs. of 4 variables:$ pid : num 10001 10001 10002 10002 10003 ...$ rater: chr "R11" "R12" "R13" "R14" ...$ crit1: int 2 2 2 1 3 2 2 1 1 1 ...$ crit2: int 3 3 2 1 2 2 2 2 2 1 ...data.cqc04contains 1452 observations for 363 persons,4 raters, 4 topics and 5 items (spe,coh,str,gra,con)'data.frame': 1452 obs. of 8 variables:$ pid : num 10010 10010 10010 10010 10016 ...$ rater: chr "BE" "CO" "BE" "CO" ...$ topic: chr "Spor" "Spor" "Spor" "Spor" ...$ spe : int 2 0 2 1 3 3 3 3 3 2 ...$ coh : int 1 1 2 0 3 3 3 3 3 3 ...$ str : int 0 1 3 0 3 2 3 2 3 0 ...$ gra : int 0 0 2 0 3 3 3 3 2 1 ...$ con : int 0 0 0 0 3 1 2 2 3 0 ...data.cqc05contains 1500 persons,3 covariates and 157 items.'data.frame': 1500 obs. of 160 variables:$ gender: int 1 0 1 0 0 0 0 1 0 1 ...$ level : int 0 1 1 0 0 0 1 0 1 1 ...$ gbyl : int 0 0 1 0 0 0 0 0 0 1 ...$ A001 : num 0 0 0 1 0 1 1 1 0 1 ...$ A002 : num 1 1 0 1 1 1 1 1 1 0 ...$ A003 : num 0 0 0 0 1 1 1 0 0 1 ...[...]
References
Wu, M. L., Adams, R. J., Wilson, M. R. & Haldane, S. (2007).ACER ConQuest Version 2.0. Mulgrave.https://shop.acer.edu.au/acer-shop/group/CON3.
See Also
See thesirt::R2conquest functionfor running ConQuest software from withinR.
See theWrightMap package for functionsconnected to reading ConQuest files and creating Wright maps.ConQuest output files can be read intoR with the help oftheWrightMap::CQmodel function.See also theIRT.WrightMap function inTAM.
See also theeat package (https://r-forge.r-project.org/projects/eat/)for elaborate functionality for communication of ConQuest withR.
Examples
## Not run: library(sirt)library(WrightMap)# In the following, ConQuest will also be used for estimation.path.conquest <- "C:/Conquest" # path of the ConQuest console.exesetwd( "p:/my_files/ConQuest_analyses" ) # working directory############################################################################## EXAMPLE 01: Rasch model data.cqc01#############################################################################data(data.cqc01)dat <- data.cqc01#********************************************#*** Model 01: Estimate Rasch modelmod01 <- TAM::tam.mml(dat)summary(mod01)#------- ConQuest# estimate modelcmod01 <- sirt::R2conquest( dat, name="mod01", path.conquest=path.conquest)summary(cmod01) # summary output# read shw file with some termsshw01a <- sirt::read.show( "mod01.shw" )cmod01$shw.itemparameter# read person item mapspi01a <- sirt::read.pimap( "mod01.shw" )cmod01$shw.pimap# read plausible values (npv=10 plausible values)pv01a <- sirt::read.pv(pvfile="mod01.pv", npv=10)cmod01$person# read ConQuest modelres01a <- WrightMap::CQmodel(p.est="mod01.wle", show="mod01.shw", p.type="WLE" )print(res01a)# plot item fitWrightMap::fitgraph(res01a)# Wright mapplot(res01a, label.items.srt=90 )############################################################################## EXAMPLE 02: Partial credit model and rating scale model data.cqc02#############################################################################data(data.cqc02)dat <- data.cqc02#********************************************# Model 02a: Partial credit model in ConQuest parametrization 'item+item*step'mod02a <- TAM::tam.mml( dat, irtmodel="PCM2" )summary(mod02a, file="mod02a")fit02a <- TAM::tam.fit(mod02a)summary(fit02a)#--- ConQuest# estimate modelmaxK <- max( dat, na.rm=TRUE )cmod02a <- sirt::R2conquest( dat, itemcodes=0:maxK, model="item+item*step", name="mod02a", path.conquest=path.conquest)summary(cmod02a) # summary output# read ConQuest modelres02a <- WrightMap::CQmodel(p.est="mod02a.wle", show="mod02a.shw", p.type="WLE" )print(res02a)# Wright mapplot(res02a, label.items.srt=90 )plot(res02a, item.table="item")#********************************************# Model 02b: Rating scale modelmod02b <- TAM::tam.mml( dat, irtmodel="RSM" )summary( mod02b )############################################################################## EXAMPLE 03: Faceted Rasch model for rating data data.cqc03#############################################################################data(data.cqc03)# select itemsresp <- data.cqc03[, c("crit1","crit2") ]#********************************************# Model 03a: 'item+step+rater'mod03a <- TAM::tam.mml.mfr( resp, facets=data.cqc03[,"rater",drop=FALSE], formulaA=~ item+step+rater, pid=data.cqc03$pid )summary( mod03a )#--- ConQuestX <- data.cqc03[,"rater",drop=FALSE]X$rater <- as.numeric(substring( X$rater, 2 )) # convert 'rater' in numeric formatmaxK <- max( resp, na.rm=TRUE)cmod03a <- sirt::R2conquest( resp, X=X, regression="", model="item+step+rater", name="mod03a", path.conquest=path.conquest, set.constraints="cases" )summary(cmod03a) # summary output# read ConQuest modelres03a <- WrightMap::CQmodel(p.est="mod03a.wle", show="mod03a.shw", p.type="WLE" )print(res03a)# Wright mapplot(res03a)#********************************************# Model 03b: 'item:step+rater'mod03b <- TAM::tam.mml.mfr( resp, facets=data.cqc03[,"rater",drop=FALSE], formulaA=~ item + item:step+rater, pid=data.cqc03$pid )summary( mod03b )#********************************************# Model 03c: 'step+rater' for first item 'crit1'# Restructuring the data is necessary.# Define raters as items in the new dataset 'dat1'.persons <- unique( data.cqc03$pid )raters <- unique( data.cqc03$rater )dat1 <- matrix( NA, nrow=length(persons), ncol=length(raters) + 1 )dat1 <- as.data.frame(dat1)colnames(dat1) <- c("pid", raters )dat1$pid <- personsfor (rr in raters){ dat1.rr <- data.cqc03[ data.cqc03$rater==rr, ] dat1[ match(dat1.rr$pid, persons),rr] <- dat1.rr$crit1 } ## > head(dat1) ## pid R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 R22 R23 R24 R25 R26 ## 1 10001 2 2 NA NA NA NA NA NA NA NA NA NA NA NA NA NA ## 2 10002 NA NA 2 1 NA NA NA NA NA NA NA NA NA NA NA NA ## 3 10003 NA NA 3 2 NA NA NA NA NA NA NA NA NA NA NA NA ## 4 10004 NA NA 2 1 NA NA NA NA NA NA NA NA NA NA NA NA ## 5 10005 NA NA 1 1 NA NA NA NA NA NA NA NA NA NA NA NA ## 6 10006 NA NA 1 1 NA NA NA NA NA NA NA NA NA NA NA NA# estimate model 03cmod03c <- TAM::tam.mml( dat1[,-1], pid=dat1$pid )summary( mod03c )############################################################################## EXAMPLE 04: Faceted Rasch model for rating data data.cqc04#############################################################################data(data.cqc04)resp <- data.cqc04[,4:8]facets <- data.cqc04[, c("rater", "topic") ]#********************************************# Model 04a: 'item*step+rater+topic'formulaA <- ~ item*step + rater + topicmod04a <- TAM::tam.mml.mfr( resp, facets=facets, formulaA=formulaA, pid=data.cqc04$pid )summary( mod04a )#********************************************# Model 04b: 'item*step+rater+topic+item*rater+item*topic'formulaA <- ~ item*step + rater + topic + item*rater + item*topicmod04b <- TAM::tam.mml.mfr( resp, facets=facets, formulaA=formulaA, pid=data.cqc04$pid )summary( mod04b )#********************************************# Model 04c: 'item*step' with fixing rater and topic parameters to zeroformulaA <- ~ item*step + rater + topicmod04c0 <- TAM::tam.mml.mfr( resp, facets=facets, formulaA=formulaA, pid=data.cqc04$pid, control=list(maxiter=4) )summary( mod04c0 )# fix rater and topic parameter to zeroxsi.est <- mod04c0$xsixsi.fixed <- cbind( seq(1,nrow(xsi.est)), xsi.est$xsi )rownames(xsi.fixed) <- rownames(xsi.est)xsi.fixed <- xsi.fixed[ c(8:13),]xsi.fixed[,2] <- 0 ## > xsi.fixed ## [,1] [,2] ## raterAM 8 0 ## raterBE 9 0 ## raterCO 10 0 ## topicFami 11 0 ## topicScho 12 0 ## topicSpor 13 0mod04c1 <- TAM::tam.mml.mfr( resp, facets=facets, formulaA=formulaA, pid=data.cqc04$pid, xsi.fixed=xsi.fixed )summary( mod04c1 )############################################################################## EXAMPLE 05: Partial credit model with latent regression and# plausible value imputation#############################################################################data(data.cqc05)resp <- data.cqc05[, -c(1:3) ] # select item responses#********************************************# Model 05a: Partial credit modelmod05a <-tam.mml(resp=resp, irtmodel="PCM2" )#********************************************# Model 05b: Partial credit model with latent regressorsmod05b <-tam.mml(resp=resp, irtmodel="PCM2", Y=data.cqc05[,1:3] )# Plausible value imputationpvmod05b <- TAM::tam.pv( mod05b )## End(Not run)Some C-Test Datasets
Description
Some C-Test datasets.
Usage
data(data.ctest1)data(data.ctest2)Format
The dataset
data.ctest1contains item responses of C-testsat two time points. The format is'data.frame': 1675 obs. of 42 variables:$ idstud : num 100101 100102 100103 100104 100105 ...$ idclass: num 1001 1001 1001 1001 1001 ...$ A01T1 : int 0 1 0 1 1 NA 1 0 1 1 ...$ A02T1 : int 0 1 0 1 0 NA 0 1 1 0 ...$ A03T1 : int 0 1 1 1 0 NA 0 1 1 1 ...$ A04T1 : int 1 0 0 0 0 NA 0 0 0 0 ...$ A05T1 : int 0 0 0 1 1 NA 0 0 1 1 ...$ B01T1 : int 1 1 0 1 1 NA 0 0 1 0 ...$ B02T1 : int 0 0 0 1 0 NA 0 0 1 1 ...[...]$ C02T2 : int 0 1 1 1 1 0 1 0 1 1 ...$ C03T2 : int 1 1 0 1 0 0 0 0 1 0 ...$ C04T2 : int 0 0 1 0 0 0 0 1 0 0 ...$ C05T2 : int 0 1 0 0 1 0 1 0 0 1 ...$ D01T2 : int 0 1 1 1 0 1 1 1 1 1 ...$ D02T2 : int 0 1 1 1 1 1 0 1 1 1 ...$ D03T2 : int 1 0 0 0 1 0 0 0 0 0 ...$ D04T2 : int 1 0 1 1 1 0 1 0 1 1 ...$ D05T2 : int 1 0 1 1 1 1 1 1 1 1 ...The dataset
data.ctest2contains two datasets($data1containing item responses,$data2containing sum scores of each C-test) anda data frame$ITEMwith item informations.List of 3$ data1:'data.frame': 933 obs. of 102 variables:..$ idstud: num [1:933] 10001 10002 10003 10004 10005 .....$ female: num [1:933] 1 1 0 0 0 0 1 1 0 1 .....$ A101 : int [1:933] NA NA NA NA NA NA NA NA NA NA .....$ A102 : int [1:933] NA NA NA NA NA NA NA NA NA NA .....$ A103 : int [1:933] NA NA NA NA NA NA NA NA NA NA .....$ A104 : int [1:933] NA NA NA NA NA NA NA NA NA NA .....$ A105 : int [1:933] NA NA NA NA NA NA NA NA NA NA .....$ A106 : int [1:933] NA NA NA NA NA NA NA NA NA NA .....$ E115 : int [1:933] NA NA NA NA NA NA NA NA NA NA .....$ E116 : int [1:933] NA NA NA NA NA NA NA NA NA NA .....$ E117 : int [1:933] NA NA NA NA NA NA NA NA NA NA ..... [list output truncated]$ data2:'data.frame': 933 obs. of 7 variables:..$ idstud: num [1:933] 10001 10002 10003 10004 10005 .....$ female: num [1:933] 1 1 0 0 0 0 1 1 0 1 .....$ A : num [1:933] NA NA NA NA NA NA NA NA NA NA .....$ B : num [1:933] 16 14 15 13 17 11 11 18 19 13 .....$ C : num [1:933] 17 15 17 14 17 13 9 15 17 12 .....$ D : num [1:933] NA NA NA NA NA NA NA NA NA NA .....$ E : num [1:933] NA NA NA NA NA NA NA NA NA NA ...$ ITEM :'data.frame': 100 obs. of 3 variables:..$ item : chr [1:100] "A101" "A102" "A103" "A104" .....$ ctest : chr [1:100] "A" "A" "A" "A" .....$ testlet: int [1:100] 1 1 2 2 2 3 3 3 NA 4 ...
Datasetsdata.ex inTAM Package
Description
Datasets included in theTAM package
Usage
data(data.ex08)data(data.ex10)data(data.ex11)data(data.ex12)data(data.ex14)data(data.ex15)data(data.exJ03)Format
Data
data.ex08for Example 8 intam.mmlhas the following format:List of 2$ facets:'data.frame': 1000 obs. of 1 variable:..$ female: int [1:1000] 1 1 1 1 1 1 1 1 1 1 ...$ resp : num [1:1000, 1:10] 1 1 1 0 1 0 1 1 0 1 .....- attr(*, "dimnames")=List of 2.. ..$ : NULL.. ..$ : chr [1:10] "I0001" "I0002" "I0003" "I0004" ...Data
data.ex10for Example 10 intam.mmlhas the following format:'data.frame': 675 obs. of 7 variables:$ pid : int 1 1 1 2 2 3 3 4 4 5 ...$ rater: int 1 2 3 2 3 1 2 1 3 1 ...$ I0001: num 0 1 1 1 1 1 1 1 1 1 ...$ I0002: num 1 1 1 1 1 0 1 1 1 1 ...$ I0003: num 1 1 1 1 0 0 0 1 0 1 ...$ I0004: num 0 1 0 0 1 0 1 0 1 0 ...$ I0005: num 0 0 1 1 1 0 0 1 0 1 ...Data
data.ex11for Example 11 intam.mmlhas the following format:'data.frame': 3400 obs. of 13 variables:$ booklet: chr "B1" "B1" "B3" "B2" ...$ M133 : int 1 1 NA 1 NA 1 NA 1 0 1 ...$ M176 : int 1 0 1 NA 0 0 0 NA NA NA ...$ M202 : int NA NA NA 0 NA NA NA 0 0 0 ...$ M212 : int NA NA 1 0 0 NA 0 1 0 0 ...$ M214 : int 1 0 1 1 0 0 0 0 1 0 ...$ M259 : int NA NA 1 1 1 NA 1 1 1 1 ...$ M303 : int NA NA 1 1 1 NA 1 1 1 0 ...$ M353 : int NA NA NA 1 NA NA NA 1 1 9 ...$ M355 : int NA NA NA 1 NA NA NA 1 1 0 ...$ M444 : int 0 0 0 NA 0 0 0 NA NA NA ...$ M446 : int 1 0 0 1 0 1 1 1 0 0 ...$ M449 : int NA NA NA 1 NA NA NA 1 1 1 ...Missing responses by design are coded as
NA, omittedresponses are coded as9.Data
data.ex12for Example 12 intam.mmlhas the following format:num [1:100, 1:10] 1 1 1 1 1 1 1 1 1 1 ...- attr(*, "dimnames")=List of 2..$ : NULL..$ : chr [1:10] "I0001" "I0002" "I0003" "I0004" ...Data
data.ex14for Example 14 intam.mmlhas the following format:'data.frame': 1110 obs. of 11 variables:$ pid : num 1001 1001 1001 1001 1001 ...$ X1 : num 1 1 1 1 1 1 0 0 0 0 ...$ X2 : int 1 1 1 1 1 1 1 1 1 1 ...$ rater: int 4 4 4 4 4 4 4 4 4 4 ...$ crit1: int 0 0 2 1 1 2 0 0 0 0 ...$ crit2: int 0 0 0 0 0 0 0 0 0 0 ...$ crit3: int 0 1 1 0 0 1 0 0 1 0 ...$ crit4: int 0 0 0 1 0 0 0 0 0 0 ...$ crit5: int 0 0 0 0 1 1 0 0 0 0 ...$ crit6: int 0 0 0 0 1 0 0 0 0 0 ...$ crit7: int 1 0 2 0 0 0 0 0 0 0 ...Data
data.ex15for Example 15 intam.mmlhas the following format:'data.frame': 2155 obs. of 182 variables:$ pid : num 10001 10002 10003 10004 10005 ...$ group : num 1 1 0 0 1 0 1 0 1 1 ...$ Item001: num 0 NA NA 0 NA NA NA 0 0 NA ...$ Item002: num 1 NA NA 1 NA NA NA NA 1 NA ...$ Item003: num NA NA NA NA 1 NA NA NA NA 1 ...$ Item004: num NA NA 0 NA NA NA NA NA NA NA ...$ Item005: num NA NA 1 NA NA NA NA NA NA NA ...[...]This dataset shows an atypical convergence behavior. Look at Example 15to fix convergence problems using arguments
increment.factorandfac.oldxsi.Data
data.exJ03for Example 4 intam.jmlhas the following format:List of 2$ resp:'data.frame': 40 obs. of 20 variables:..$ I104: int [1:40] 4 5 6 5 3 4 3 5 4 6 .....$ I118: int [1:40] 6 4 6 5 3 2 5 3 5 4 ...[...]..$ I326: int [1:40] 6 1 5 1 4 2 4 1 6 1 .....$ I338: int [1:40] 6 2 6 1 6 2 4 1 6 1 ...$ X :'data.frame': 40 obs. of 4 variables:..$ rater : int [1:40] 40 40 96 96 123 123 157 157 164 164 .....$ gender: int [1:40] 2 2 1 1 1 1 2 2 2 2 .....$ region: num [1:40] 1 1 1 1 2 2 1 1 1 1 .....$ leader: int [1:40] 1 2 1 2 1 2 1 2 1 2 ...It is a rating dataset (a subset of a dataset provided by Matt Barney).
Data
data.ex16contains dichotomous item response data fromthree studies corresponding to three grades.'data.frame': 3235 obs. of 25 variables:$ idstud: num 1e+05 1e+05 1e+05 1e+05 1e+05 ...$ grade : num 1 1 1 1 1 1 1 1 1 1 ...$ A1 : int 1 1 1 1 1 1 1 1 1 1 ...$ B1 : int 1 1 1 1 1 1 1 1 1 1 ...$ C1 : int 1 1 1 1 1 1 1 1 1 1 ...$ D1 : int 1 1 1 1 1 1 1 1 1 1 ...$ E1 : int 0 0 1 0 1 1 1 0 1 1 ...$ E2 : int 1 1 1 1 1 1 1 0 1 1 ...$ E3 : int 1 1 1 1 1 1 1 0 1 1 ...$ F1 : int 1 0 1 1 0 0 1 0 1 1 ...$ G1 : int 0 1 1 1 1 0 1 0 1 1 ...$ G2 : int 1 1 1 1 1 0 0 0 1 1 ...$ G3 : int 1 0 1 1 1 0 0 0 1 1 ...$ H1 : int 1 0 1 1 1 0 0 0 1 1 ...$ H2 : int 1 0 1 1 1 0 0 0 1 1 ...$ I1 : int 1 0 1 0 1 0 0 0 1 1 ...$ I2 : int 1 0 1 0 1 0 0 0 1 1 ...$ J1 : int NA NA NA NA NA NA NA NA NA NA ...$ K1 : int NA NA NA NA NA NA NA NA NA NA ...$ L1 : int NA NA NA NA NA NA NA NA NA NA ...$ L2 : int NA NA NA NA NA NA NA NA NA NA ...$ L3 : int NA NA NA NA NA NA NA NA NA NA ...$ M1 : int NA NA NA NA NA NA NA NA NA NA ...$ M2 : int NA NA NA NA NA NA NA NA NA NA ...$ M3 : int NA NA NA NA NA NA NA NA NA NA ...Data
data.ex17contains polytomous item response data fromthree studies corresponding to three grades.'data.frame': 3235 obs. of 15 variables:$ idstud: num 1e+05 1e+05 1e+05 1e+05 1e+05 ...$ grade : num 1 1 1 1 1 1 1 1 1 1 ...$ A : int 1 1 1 1 1 1 1 1 1 1 ...$ B : int 1 1 1 1 1 1 1 1 1 1 ...$ C : int 1 1 1 1 1 1 1 1 1 1 ...$ D : int 1 1 1 1 1 1 1 1 1 1 ...$ E : num 2 2 3 2 3 3 3 0 3 3 ...$ F : int 1 0 1 1 0 0 1 0 1 1 ...$ G : num 2 2 3 3 3 0 1 0 3 3 ...$ H : num 2 0 2 2 2 0 0 0 2 2 ...$ I : num 2 0 2 0 2 0 0 0 2 2 ...$ J : int NA NA NA NA NA NA NA NA NA NA ...$ K : int NA NA NA NA NA NA NA NA NA NA ...$ L : num NA NA NA NA NA NA NA NA NA NA ...$ M : num NA NA NA NA NA NA NA NA NA NA ...
See Also
These examples are used in thetam.mml Examples.
Dataset FIMS Study with Responses of Australian and Japanese Students
Description
Dataset FIMS study with raw responses (data.fims.Aus.Jpn.raw) orscored responses (data.fims.Aus.Jpn.scored) of Australian andJapanese Students.
Usage
data(data.fims.Aus.Jpn.raw)data(data.fims.Aus.Jpn.scored)Format
A data frame with 6371 observations on the following 16 variables.
SEXGender: 1 – male, 2 – female
M1PTI1A Mathematics item
M1PTI2A Mathematics item
M1PTI3A Mathematics item
M1PTI6A Mathematics item
M1PTI7A Mathematics item
M1PTI11A Mathematics item
M1PTI12A Mathematics item
M1PTI14A Mathematics item
M1PTI17A Mathematics item
M1PTI18A Mathematics item
M1PTI19A Mathematics item
M1PTI21A Mathematics item
M1PTI22A Mathematics item
M1PTI23A Mathematics item
countryCountry: 1 – Australia, 2 – Japan
See Also
http://www.edmeasurementsurveys.com/TAM/Tutorials/7DIF.htm
Examples
## Not run: data(data.fims.Aus.Jpn.scored)#*****# Model 1: Differential Item Functioning Gender for Australian students# extract Australian studentsscored <- data.fims.Aus.Jpn.scored[ data.fims.Aus.Jpn.scored$country==1, ]# select itemsitems <- grep("M1", colnames(data.fims.Aus.Jpn.scored), value=TRUE)## > items## [1] "M1PTI1" "M1PTI2" "M1PTI3" "M1PTI6" "M1PTI7" "M1PTI11" "M1PTI12"## [8] "M1PTI14" "M1PTI17" "M1PTI18" "M1PTI19" "M1PTI21" "M1PTI22" "M1PTI23"# Run partial credit modelmod1 <- TAM::tam.mml(scored[,items])# extract values of the gender variable into a variable called "gender".gender <- scored[,"SEX"]# computes the test score for each student by calculating the row sum# of each student's scored responses.raw_score <- rowSums(scored[,items] )# compute the mean test score for each gender group: 1=male, and 2=femalestats::aggregate(raw_score,by=list(gender),FUN=mean)# The mean test score is 6.12 for group 1 (males) and 6.27 for group 2 (females).# That is, the two groups performed similarly, with girls having a slightly# higher mean test score. The step of computing raw test scores is not necessary# for the IRT analyses. But it's always a good practice to explore the data# a little before delving into more complex analyses.# Facets analysis# To conduct a DIF analysis, we set up the variable "gender" as a facet and# re-run the IRT analysis.formulaA <- ~item+gender+item*gender # define facets analysisfacets <- as.data.frame(gender) # data frame with student covariates# facets model for studying differential item functioningmod2 <- TAM::tam.mml.mfr( resp=scored[,items], facets=facets, formulaA=formulaA )summary(mod2)## End(Not run)Dataset from Geiser et al. (2006)
Description
This is a subsample of the dataset used in Geiser et al. (2006) andGeiser and Eid (2010).
Usage
data(data.geiser)Format
A data frame with 519 observations on the following 24 variables
'data.frame': 519 obs. of 24 variables: $ mrt1 : num 0 0 0 0 0 0 0 0 0 0 ... $ mrt2 : num 0 0 0 0 0 0 0 0 0 0 ... $ mrt3 : num 0 0 0 0 0 0 0 0 1 0 ... $ mrt4 : num 0 0 0 0 0 1 0 0 0 0 ...[...] $ mrt23: num 0 0 0 0 0 0 0 1 0 0 ... $ mrt24: num 0 0 0 0 0 0 0 0 0 0 ...
References
Geiser, C., & Eid, M. (2010). Item-Response-Theorie.In C. Wolf & H. Best (Hrsg.).Handbuch der sozialwissenschaftlichenDatenanalyse (S. 311-332). VS Verlag fuer Sozialwissenschaften.
Geiser, C., Lehmann, W., & Eid, M. (2006). Separating rotators fromnonrotators in the mental rotations test: A multigroup latent class analysis.Multivariate Behavioral Research, 41(3), 261-293.doi:10.1207/s15327906mbr4103_2
Examples
## Not run: ############################################################################## EXAMPLE 1: Latent trait and latent class models (Geiser et al., 2006, MBR)#############################################################################data(data.geiser)dat <- data.geiser#**********************************************# Model 1: Rasch modeltammodel <- " LAVAAN MODEL: F=~ 1*mrt1__mrt12 F ~~ F ITEM TYPE: ALL(Rasch) "mod1 <- TAM::tamaan( tammodel, dat)summary(mod1)#**********************************************# Model 2: 2PL modeltammodel <- " LAVAAN MODEL: F=~ mrt1__mrt12 F ~~ 1*F "mod2 <- TAM::tamaan( tammodel, dat)summary(mod2)# model comparison Rasch vs. 2PLanova(mod1,mod2)#*********************************************************************#*** Model 3: Latent class analysis with four classestammodel <- "ANALYSIS: TYPE=LCA; NCLASSES(4); # 4 classes NSTARTS(10,20); # 10 random starts with 20 iterationsLAVAAN MODEL: F=~ mrt1__mrt12 "mod3 <- TAM::tamaan( tammodel, resp=dat )summary(mod3)# extract item response functionsimod2 <- IRT.irfprob(mod3)[,2,]# plot class specific probabilitiesmatplot( imod2, type="o", pch=1:4, xlab="Item", ylab="Probability" )legend( 10,1, paste0("Class",1:4), lty=1:4, col=1:4, pch=1:4 )#*********************************************************************#*** Model 4: Latent class analysis with five classestammodel <- "ANALYSIS: TYPE=LCA; NCLASSES(5); NSTARTS(10,20);LAVAAN MODEL: F=~ mrt1__mrt12 "mod4 <- TAM::tamaan( tammodel, resp=dat )summary(mod4)# compare different modelsAIC(mod1); AIC(mod2); AIC(mod3); AIC(mod4)BIC(mod1); BIC(mod2); BIC(mod3); BIC(mod4)# more condensed formIRT.compareModels(mod1, mod2, mod3, mod4)############################################################################## EXAMPLE 2: Rasch model and mixture Rasch model (Geiser & Eid, 2010)#############################################################################data(data.geiser)dat <- data.geiser#*********************************************************************#*** Model 1: Rasch modeltammodel <- "LAVAAN MODEL: F=~ mrt1__mrt6 F ~~ FITEM TYPE: ALL(Rasch); "mod1 <- TAM::tamaan( tammodel, resp=dat )summary(mod1)#*********************************************************************#*** Model 2: Mixed Rasch model with two classestammodel <- "ANALYSIS: TYPE=MIXTURE ; NCLASSES(2); NSTARTS(20,25);LAVAAN MODEL: F=~ mrt1__mrt6 F ~~ FITEM TYPE: ALL(Rasch); "mod2 <- TAM::tamaan( tammodel, resp=dat )summary(mod2)# plot item parametersipars <- mod2$itempartable_MIXTURE[ 1:6, ]plot( 1:6, ipars[,3], type="o", ylim=c(-3,2), pch=16, xlab="Item", ylab="Item difficulty")lines( 1:6, ipars[,4], type="l", col=2, lty=2)points( 1:6, ipars[,4], col=2, pch=2)# extract individual posterior distributionpost2 <- IRT.posterior(mod2)str(post2)# num [1:519, 1:30] 0.000105 0.000105 0.000105 0.000105 0.000105 ...# - attr(*, "theta")=num [1:30, 1:30] 1 0 0 0 0 0 0 0 0 0 ...# - attr(*, "prob.theta")=num [1:30, 1] 1.21e-05 2.20e-04 2.29e-03 1.37e-02 4.68e-02 ...# - attr(*, "G")=num 1# There are 2 classes and 15 theta grid points for each class# The loadings of the theta grid on items are as followsmod2$E[1,2,,"mrt1_F_load_Cl1"]mod2$E[1,2,,"mrt1_F_load_Cl2"]# compute individual posterior probability for class 1 (first 15 columns)round( rowSums( post2[, 1:15] ), 3 )# columns 16 to 30 refer to class 2#*********************************************************************#*** Model 3: Mixed Rasch model with three classestammodel <- "ANALYSIS: TYPE=MIXTURE ; NCLASSES(3); NSTARTS(20,25);LAVAAN MODEL: F=~ mrt1__mrt6 F ~~ FITEM TYPE: ALL(Rasch); "mod3 <- TAM::tamaan( tammodel, resp=dat )summary(mod3)# plot item parametersipars <- mod3$itempartable_MIXTURE[ 1:6, ]plot( 1:6, ipars[,3], type="o", ylim=c(-3.7,2), pch=16, xlab="Item", ylab="Item difficulty")lines( 1:6, ipars[,4], type="l", col=2, lty=2)points( 1:6, ipars[,4], col=2, pch=2)lines( 1:6, ipars[,5], type="l", col=3, lty=3)points( 1:6, ipars[,5], col=3, pch=17)# model comparisonIRT.compareModels( mod1, mod2, mod3 )## End(Not run)Dataset with Ordered Indicators
Description
Dataset with ordered values of 3 indicators
Usage
data(data.gpcm)Format
A data frame with 392 observations on the following 3 items.
Comforta numeric vector
Worka numeric vector
Benefita numeric vector
Source
The dataset is copied from theltm package.
Examples
data(data.gpcm)summary(data.gpcm)Dataset from Janssen and Geiser (2010)
Description
Dataset used in Janssen and Geiser (2010).
Usage
data(data.janssen)data(data.janssen2)Format
data.janssenis a data frame with 346 observations on the 8items of the following format'data.frame': 346 obs. of 8 variables:$ PIS1 : num 1 1 1 0 0 1 1 1 0 1 ...$ PIS3 : num 0 1 1 1 1 1 0 1 1 1 ...$ PIS4 : num 1 1 1 1 1 1 1 1 1 1 ...$ PIS5 : num 0 1 1 0 1 1 1 1 1 0 ...$ SCR6 : num 1 1 1 1 1 1 1 1 1 0 ...$ SCR9 : num 1 1 1 1 0 0 0 1 0 0 ...$ SCR10: num 0 0 0 0 0 0 0 0 0 0 ...$ SCR17: num 0 0 0 0 0 1 0 0 0 0 ...data.janssen2contains 20 IST items:'data.frame': 346 obs. of 20 variables:$ IST01 : num 1 1 1 0 0 1 1 1 0 1 ...$ IST02 : num 1 0 1 0 1 1 1 1 0 1 ...$ IST03 : num 0 1 1 1 1 1 0 1 1 1 ...[...]$ IST020: num 0 0 0 1 1 0 0 0 0 0 ...
References
Janssen, A. B., & Geiser, C. (2010). On the relationship between solutionstrategies in two mental rotation tasks.Learning and Individual Differences, 20(5), 473-478.doi:10.1016/j.lindif.2010.03.002
Examples
## Not run: ############################################################################## EXAMPLE 1: CCT data, Janssen and Geiser (2010, LID)# Latent class analysis based on data.janssen#############################################################################data(data.janssen)dat <- data.janssencolnames(dat) ## [1] "PIS1" "PIS3" "PIS4" "PIS5" "SCR6" "SCR9" "SCR10" "SCR17"#*********************************************************************#*** Model 1: Latent class analysis with two classestammodel <- "ANALYSIS: TYPE=LCA; NCLASSES(2); NSTARTS(10,20);LAVAAN MODEL: # missing item numbers (e.g. PIS2) are ignored in the model F=~ PIS1__PIS5 + SCR6__SCR17 "mod3 <- TAM::tamaan( tammodel, resp=dat )summary(mod3)# extract item response functionsimod2 <- IRT.irfprob(mod3)[,2,]# plot class specific probabilitiesncl <- 2matplot( imod2, type="o", pch=1:ncl, xlab="Item", ylab="Probability" )legend( 1, .3, paste0("Class",1:ncl), lty=1:ncl, col=1:ncl, pch=1:ncl )#*********************************************************************#*** Model 2: Latent class analysis with three classestammodel <- "ANALYSIS: TYPE=LCA; NCLASSES(3); NSTARTS(10,20);LAVAAN MODEL: F=~ PIS1__PIS5 + SCR6__SCR17 "mod3 <- TAM::tamaan( tammodel, resp=dat )summary(mod3)# extract item response functionsimod2 <- IRT.irfprob(mod3)[,2,]# plot class specific probabilitiesncl <- 3matplot( imod2, type="o", pch=1:ncl, xlab="Item", ylab="Probability" )legend( 1, .3, paste0("Class",1:ncl), lty=1:ncl, col=1:ncl, pch=1:ncl )# compare modelsAIC(mod1); AIC(mod2)## End(Not run)Dataset with Raw and Scored Responses from Multiple Choice Items
Description
Dataset of responses from multiple choice items, containing 143 studentson 30 items.
Usage
data(data.mc)Format
The dataset is a list with two elements. The entryrawcontains unscored (raw) item responses and the entryscoredcontains the scored (recoded) item responses. The format is:
List of 2 $ raw : chr [1:143, 1:30] "A" "A" "A" "A" ... ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : chr [1:30] "I01" "I02" "I03" "I04" ... $ scored:'data.frame': ..$ I01: num [1:143] 1 1 1 1 1 1 1 1 1 1 ... ..$ I02: num [1:143] 1 1 1 0 1 1 1 1 1 1 ... ..$ I03: num [1:143] 1 1 1 1 1 1 1 1 1 1 ... [...] ..$ I29: num [1:143] NA 0 1 0 1 0 0 0 0 0 ... ..$ I30: num [1:143] NA NA 1 1 1 1 0 1 1 0 ...
Dataset Numeracy
Description
Dataset numeracy with unscored (raw) and scored (scored)item responses of 876 persons and 15 items.
Usage
data(data.numeracy)Format
The format is a list a two entries:
List of 2 $ raw :'data.frame': ..$ I1 : int [1:876] 1 0 1 0 0 0 0 0 1 1 ... ..$ I2 : int [1:876] 0 1 0 0 1 1 1 1 1 0 ... ..$ I3 : int [1:876] 4 4 1 3 4 4 4 4 4 4 ... ..$ I4 : int [1:876] 4 1 2 2 1 1 1 1 1 1 ... [...] ..$ I15: int [1:876] 1 1 1 1 0 1 1 1 1 1 ... $ scored:'data.frame': ..$ I1 : int [1:876] 1 0 1 0 0 0 0 0 1 1 ... ..$ I2 : int [1:876] 0 1 0 0 1 1 1 1 1 0 ... ..$ I3 : int [1:876] 1 1 0 0 1 1 1 1 1 1 ... ..$ I4 : int [1:876] 0 1 0 0 1 1 1 1 1 1 ... [...] ..$ I15: int [1:876] 1 1 1 1 0 1 1 1 1 1 ...
Examples
####################################################################### (1) Scored numeracy data######################################################################data(data.numeracy)dat <- data.numeracy$scored#Run IRT analysis: Rasch modelmod1 <- TAM::tam.mml(dat)#Item difficultiesmod1$xsiItemDiff <- mod1$xsi$xsiItemDiff#Ability estimate - Weighted Likelihood EstimateAbil <- TAM::tam.wle(mod1)AbilPersonAbility <- Abil$thetaPersonAbility#Descriptive statistics of item and person parametershist(ItemDiff)hist(PersonAbility)mean(ItemDiff)mean(PersonAbility)stats::sd(ItemDiff)stats::sd(PersonAbility)## Not run: #Extension#plot histograms of ability and item parameters in the same grapholdpar <- par(no.readonly=TRUE) # save writable default graphic settingswindows(width=4.45, height=4.45, pointsize=12)layout(matrix(c(1,1,2),3,byrow=TRUE))layout.show(2)hist(PersonAbility,xlim=c(-3,3),breaks=20)hist(ItemDiff,xlim=c(-3,3),breaks=20)par( oldpar ) # restore default graphic settingshist(PersonAbility,xlim=c(-3,3),breaks=20)####################################################################### (2) Raw numeracy data######################################################################raw_resp <- data.numeracy$raw#score responseskey <- c(1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1)scored <- sapply( seq(1,length(key)), FUN=function(ii){ 1*(raw_resp[,ii]==key[ii]) } )#run IRT analysismod1 <- TAM::tam.mml(scored)#Ability estimate - Weighted Likelihood EstimateAbil <- TAM::tam.wle(mod1)#CTT statisticsctt1 <- TAM::tam.ctt(raw_resp, Abil$theta)write.csv(ctt1,"D1_ctt1.csv") # write statistics into a file # use maybe write.csv2 if ';' should be the column separator#Fit statisticsFit <- TAM::tam.fit(mod1)Fit# plot expected response curvesplot( mod1, ask=TRUE )## End(Not run)Simulated Multifaceted Data
Description
Simulated data from multiple facets.
Usage
data(data.sim.mfr) data(data.sim.facets)Format
The format ofdata.sim.mfr is: num [1:100, 1:5] 3 2 1 1 0 1 0 1 0 0 ... - attr(*, "dimnames")=List of 2 ..$ : chr [1:100] "V1" "V1.1" "V1.2" "V1.3" ... ..$ : NULL
The format ofdata.sim.facets is:'data.frame': 100 obs. of 3 variables: $ rater : num 1 2 3 4 5 1 2 3 4 5 ... $ topic : num 3 1 3 1 3 2 3 2 2 1 ... $ female: num 2 2 1 2 1 1 2 1 2 1 ...
Source
Simulated
Examples
######## sim multi faceted Rasch modeldata(data.sim.mfr)data(data.sim.facets) # 1: A-matrix test_rater test_1_items <- TAM::.A.matrix( data.sim.mfr, formulaA=~rater, facets=data.sim.facets, constraint="items" ) test_1_cases <- TAM::.A.matrix( data.sim.mfr, formulaA=~rater, facets=data.sim.facets, constraint="cases" ) # 2: test_item+rater test_2_cases <- TAM::.A.matrix( data.sim.mfr, formulaA=~item+rater, facets=data.sim.facets, constraint="cases" ) # 3: test_item+rater+topic+ratertopic test_3_items <- TAM::.A.matrix( data.sim.mfr, formulaA=~item+rater*topic, facets=data.sim.facets, constraint="items" ) # conquest uses a different way of ordering the rows # these are the first few rows of the conquest design matrix # test_3_items$A[grep("item1([[:print:]])*topic1", rownames(test_3_items)),] # 4: test_item+step test_4_cases <- TAM::.A.matrix( data.sim.mfr, formulaA=~item+step, facets=data.sim.facets, constraint="cases" ) # 5: test_item+item:step test_5_cases <- TAM::.A.matrix( data.sim.mfr, formulaA=~item+item:step, facets=data.sim.facets, constraint="cases" ) test_5_cases$A[, grep("item1", colnames(test_5_cases)) ] # 5+x: more #=> 6: is this even well defined in the conquest-design output # (see test_item+topicstep_cases.cqc / .des) # regardless of the meaning of such a formula; # currently .A.matrix throws a warning # test_6_cases <- TAM::.A.matrix( data.sim.mfr, formulaA=~item+topic:step, # facets=data.sim.facets, constraint="cases" ) test_7_cases <- TAM::.A.matrix( data.sim.mfr, formulaA=~item+topic+topic:step, facets=data.sim.facets, constraint="cases" )## Not run: #=> 8: same as with 6 test_8_cases <- TAM::.A.matrix( data.sim.mfr, formulaA=~item+rater+item:rater:step, facets=data.sim.facets, constraint="cases" )## [1] "Can't proceed the estimation: Lower-order term is missing." test_9_cases <- TAM::.A.matrix( data.sim.mfr, formulaA=~item+step+rater+item:step+item:rater, facets=data.sim.facets, constraint="cases" ) test_10_cases <- TAM::.A.matrix( data.sim.mfr, formulaA=~item+female+item:female, facets=data.sim.facets, constraint="cases" ) ### All Design matrices test_1_cases <- TAM::designMatrices.mfr( data.sim.mfr, formulaA=~rater, facets=data.sim.facets, constraint="cases" ) test_4_cases <- TAM::designMatrices.mfr( data.sim.mfr, formulaA=~item+item:step, facets=data.sim.facets, constraint="cases" ) ### TAM test_4_cases <- TAM::tam.mml.mfr( data.sim.mfr, formulaA=~item+item:step ) test_tam <- TAM::tam.mml( data.sim.mfr ) test_1_cases <- TAM::tam.mml.mfr( data.sim.mfr, formulaA=~rater, facets=data.sim.facets, constraint="cases" ) test_2_cases <- TAM::tam.mml.mfr( data.sim.mfr, formulaA=~item+rater, facets=data.sim.facets, constraint="cases" )## End(Not run)Simulated Rasch data
Description
Simulated Rasch data under unidimensional trait distribution
Usage
data(data.sim.rasch) data(data.sim.rasch.pweights) data(data.sim.rasch.missing)Format
The format is:num [1:2000, 1:40] 1 0 1 1 1 1 1 1 1 1 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:40] "I1" "I2" "I3" "I4" ...
Details
N <- 2000 # simulate predictors Y <- cbind( stats::rnorm( N, sd=1.5), stats::rnorm(N, sd=.3 ) ) theta <- stats::rnorm( N ) + .4 * Y[,1] + .2 * Y[,2] # latent regression model # simulate item responses with missing data I <- 40 resp[ theta < 0, c(1,seq(I/2+1, I)) ] <- NA # define person weights pweights <- c( rep(3,N/2), rep( 1, N/2 ) )
Source
Simulated data (see Details)
Examples
## Not run: data(data.sim.rasch)N <- 2000Y <- cbind( stats::rnorm( N, sd=1.5), stats::rnorm(N, sd=.3 ) )# Loading Matrix# B <- array( 0, dim=c( I, 2, 1 ) )# B[1:(nrow(B)), 2, 1] <- 1B <- TAM::designMatrices(resp=data.sim.rasch)[["B"]]# estimate Rasch modelmod1_1 <- TAM::tam.mml(resp=data.sim.rasch, Y=Y)# standard errorsres1 <- TAM::tam.se(mod1_1)# Compute fit statisticstam.fit(mod1_1)# plausible value imputation# PV imputation has to be adpated for multidimensional case!pv1 <- TAM::tam.pv( mod1_1, nplausible=7, # 7 plausible values samp.regr=TRUE # sampling of regression coefficients )# item parameter constraintsxsi.fixed <- matrix( c( 1, -2,5, -.22,10, 2 ), nrow=3, ncol=2, byrow=TRUE)xsi.fixedmod1_4 <- TAM::tam.mml( resp=data.sim.rasch, xsi.fixed=xsi.fixed )# missing value handlingdata(data.sim.rasch.missing)mod1_2 <- TAM::tam.mml(data.sim.rasch.missing, Y=Y)# handling of sample (person) weightsdata(data.sim.rasch.pweights)N <- 1000pweights <- c( rep(3,N/2), rep( 1, N/2 ) )mod1_3 <- TAM::tam.mml( data.sim.rasch.pweights, control=list(conv=.001), pweights=pweights ) ## End(Not run)Dataset TIMSS 2011 of Australian and Taiwanese Students
Description
Mathematics items of TIMSS 2011 of 1773 Australian andTaiwanese students. The datasetdata.timssAusTwn contains rawresponses whiledata.timssAusTwn.scored contains scored itemresponses.
Usage
data(data.timssAusTwn)data(data.timssAusTwn.scored)Format
A data frame with 1773 observations on the following 14 variables.
M032166a mathematics item
M032721a mathematics item
M032757a mathematics item
M032760Aa mathematics item
M032760Ba mathematics item
M032760Ca mathematics item
M032761a mathematics item
M032692a mathematics item
M032626a mathematics item
M032595a mathematics item
M032673a mathematics item
IDCNTRYCountry identifier
ITSEXGender
IDBOOKBooklet identifier
See Also
http://www.edmeasurementsurveys.com/TAM/Tutorials/5PartialCredit.htm
http://www.edmeasurementsurveys.com/TAM/Tutorials/6Population.htm
Examples
data(data.timssAusTwn)raw_resp <- data.timssAusTwn#Recode dataresp <- raw_resp[,1:11] #Column 12 is country code. Column 13 is gender code. Column 14 is Book ID.all.na <- rowMeans( is.na(resp) )==1 #Find records where all responses are missing.resp <- resp[!all.na,] #Delete records with all missing responsesresp[resp==20 | resp==21] <- 2 #TIMSS double-digit coding: "20" or "21" is a score of 2resp[resp==10 | resp==11] <- 1 #TIMSS double-digit coding: "10" or "11" is a score of 1resp[resp==70 | resp==79] <- 0 #TIMSS double-digit coding: "70" or "79" is a score of 0resp[resp==99] <- 0 #"99" is omitted responses. Score it as wrong here.resp[resp==96 | resp==6] <- NA #"96" and "6" are not-reached items. Treat these as missing.#Score multiple-choice items #"resp" contains raw responses for MC items.Scored <- respScored[,9] <- (resp[,9]==4)*1 #Key for item 9 is D.Scored[,c(1,2)] <- (resp[,c(1,2)]==2)*1 #Key for items 1 and 2 is B.Scored[,c(10,11)] <- (resp[,c(10,11)]==3)*1 #Key for items 10 and 11 is C.#Run IRT analysis for partial credit model (MML estimation)mod1 <- TAM::tam.mml(Scored)#Item parametersmod1$xsi#Thurstonian thresholdstthresh <- TAM::tam.threshold(mod1)tthresh## Not run: #Plot Thurstonian thresholdswindows (width=8, height=7)par(ps=9)dotchart(t(tthresh), pch=19)# plot expected response curvesplot( mod1, ask=TRUE)#Re-run IRT analysis in JMLmod1.2 <- TAM::tam.jml(Scored)stats::var(mod1.2$WLE)#Re-run the model with "not-reached" coded as incorrect.Scored2 <- ScoredScored2[is.na(Scored2)] <- 0#Prepare anchor parameter valuesnparam <- length(mod1$xsi$xsi)xsi <- mod1$xsi$xsianchor <- matrix(c(seq(1,nparam),xsi), ncol=2)#Run IRT with item parameters anchored on mod1 valuesmod2 <- TAM::tam.mml(Scored2, xsi.fixed=anchor)#WLE ability estimatesability <- TAM::tam.wle(mod2)ability#CTT statisticsctt <- TAM::tam.ctt(resp, ability$theta)write.csv(ctt,"TIMSS_CTT.csv")#plot histograms of ability and item parameters in the same graphwindows(width=4.45, height=4.45, pointsize=12)layout(matrix(c(1,1,2),3,byrow=TRUE))layout.show(2)hist(ability$theta,xlim=c(-3,3),breaks=20)hist(tthresh,xlim=c(-3,3),breaks=20)#Extension#Score equivalence tabledummy <- matrix(0,nrow=16,ncol=11)dummy[lower.tri(dummy)] <- 1dummy[12:16,c(3,4,7,8)][lower.tri(dummy[12:16,c(3,4,7,8)])]<-2mod3 <- TAM::tam.mml(dummy, xsi.fixed=anchor)wle3 <- TAM::tam.wle(mod3)## End(Not run)Generation of Design Matrices
Description
Generate design matrices, and display them at console.
Usage
designMatrices(modeltype=c("PCM", "RSM"), maxKi=NULL, resp=resp, ndim=1, A=NULL, B=NULL, Q=NULL, R=NULL, constraint="cases",...)## S3 method for class 'designMatrices'print(x, ...)designMatrices.mfr(resp, formulaA=~ item + item:step, facets=NULL, constraint=c("cases", "items"), ndim=1, Q=NULL, A=NULL, B=NULL, progress=FALSE)designMatrices.mfr2(resp, formulaA=~ item + item:step, facets=NULL, constraint=c("cases", "items"), ndim=1, Q=NULL, A=NULL, B=NULL, progress=FALSE).A.matrix(resp, formulaA=~ item + item*step, facets=NULL, constraint=c("cases", "items"), progress=FALSE, maxKi=NULL)rownames.design(X).A.PCM2( resp, Kitem=NULL, constraint="cases", Q=NULL) # generates ConQuest parametrization of partial credit model.A.PCM3( resp, Kitem=NULL ) # parametrization for A matrix in the dispersion modelArguments
modeltype | Type of item response model. Until now, thepartial credit model ( |
maxKi | A vector containing the maximum score per item |
resp | Data frame of item responses |
ndim | Number of dimensions |
A | The design matrix for linking item category parametersto generalized item parameters |
B | The scoring matrix of item categories on |
Q | A loading matrix of items on dimensionswith number of rows equal the numberof items and the number of columns equals thenumber of dimensions in the item response model. |
R | This argument is not used |
x | Object generated by |
X | Object generated by |
formulaA | AnR formula object for generating the |
facets | A data frame with observed facets. The number of rows must be equalto the number of rows in |
constraint | Constraint in estimation: |
Kitem | Maximum number of categories per item |
progress | Display progress for creation of design matrices |
... | Further arguments |
Details
The function.A.PCM2 generates the Conquest parametrizationof the partial credit model.
The function.A.PCM3 generates the parametrization for theAdesign matrix in the dispersion model for ordered data (Andrich, 1982).
Note
The functiondesignMatrices.mfr2 handles multi-faceted design foritems with differing number of response options.
References
Andrich, D. (1982). An extension of the Rasch model for ratings providingboth location and dispersion parameters.Psychometrika, 47(1),105-113.doi:10.1007/BF02293856
See Also
Seedata.sim.mfr for some examples for creating design matrices.
Examples
############################################################ different parametrizations for ordered datadata( data.gpcm )resp <- data.gpcm# parametrization for partial credit modelA1 <- TAM::designMatrices( resp=resp )$A# item difficulty and threshold parametrizationA2 <- TAM::.A.PCM2( resp )# dispersion model of Andrich (1982)A3 <- TAM::.A.PCM3( resp )# rating scale modelA4 <- TAM::designMatrices( resp=resp, modeltype="RSM" )$AParsing a String withDO Statements
Description
This function parses a string and expands this string in case ofDOstatements which are shortcuts for writing loops. The statementDO(n,m,k) increments an index fromn tom in stepsofk. The index in the stringmodel must be definedas%. For a nested loop within a loop,theDO2 statement can be used using%1 and%2as indices. See Examples for hints on the specification. The loop inDO2must not be explicitly crossed, e.g. in applications for specifyingcovariances or correlations. The formal syntax for for (ii in 1:(K-1)){ for (jj in (ii+1):K) { ... } }
can be written asDO2(1,K-1,1,%1,K,1). See Example 2.
Usage
doparse(model)Arguments
model | A string with |
Value
Parsed string in whichDO statements are expanded.
See Also
This function is also used inlavaanify.IRT andtamaanify.
Examples
############################################################################## EXAMPLE 1: doparse example############################################################################## define modelmodel <- " # items I1,...,I10 load on G DO(1,10,1) G=~ lamg% * I% DOEND I2 | 0.75*t1 v10 > 0 ; # The first index loops from 1 to 3 and the second index loops from 1 to 2 DO2(1,3,1, 1,2,1) F%2=~ a%2%1 * A%2%1 ; DOEND # Loop from 1 to 9 with steps of 2 DO(1,9,2) HA1=~ I% I% | beta% * t1 DOEND "# process stringout <- TAM::doparse(model)cat(out) ## # items I1,...,I10 load on G ## G=~ lamg1 * I1 ## G=~ lamg2 * I2 ## G=~ lamg3 * I3 ## G=~ lamg4 * I4 ## G=~ lamg5 * I5 ## G=~ lamg6 * I6 ## G=~ lamg7 * I7 ## G=~ lamg8 * I8 ## G=~ lamg9 * I9 ## G=~ lamg10 * I10 ## I2 | 0.75*t1 ## v10 > 0 ## F1=~ a11 * A11 ## F2=~ a21 * A21 ## F1=~ a12 * A12 ## F2=~ a22 * A22 ## F1=~ a13 * A13 ## F2=~ a23 * A23 ## HA1=~ I1 ## HA1=~ I3 ## HA1=~ I5 ## HA1=~ I7 ## HA1=~ I9 ## I1 | beta1 * t1 ## I3 | beta3 * t1 ## I5 | beta5 * t1 ## I7 | beta7 * t1 ## I9 | beta9 * t1############################################################################## EXAMPLE 2: doparse with nested loop example############################################################################## define modelmodel <- " DO(1,4,1) G=~ lamg% * I% DOEND # specify some correlated residuals DO2(1,3,1,%1,4,1) I%1 ~~ I%2 DOEND "# process stringout <- TAM::doparse(model)cat(out) ## G=~ lamg1 * I1 ## G=~ lamg2 * I2 ## G=~ lamg3 * I3 ## G=~ lamg4 * I4 ## # specify some correlated residuals ## I1 ~~ I2 ## I1 ~~ I3 ## I1 ~~ I4 ## I2 ~~ I3 ## I2 ~~ I4 ## I3 ~~ I4Slight Extension of thelavaan Syntax, with Focus on Item Response Models
Description
This functions slightly extends thelavaansyntax implemented in thelavaan package(seelavaan::lavaanify).
Guessing and slipping parameters can be specifiedby using the operators?=g1 and?=s1,respectively.
The operator__ can be used for a convenientspecification for groups of items. For example,I1__I5 refersto itemsI1,...,I5. The operator__ can also be used foritem labels (see Example 2).
Nonlinear terms can also be specified for loadings (=~) andregressions (~) (see Example 3).
It is also possible to construct the syntax using a loop by making useof theDO statement, seedoparse for specification.
The operatorsMEASERR1 andMEASERR0 can be used formodel specification for variables which contains known measurementerror (see Example 6). WhileMEASERR1 can be used for endogenousvariables,MEASERR0 provides the specification for exogeneous variables.
Usage
lavaanify.IRT(lavmodel, items=NULL, data=NULL, include.residuals=TRUE, doparse=TRUE)Arguments
lavmodel | A model in |
items | Optional vector of item names |
data | Optional data frame with item responses |
include.residuals | Optional logical indicating whetherresidual variances should be processed such that theyare freely estimated. |
doparse | Optional logical indicating whether |
Value
A list with following entries
lavpartable | A |
lavaan.syntax | Processed syntax forlavaan package |
nonlin_factors | Data frame with renamed and original nonlinearfactor specifications |
nonlin_syntable | Data frame with original and modifiedsyntax if nonlinear factors are used. |
See Also
Seesirt::tam2mirt forconverting objects of classtam intomirtobjects.
Seesirt::lavaan2mirtfor estimating models in themirt package usinglavaan syntax.
Seedoparse for theDO andDO2 statements.
Examples
library(lavaan)############################################################################## EXAMPLE 1: lavaan syntax with guessing and slipping parameters############################################################################## define model in lavaanlavmodel <- " F=~ A1+c*A2+A3+A4 # define slipping parameters for A1 and A2 A1 + A2 ?=s1 # joint guessing parameter for A1 and A2 A1+A2 ?=c1*g1 A3 | 0.75*t1 # fix guessing parameter to .25 and # slipping parameter to .01 for item A3 A3 ?=.25*g1+.01*s1 A4 ?=c2*g1 A1 | a*t1 A2 | b*t1 "# process lavaan syntaxlavpartable <- TAM::lavaanify.IRT(lavmodel)$lavpartable ## id lhs op rhs user group free ustart exo label eq.id unco ## 1 1 F=~ A1 1 1 1 NA 0 0 1 ## 2 2 F=~ A2 1 1 2 NA 0 c 0 2 ## 3 3 F=~ A3 1 1 3 NA 0 0 3 ## 4 4 F=~ A4 1 1 4 NA 0 0 4 ## 5 5 A3 | t1 1 1 0 0.75 0 0 0 ## 6 6 A1 | t1 1 1 5 NA 0 a 0 5 ## 7 7 A2 | t1 1 1 6 NA 0 b 0 6 ## 8 8 A1 ?=s1 1 1 7 NA 0 0 7 ## 9 9 A2 ?=s1 1 1 8 NA 0 0 8 ## 10 10 A1 ?=g1 1 1 9 NA 0 c1 1 9 ## 11 11 A2 ?=g1 1 1 9 NA 0 c1 1 10 ## 12 12 A3 ?=g1 1 1 0 0.25 0 0 0 ## 13 13 A3 ?=s1 1 1 0 0.01 0 0 0 ## 14 14 A4 ?=g1 1 1 10 NA 0 c2 0 11## Not run: ############################################################################## EXAMPLE 2: Usage of "__" and "?=" operators#############################################################################library(sirt)data(data.read, package="sirt")dat <- data.readitems <- colnames(dat)lavmodel <- " F1=~ A1+A2+ A3+lam4*A4 # equal item loadings for items B1 to B4 F2=~ lam5*B1__B4 # different labelled item loadings of items C1 to C4 F3=~ lam9__lam12*C1__C4 # item intercepts B1__B2 | -0.5*t1 B3__C1 | int6*t1 # guessing parameters C1__C3 ?=g1 C4 + B1__B3 ?=0.2*g1 # slipping parameters A1__B1 + B3__C2 ?=slip1*s1 # residual variances B1__B3 ~~ errB*B1__B3 A2__A4 ~~ erra1__erra3*A2__A4 "lav2 <- TAM::lavaanify.IRT( lavmodel, data=dat)lav2$lavpartablecat( lav2$lavaan.syntax )#** simplified examplelavmodel <- " F1=~ A1+lam4*A2+A3+lam4*A4 F2=~ lam5__lam8*B1__B4 F1 ~~ F2 F1 ~~ 1*F1 F2 ~~ 1*F2 "lav3 <- TAM::lavaanify.IRT( lavmodel, data=dat)lav3$lavpartablecat( lav3$lavaan.syntax )############################################################################## EXAMPLE 3: Nonlinear terms##############################################################################*** define itemsitems <- paste0("I",1:12)#*** define lavaan modellavmodel <- " F1=~ I1__I5 F2=~ I6__I9 F3=~ I10__I12 # I3, I4 and I7 load on interaction of F1 and F2 I(F1*F2)=~ a*I3+a*I4 I(F1*F2)=~ I7 # I3 and I5 load on squared factor F1 I(F1^2)=~ I3 + I5 # I1 regression on B spline version of factor F1 I( bs(F1,4) )=~ I1 F2 ~ F1 + b*I(F1^2) + I(F1>0) F3 ~ F1 + F2 + 1.4*I(F1*F2) + b*I(F1^2) + I(F2^2 ) # F3 ~ F2 + I(F2^2) # this line is ignored in the lavaan model F1 ~~ 1*F1 "#*** process lavaan syntaxlav3 <- TAM::lavaanify.IRT( lavmodel, items=items)#*** inspect resultslav3$lavpartablecat( lav3$lavaan.syntax )lav3$nonlin_syntablelav3$nonlin_factors############################################################################## EXAMPLE 4: Using lavaanify.IRT for estimation with lavaan#############################################################################data(data.big5, package="sirt")# extract first 10 openness itemsitems <- which( substring( colnames(data.big5), 1, 1 )=="O" )[1:10]dat <- as.data.frame( data.big5[, items ] ) ## > colnames(dat) ## [1] "O3" "O8" "O13" "O18" "O23" "O28" "O33" "O38" "O43" "O48"apply(dat,2,var) # variances#*** Model 1: Confirmatory factor analysis with one factorlavmodel <- " O=~ O3__O48 # convenient syntax for defining the factor for all items O ~~ 1*O "# process lavaan syntaxres <- TAM::lavaanify.IRT( lavmodel, data=dat )# estimate lavaan modelmod1 <- lavaan::lavaan( model=res$lavaan.syntax, data=dat)summary(mod1, standardized=TRUE, fit.measures=TRUE, rsquare=TRUE )## End(Not run)############################################################################## EXAMPLE 5: lavaanify.IRT with do statements#############################################################################lavmodel <- " DO(1,6,1) F=~ I% DOEND DO(1,5,2) A=~ I% DOEND DO(2,6,2) B=~ I% DOEND F ~~ 1*F A ~~ 1*A B ~~ 1*B F ~~ 0*A F ~~ 0*B A ~~ 0*B "res <- TAM::lavaanify.IRT( lavmodel, items=paste("I",1:6) )cat(res$lavaan.syntax)############################################################################## EXAMPLE 6: Single indicator models with measurement error (MEASERR operator)############################################################################## define lavaan modellavmodel <- " ytrue ~ xtrue + z # exogeneous variable error-prone y with error variance .20 MEASERR1(ytrue,y,.20) # exogeneous variable error-prone x with error variance .35 MEASERR0(xtrue,x,.35) ytrue ~~ ytrue "# observed itemsitems <- c("y","x","z")# lavaanifyres <- TAM::lavaanify.IRT( lavmodel, items )cat(res$lavaan.syntax) ## > cat(res$lavaan.syntax) ## ytrue~xtrue ## ytrue~z ## ytrue=~1*y ## y~~0.2*y ## xtrue=~1*x ## x~~0.35*x ## xtrue~~xtrue ## ytrue~~ytrue ## z~~zMean Squared Residual Based Item Fit Statistics (Infit, Outfit)
Description
The functionmsq.itemfit computes computed the outfit and infit statisticfor items or item groups. Contrary totam.fit, the functionmsq.itemfit is not based on simulation from individual posterior distributionsbut rather on evaluating the individual posterior.
The functionmsq.itemfit also computes the outfit and infit statisticsbut these are based on weighted likelihood estimates obtained fromtam.wle.
Usage
msq.itemfit( object, fitindices=NULL)## S3 method for class 'msq.itemfit'summary(object, file=NULL, ... )msq.itemfitWLE( tamobj, fitindices=NULL, ... )## S3 method for class 'msq.itemfitWLE'summary(object, file=NULL, ... )Arguments
object | Object for which the classes |
fitindices | Vector with parameter labels defining the item groups forwhich the fit should be evaluated. |
tamobj | Object of class |
file | Optional name of a file to which the summary should be written |
... | Further arguments to be passed |
Value
List with following entries
itemfit | Data frame with outfit and infit statistics. |
summary_itemfit | Summary statistics of outfitand infit |
See Also
See alsotam.fit for simulation based assessment of item fit.
See alsoeRm::itemfit ormirt::itemfit.
Examples
## Not run: ############################################################################## EXAMPLE 1: Simulated data Rasch model##############################################################################*** simulate datalibrary(sirt)set.seed(9875)N <- 2000I <- 20b <- sample( seq( -2, 2, length=I ) )a <- rep( 1, I )# create some misfitting itemsa[c(1,3)] <- c(.5, 1.5 )# simulate datadat <- sirt::sim.raschtype( rnorm(N), b=b, fixed.a=a )#*** estimate Rasch modelmod1 <- TAM::tam.mml(resp=dat)# compute WLEswmod1 <- TAM::tam.wle(mod1)$theta#--- item fit from "msq.itemfit" functionfit1 <- TAM::msq.itemfit(mod1)summary( fit1 )#--- item fit using simulation in "tam.fit"fit0 <- TAM::tam.fit( mod1 )summary(fit0)#--- item fit based on WLEsfit2a <- TAM::msq.itemfitWLE( mod1 )summary(fit2a)#++ fit assessment in mirt packagelibrary(mirt)mod1b <- mirt::mirt( dat, model=1, itemtype="Rasch", verbose=TRUE )print(mod1b)sirt::mirt.wrapper.coef(mod1b)fmod1b <- mirt::itemfit(mod1b, Theta=as.matrix(wmod1,ncol=1), Zh=TRUE, X2=FALSE, S_X2=FALSE )cbind( fit2a$fit_data, fmod1b )#++ fit assessment in eRm packagelibrary(eRm)mod1c <- eRm::RM( dat )summary(mod1c)eRm::plotPImap(mod1c) # person-item mappmod1c <- eRm::person.parameter(mod1c)fmod1c <- eRm::itemfit(pmod1c)print(fmod1c)plot(fmod1c)#--- define some item groups for fit assessment# bases on evaluating the posteriorfitindices <- rep( paste0("IG",c(1,2)), each=10)fit2 <- TAM::msq.itemfit( mod1, fitindices )summary(fit2)# using WLEsfit2b <- TAM::msq.itemfitWLE( mod1, fitindices )summary(fit2b)############################################################################## EXAMPLE 2: data.read | fit statistics assessed for testlets#############################################################################library(sirt)data(data.read,package="sirt")dat <- data.read# fit Rasch modelmod <- TAM::tam.mml( dat )#***** item fit for each item# based on posteriorres1 <- TAM::msq.itemfit( mod )summary(res1)# based on WLEsres2 <- TAM::msq.itemfitWLE( mod )summary(res2)#***** item fit for item groups# define item groupsfitindices <- substring( colnames(dat), 1, 1 )# based on posteriorres1 <- TAM::msq.itemfit( mod, fitindices )summary(res1)# based on WLEsres2 <- TAM::msq.itemfitWLE( mod, fitindices )summary(res2)############################################################################## EXAMPLE 3: Fit statistics for rater models#############################################################################library(sirt)data(data.ratings2, package="sirt")dat <- data.ratings2# fit rater model "~ item*step + rater"mod <- TAM::tam.mml.mfr( resp=dat[, paste0( "k",1:5) ], facets=dat[, "rater", drop=FALSE], pid=dat$pid, formulaA=~ item*step + rater )# fit for parameter with "tam.fit" functionfmod1a <- TAM::tam.fit( mod )fmod1b <- TAM::msq.itemfit( mod )summary(fmod1a)summary(fmod1b)# define item groups using pseudo items from object "mod"pseudo_items <- colnames(mod$resp)pss <- strsplit( pseudo_items, split="-" )item_parm <- unlist( lapply( pss, FUN=function(ll){ ll[1] } ) )rater_parm <- unlist( lapply( pss, FUN=function(ll){ ll[2] } ) )# fit for items with "msq.itemfit" functionsres2a <- TAM::msq.itemfit( mod, item_parm )res2b <- TAM::msq.itemfitWLE( mod, item_parm )summary(res2a)summary(res2b)# fit for ratersres3a <- TAM::msq.itemfit( mod, rater_parm )res3b <- TAM::msq.itemfitWLE( mod, rater_parm )summary(res3a)summary(res3b)## End(Not run)Plot Function for Unidimensional Item Response Models
Description
S3 plot method for objects of classtam,tam.mmlortam.mml.
Usage
## S3 method for class 'tam'plot(x, items=1:x$nitems, type="expected", low=-3, high=3, ngroups=6, groups_by_item=FALSE, wle=NULL, export=TRUE, export.type="png", export.args=list(), observed=TRUE, overlay=FALSE, ask=FALSE, package="lattice", fix.devices=TRUE, nnodes=100, ...)## S3 method for class 'tam.mml'plot(x, items=1:x$nitems, type="expected", low=-3, high=3, ngroups=6, groups_by_item=FALSE, wle=NULL, export=TRUE, export.type="png", export.args=list(), observed=TRUE, overlay=FALSE, ask=FALSE, package="lattice", fix.devices=TRUE, nnodes=100, ...)## S3 method for class 'tam.jml'plot(x, items=1:x$nitems, type="expected", low=-3, high=3, ngroups=6, groups_by_item=FALSE, wle=NULL, export=TRUE, export.type="png", export.args=list(), observed=TRUE, overlay=FALSE, ask=FALSE, package="lattice", fix.devices=TRUE, nnodes=100, ...)Arguments
x | Object of class |
items | An index vector giving the items to be visualized. |
type | Plot type. |
low | Lowest |
high | Highest |
ngroups | Number of score groups to be displayed. The default aresix groups. |
groups_by_item | Logical indicating whether grouping of personsshould be conducted item-wise. The groupings will differ from item to itemin case of missing item responses. |
wle | Use WLE estimate for displaying observed scores. |
export | A logical which indicates whether all graphics should be separatelyexported in files of type |
export.type | A string which indicates the type of the graphics export. For currentlysupported file types, see |
export.args | A list of arguments that are passed to the export method can be specified.See the respective export device method for supported usage. |
observed | A logical which indicates whether observed response curve shouldbe displayed |
overlay | A logical indicating whether expected score functions should overlay. |
ask | A logical which asks for changing the graphic from item to item.The default is |
package | UsedR package for plot. Can be |
fix.devices | Optional logical indicating whether old graphics devices shouldbe saved. |
nnodes | Number of |
... | Further arguments to be passed |
Details
This plot method does not work for multidimensional item responsemodels.
Value
A plot and list of computed values forplot (if saved as an object)
Author(s)
Margaret Wu, Thomas Kiefer, Alexander Robitzsch, Michal Modzelewski
See Also
SeeCDM::IRT.irfprobPlotfor a general plot method.
Examples
## Not run: ############################################################################## EXAMPLE 1: Dichotomous data data.sim.rasch#############################################################################data(data.sim.rasch)mod <- TAM::tam.mml(data.sim.rasch)# expected response curvesplot(mod, items=1:5, export=FALSE)# export computed valuesout <- plot(mod, items=1:5, export=FALSE)# item response curvesplot(mod, items=1:5, type="items", export=FALSE)# plot with graphics packageplot(mod, items=1:5, type="items", export=FALSE, ask=TRUE, package="graphics")############################################################################## EXAMPLE 2: Polytomous data#############################################################################data(data.Students, package="CDM")dat <- data.Students[, c("sc3","sc4", "mj1", "mj2" )]dat <- na.omit(dat)dat[ dat[,1]==3, 1 ] <- 2 # modify datadat[ 1:20, 2 ] <- 4# estimate modelmod1 <- TAM::tam.mml( dat )# plot item response curves and expected response curvesplot(mod1, type="items", export=FALSE)plot(mod1, type="expected", export=FALSE )## End(Not run)Deviance Plot forTAM Objects
Description
Plots the deviance change in every iteration.
Usage
plotDevianceTAM(tam.obj, omitUntil=1, reverse=TRUE, change=TRUE)Arguments
tam.obj | Object of class |
omitUntil | An optional value indicating number of iterations to be omitted forplotting. |
reverse | A logical indicating whether the deviance change should bemultiplied by minus 1. The default is |
change | An optional logical indicating whether deviance changeor the deviance should be plotted. |
Author(s)
Martin Hecht, Sebastian Weirich, Alexander Robitzsch
Examples
############################################################################## EXAMPLE 1: deviance plot dichotomous data#############################################################################data(data.sim.rasch)# 2PL modelmod1 <- TAM::tam.mml.2pl(resp=data.sim.rasch )# plot deviance changeplotDevianceTAM( mod1 )# plot devianceplotDevianceTAM( mod1, change=FALSE)Expected Values and Predicted Probabilities for FittedTAM Models
Description
Extracts predicted values from the posterior distribution for modelsfitted inTAM.
SeeCDM::predictfor more details.
Usage
## S3 method for class 'tam.mml'predict(object, ...)## S3 method for class 'tam.mml.3pl'predict(object, ...)## S3 method for class 'tamaan'predict(object, ...)Arguments
object | Object of class |
... | Further arguments to be passed |
Value
List with entries for predicted values (expectations and probabilities)for each person and each item.
Seepredict (CDM).
Examples
############################################################################## EXAMPLE 1: Dichotomous data sim.rasch - predict method#############################################################################data(data.sim.rasch)# 1PL estimationmod1 <- TAM::tam.mml(resp=data.sim.rasch)# predict methodprmod1 <- IRT.predict(mod1, data.sim.rasch)str(prmod1)Classical Test Theory Based Statistics and Plots
Description
The functions computes some item statistics based on classical testtheory.
Usage
tam.ctt(resp, wlescore=NULL, pvscores=NULL, group=NULL, progress=TRUE)tam.ctt2(resp, wlescore=NULL, group=NULL, allocate=30, progress=TRUE)tam.ctt3(resp, wlescore=NULL, group=NULL, allocate=30, progress=TRUE, max_ncat=30, pweights=NULL)tam.cb( dat, wlescore=NULL, group=NULL, max_ncat=30, progress=TRUE, pweights=NULL, digits_freq=5)plotctt( resp, theta, Ncuts=NULL, ask=FALSE, col.list=NULL, package="lattice", ... )Arguments
resp | A data frame with unscored or scored item responses |
wlescore | A vector with person parameter estimates, e.g. weighted likelihoodestimates obtained from |
pvscores | A matrix with plausible values, e.g. obtained from |
group | Vector of group identifiers if descriptive statistics shallbe groupwise calculated |
progress | An optional logical indicating whether computation progressshould be displayed. |
allocate | Average number of categories per item. This argument is justused for matrix size allocations. If an error is produced, usea sufficiently higher number. |
max_ncat | Maximum number of categories of variables for whichfrequency tables should be computed |
pweights | Optional vector of person weights |
dat | Data frame |
digits_freq | Number of digits for rounding in frequency table |
theta | A score to be conditioned |
Ncuts | Number of break points for |
ask | A logical which asks for changing the graphic from item to item.The default is |
col.list | Optional vector of colors for plotting |
package | Package used for plotting. Can be |
... | Further arguments to be passed. |
Details
The functionstam.ctt2 andtam.ctt3 useRcpp codeand are slightly faster.However, onlytam.ctt allows the input ofwlescore andpvscores.
Value
A data frame with following columns:
index | Index variable in this data frame |
group | Group identifier |
itemno | Item number |
item | Item |
N | Number of students responding to this item |
Categ | Category label |
AbsFreq | Absolute frequency of category |
RelFreq | Relative frequency of category |
rpb.WLE | Point biserial correlation of an item category and the WLE |
M.WLE | Mean of the WLE of students in this item category |
SD.WLE | Standard deviation of the WLE of students in this item category |
rpb.PV | Point biserial correlation of an item category and the PV |
M.PV | Mean of the PV of students in this item category |
SD.PV | Standard deviation of the PV of students in this item category |
Note
For dichotomously scored data,rpb.WLE is the ordinary point biserialcorrelation of an item and a test score (here the WLE).
See Also
http://www.edmeasurementsurveys.com/TAM/Tutorials/4CTT.htm
Examples
## Not run: ############################################################################## EXAMPLE 1: Multiple choice data data.mc#############################################################################data(data.mc)# estimate Rasch model for scored data.mc datamod <- TAM::tam.mml( resp=data.mc$scored )# estimate WLEw1 <- TAM::tam.wle( mod )# estimate plausible valuesset.seed(789)p1 <- TAM::tam.pv( mod, ntheta=500, normal.approx=TRUE )$pv# CTT results for raw datastat1 <- TAM::tam.ctt( resp=data.mc$raw, wlescore=w1$theta, pvscores=p1[,-1] )stat1a <- TAM::tam.ctt2( resp=data.mc$raw, wlescore=w1$theta ) # fasterstat1b <- TAM::tam.ctt2( resp=data.mc$raw ) # only frequenciesstat1c <- TAM::tam.ctt3( resp=data.mc$raw, wlescore=w1$theta ) # faster# plot empirical item response curvesplotctt( resp=data.mc$raw, theta=w1$theta, Ncuts=5, ask=TRUE)# use graphics for plotplotctt( resp=data.mc$raw, theta=w1$theta, Ncuts=5, ask=TRUE, package="graphics")# change colorscol.list <- c( "darkred", "darkslateblue", "springgreen4", "darkorange", "hotpink4", "navy" )plotctt( resp=data.mc$raw, theta=w1$theta, Ncuts=5, ask=TRUE, package="graphics", col.list=col.list )# CTT results for scored datastat2 <- TAM::tam.ctt( resp=data.mc$scored, wlescore=w1$theta, pvscores=p1[,-1] )# descriptive statistics for different groups# define group identifiergroup <- c( rep(1,70), rep(2,73) )stat3 <- TAM::tam.ctt( resp=data.mc$raw, wlescore=w1$theta, pvscores=p1[,-1], group=group)stat3a <- TAM::tam.ctt2( resp=data.mc$raw, wlescore=w1$theta, group=group)## End(Not run)Bifactor Model and Exploratory Factor Analysis
Description
Estimates the bifactor model and exploratory factor analysis withmarginal maximum likelihood estimation.
This function is simply a wrapper totam.mml ortam.mml.2pl.
Usage
tam.fa(resp, irtmodel, dims=NULL, nfactors=NULL, pid=NULL, pweights=NULL, verbose=TRUE, control=list(), ...)Arguments
resp | Data frame with polytomous item responses |
irtmodel | A string which defines the IRT model to be estimated. Optionsare |
dims | A numeric or string vector which only applies in case of |
nfactors | A numerical value which indicates the number of factors inexploratory factor analysis. |
pid | An optional vector of person identifiers |
pweights | An optional vector of person weights |
verbose | Logical indicating whether output shouldbe printed during iterations. This argument replaces |
control | See |
... | Further arguments to be passed. These arguments are used in |
Details
The exploratory factor analysis (irtmodel="efa"is estimated using an echelon form of the loading matrix and uncorrelated factors.The obtained standardized loading matrix is rotated using oblimin rotation.In addition, a Schmid-Leimann transformation (see Revelle & Zinbarg, 2009)is employed.
The bifactor model (irtmodel="bifactor2"; Reise 2012)for dichotomous responses is defined as
logit P(X_{pi}=1 | \theta_{pg}, u_{p1}, \ldots, u_{pD} )= a_{i0} \theta_{pg} + a_{i1} u_{pd(i) }
Items load on the general factor\theta_{pg} and a specific (nested)factoru_{pd(i) }. All factors are assumed to be uncorrelated.
In the Rasch testlet model (irtmodel="bifactor1"),all item slopes are set to 1 and variances areestimated.
For polytomous data, the generalized partial credit model is used. The loadingstructure is defined in the same way as for dichotomous data.
Value
The same list entries as intam.mml but in addition thefollowing statistics are included:
B.stand | Standardized factor loadings of the bifactor model or theexploratory factor analysis. |
B.SL | In case of exploratory factor analysis ( |
efa.oblimin | Output from oblimin rotation in exploratoryfactor analysis which is produced by theGPArotation package |
meas | Vector of dimensionality and reliability statistics.Included are the ECV measure (explained common variation;Reise, Moore & Haviland, 2010; Reise, 2012), |
References
Green, S. B., & Yang, Y. (2009). Reliability of summed itemscores using structural equation modeling: An alternative tocoefficient alpha.Psychometrika, 74, 155-167.doi:10.1007/s11336-008-9099-3
Reise, S. P. (2012). The rediscovery of bifactor measurement models.Multivariate Behavioral Research, 47(5), 667-696.doi:10.1080/00273171.2012.715555
Reise, S. P., Moore, T. M., & Haviland, M. G. (2010).Bifactor models and rotations: Exploring the extent to whichmultidimensional data yield univocal scale scores.Journal of Personality Assessment, 92(6), 544-559.doi:10.1080/00223891.2010.496477
Revelle, W., & Zinbarg, R. E. (2009).Coefficients alpha, beta, omega and the glb: Comments on Sijtsma.Psychometrika, 74(1), 145-154.doi:10.1007/s11336-008-9102-z
Wang, W.-C., & Wilson, M. (2005). The Rasch testlet model.Applied Psychological Measurement, 29(2), 126-149.doi:10.1177/0146621604271053
See Also
For more details seetam.mml becausetam.fa is justa wrapper fortam.mml.2pl andtam.mml.
Examples
## Not run: ############################################################################## EXAMPLE 1: Dataset reading from sirt package#############################################################################data(data.read,package="sirt")resp <- data.read#***# Model 1a: Exploratory factor analysis with 2 factorsmod1a <- TAM::tam.fa( resp=resp, irtmodel="efa", nfactors=2 )summary(mod1a)# varimax rotationstats::varimax(mod1a$B.stand)# promax rotationstats::promax(mod1a$B.stand)# more rotations are included in the GPArotation packagelibrary(GPArotation)# geomin rotation obliqueGPArotation::geominQ( mod1a$B.stand )# quartimin rotationGPArotation::quartimin( mod1a$B.stand )#***# Model 1b: Rasch testlet model with 3 testletsdims <- substring( colnames(resp),1,1 ) # define dimensionsmod1b <- TAM::tam.fa( resp=resp, irtmodel="bifactor1", dims=dims )summary(mod1b)#***# Model 1c: Bifactor modelmod1c <- TAM::tam.fa( resp=resp, irtmodel="bifactor2", dims=dims )summary(mod1c)#***# Model 1d: reestimate Model 1c but assume that items 3 and 5 do not load on# specific factorsdims1 <- dimsdims1[c(3,5)] <- NAmod1d <- TAM::tam.fa( resp=resp, irtmodel="bifactor2", dims=dims1 )summary(mod1d)############################################################################## EXAMPLE 2: Polytomous data#############################################################################data(data.timssAusTwn.scored, package="TAM")dat <- data.timssAusTwn.scoredresp <- dat[, grep("M0", colnames(dat))]#***# Model 1a: Rasch testlet model with 2 testletsdims <- c( rep(1,5), rep(2,6))mod1a <- TAM::tam.fa( resp=resp, irtmodel="bifactor1", dims=dims )summary(mod1a)#***# Model 1b: Bifactor modelmod1b <- TAM::tam.fa( resp=resp, irtmodel="bifactor2", dims=dims )summary(mod1b)## End(Not run)Item Infit and Outfit Statistic
Description
The item infit and outfit statistic are calculated forobjects of classestam,tam.mml andtam.jml, respectively.
Usage
tam.fit(tamobj, ...)tam.mml.fit(tamobj, FitMatrix=NULL, Nsimul=NULL,progress=TRUE, useRcpp=TRUE, seed=NA, fit.facets=TRUE)tam.jml.fit(tamobj, trim_val=10)## S3 method for class 'tam.fit'summary(object, file=NULL, ...)Arguments
tamobj | An object of class |
FitMatrix | A fit matrix |
Nsimul | Number of simulations used for fit calculation.The default is 100 (less than 400 students), 40 (less than 1000 students),15 (less than 3000 students) and 5 (more than 3000 students) |
progress | An optional logical indicating whether computation progress shouldbe displayed at console. |
useRcpp | Optional logical indicating whetherRcppor pureR code should be used for fit calculation.The latter is consistent withTAM (<=1.1). |
seed | Fixed simulation seed. |
fit.facets | An optional logical indicating whetherfit for all facet parameters should be computed. |
trim_val | Optional trimming value. Squared standardized reaisualslarger than |
object | Object of class |
file | Optional file name for summary output |
... | Further arguments to be passed |
Value
In case oftam.mml.fit a data frame as entryitemfitwith four columns:
Outfit | Item outfit statistic |
Outfit_t | The |
Outfit_p | Significance |
Outfit_pholm | Significance |
Infit | Item infit statistic |
Infit_t | The |
Infit_p | Significance |
Infit_pholm | Significance |
References
Adams, R. J., & Wu, M. L. (2007). The mixed-coefficients multinomial logit model.A generalized form of the Rasch model. In M. von Davier & C. H. Carstensen (Eds.),Multivariate and mixture distribution Rasch models: Extensions and applications(pp. 55-76). New York: Springer.doi:10.1007/978-0-387-49839-3_4
See Also
Fit statistics can be also calculated by the functionmsq.itemfitwhich avoids simulations and directly evaluates individualposterior distributions.
Seetam.jml.fit for calculating item fit and person fit statisticsfor models fitted with JML.
Seetam.personfit for computing person fit statistics.
Item fit and person fit based on estimated person parameters can also becalculated using thesirt::pcm.fit functionin thesirt package (see Example 1 and Example 2).
Examples
############################################################################## EXAMPLE 1: Dichotomous data data.sim.rasch#############################################################################data(data.sim.rasch)# estimate Rasch modelmod1 <- TAM::tam.mml(resp=data.sim.rasch)# item fitfit1 <- TAM::tam.fit( mod1 )summary(fit1) ## > summary(fit1) ## parameter Outfit Outfit_t Outfit_p Infit Infit_t Infit_p ## 1 I1 0.966 -0.409 0.171 0.996 -0.087 0.233 ## 2 I2 1.044 0.599 0.137 1.029 0.798 0.106 ## 3 I3 1.022 0.330 0.185 1.012 0.366 0.179 ## 4 I4 1.047 0.720 0.118 1.054 1.650 0.025## Not run: #--------# infit and oufit based on estimated WLEslibrary(sirt)# estimate WLEwle <- TAM::tam.wle(mod1)# extract item parametersb1 <- - mod1$AXsi[, -1 ]# assess item fit and person fitfit1a <- sirt::pcm.fit(b=b1, theta=wle$theta, data.sim.rasch )fit1a$item # item fit statisticfit1a$person # person fit statistic############################################################################## EXAMPLE 2: Partial credit model data.gpcm#############################################################################data( data.gpcm )dat <- data.gpcm# estimate partial credit model in ConQuest parametrization 'item+item*step'mod2 <- TAM::tam.mml( resp=dat, irtmodel="PCM2" )summary(mod2)# estimate item fitfit2 <- TAM::tam.fit(mod2)summary(fit2)#=> The first three rows of the data frame correspond to the fit statistics# of first three items Comfort, Work and Benefit.#--------# infit and oufit based on estimated WLEs# compute WLEswle <- TAM::tam.wle(mod2)# extract item parametersb1 <- - mod2$AXsi[, -1 ]# assess fitfit1a <- sirt::pcm.fit(b=b1, theta=wle$theta, dat)fit1a$item############################################################################## EXAMPLE 3: Fit statistic testing for local independence############################################################################## generate data with local dependence and User-defined fit statisticsset.seed(4888)I <- 40 # 40 itemsN <- 1000 # 1000 personsdelta <- seq(-2,2, len=I)theta <- stats::rnorm(N, 0, 1)# simulate dataprob <- stats::plogis(outer(theta, delta, "-"))rand <- matrix( stats::runif(N*I), nrow=N, ncol=I)resp <- 1*(rand < prob)colnames(resp) <- paste("I", 1:I, sep="")#induce some local dependencefor (item in c(10, 20, 30)){ # 20 #are made equal to the previous item row <- round( stats::runif(0.2*N)*N + 0.5) resp[row, item+1] <- resp[row, item]}#run TAMmod1 <- TAM::tam.mml(resp)#User-defined fit design matrixF <- array(0, dim=c(dim(mod1$A)[1], dim(mod1$A)[2], 6))F[,,1] <- mod1$A[,,10] + mod1$A[,,11]F[,,2] <- mod1$A[,,12] + mod1$A[,,13]F[,,3] <- mod1$A[,,20] + mod1$A[,,21]F[,,4] <- mod1$A[,,22] + mod1$A[,,23]F[,,5] <- mod1$A[,,30] + mod1$A[,,31]F[,,6] <- mod1$A[,,32] + mod1$A[,,33]fit <- TAM::tam.fit(mod1, FitMatrix=F)summary(fit)############################################################################## EXAMPLE 4: Fit statistic testing for items with differing slopes##############################################################################*** simulate datalibrary(sirt)set.seed(9875)N <- 2000I <- 20b <- sample( seq( -2, 2, length=I ) )a <- rep( 1, I )# create some misfitting itemsa[c(1,3)] <- c(.5, 1.5 )# simulate datadat <- sirt::sim.raschtype( rnorm(N), b=b, fixed.a=a )#*** estimate Rasch modelmod1 <- TAM::tam.mml(resp=dat)#*** assess item fit by infit and outfit statisticfit1 <- TAM::tam.fit( mod1 )$itemfitround( cbind( "b"=mod1$item$AXsi_.Cat1, fit1$itemfit[,-1] )[1:7,], 3 )#*** compute item fit statistic in mirt packagelibrary(mirt)library(sirt)mod1c <- mirt::mirt( dat, model=1, itemtype="Rasch", verbose=TRUE)print(mod1c) # model summarysirt::mirt.wrapper.coef(mod1c) # estimated parametersfit1c <- mirt::itemfit(mod1c, method="EAP") # model fit in mirt package# compare results of TAM and mirtdfr <- cbind( "TAM"=fit1, "mirt"=fit1c[,-c(1:2)] )# S-X2 item fit statistic (see also the output from mirt)library(CDM)sx2mod1 <- CDM::itemfit.sx2( mod1 )summary(sx2mod1)# compare results of CDM and mirtsx2comp <- cbind( sx2mod1$itemfit.stat[, c("S-X2", "p") ], dfr[, c("mirt.S_X2", "mirt.p.S_X2") ] )round(sx2comp, 3 )## End(Not run)Joint Maximum Likelihood Estimation
Description
This function estimate unidimensionalitem response models with joint maximum likelihood (JML,see e.g. Linacre, 1994).
Usage
tam.jml(resp, group=NULL, adj=.3, disattenuate=FALSE, bias=TRUE, xsi.fixed=NULL, xsi.inits=NULL, theta.fixed=NULL, A=NULL, B=NULL, Q=NULL, ndim=1, pweights=NULL, constraint="cases", theta_proc=NULL, verbose=TRUE, control=list(), version=3)## S3 method for class 'tam.jml'summary(object, file=NULL, ...)## S3 method for class 'tam.jml'logLik(object, ...)Arguments
resp | A matrix of item responses. Missing responses must be declaredas |
group | An optional vector of group identifier |
disattenuate | An optional logical indicating whether the person parametersshould be disattenuated due to unreliability?The disattenuation is conducted by applying the Kelley formula. |
adj | Adjustment constant which is subtracted or added to extremescores (score of zero or maximum score). The default is a value of 0.3 |
bias | A logical which indicates if JML bias should be reducedby multiplying item parameters by the adjustment factorof |
xsi.fixed | An optional matrix with two columns for fixing some of thebasis parameters |
xsi.inits | An optional vector of initial |
theta.fixed | Matrix for fixed person parameters |
A | A design array |
B | A design array for scoring item category responses.Entries in |
Q | A Q-matrix which defines loadings of items on dimensions. |
ndim | Number of dimensions in the model. The default is 1. |
pweights | An optional vector of person weights. |
constraint | Type of constraint for means. Either |
theta_proc | Function for processing |
verbose | Logical indicating whether output shouldbe printed during iterations. This argument replaces |
control | A list of control arguments. See |
version | Version function which should be used. |
object | Object of class |
file | A file name in which the summary output will be written(only for |
... | Further arguments to be passed |
Value
A list with following entries
item1 | Data frame with item parameters |
xsi | Vector of item parameters |
errorP | Standard error of item parameters |
theta | MLE in final step |
errorWLE | Standard error of WLE |
WLE | WLE in last iteration |
WLEreliability | WLE reliability |
PersonScores | Scores for each person (sufficient statistic) |
ItemScore | Sufficient statistic for each item parameter |
PersonMax | Maximum person score |
ItemMax | Maximum item score |
deviance | Deviance |
deviance.history | Deviance history in iterations |
resp | Original data frame |
resp.ind | Response indicator matrix |
group | Vector of group identifiers (if provided as an argument) |
pweights | Vector of person weights |
A | Design matrix |
B | Loading (or scoring) matrix |
nitems | Number of items |
maxK | Maximum number of categories |
nstud | Number of persons in |
resp.ind.list | Like |
xsi.fixed | Fixed |
control | Control list |
item | Extended data frame of item parameters |
theta_summary | Summary of person parameters |
... |
Note
This joint maximum likelihood estimation procedure should becompatible with Winsteps and Facets software, see alsohttp://www.rasch.org/software.htm.
References
Linacre, J. M. (1994).Many-Facet Rasch Measurement.Chicago: MESA Press.
See Also
For estimating the same class of models with marginalmaximum likelihood estimation seetam.mml.
Examples
############################################################################## EXAMPLE 1: Dichotomous data#############################################################################data(data.sim.rasch)resp <- data.sim.rasch[1:700, seq( 1, 40, len=10) ] # subsample# estimate the Rasch model with JML (function 'tam.jml')mod1a <- TAM::tam.jml(resp=resp)summary(mod1a)itemfit <- TAM::tam.fit(mod1a)$fit.item# compare results with Rasch model estimated by MMLmod1b <- TAM::tam.mml(resp=resp )# constrain item difficulties to zeromod1c <- TAM::tam.jml(resp=resp, constraint="items")# plot estimated parametersplot( mod1a$xsi, mod1b$xsi$xsi, pch=16, xlab=expression( paste( xi[i], " (JML)" )), ylab=expression( paste( xi[i], " (MML)" )), main="Item Parameter Estimate Comparison")lines( c(-5,5), c(-5,5), col="gray" )# Now, the adjustment pf .05 instead of the default .3 is used.mod1d <- TAM::tam.jml(resp=resp, adj=.05)# compare item parametersround( rbind( mod1a$xsi, mod1d$xsi ), 3 ) ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## [1,] -2.076 -1.743 -1.217 -0.733 -0.338 0.147 0.593 1.158 1.570 2.091 ## [2,] -2.105 -1.766 -1.233 -0.746 -0.349 0.139 0.587 1.156 1.574 2.108# person parameters for persons with a score 0, 5 and 10pers1 <- data.frame( "score_adj0.3"=mod1a$PersonScore, "theta_adj0.3"=mod1a$theta, "score_adj0.05"=mod1d$PersonScore, "theta_adj0.05"=mod1d$theta )round( pers1[ c(698, 683, 608), ],3 ) ## score_adj0.3 theta_adj0.3 score_adj0.05 theta_adj0.05 ## 698 0.3 -4.404 0.05 -6.283 ## 683 5.0 -0.070 5.00 -0.081 ## 608 9.7 4.315 9.95 6.179## Not run: #*** item fit and person fit statisticsfmod1a <- TAM::tam.jml.fit(mod1a)head(fmod1a$fit.item)head(fmod1a$fit.person)#*** Models in which some item parameters are fixedxsi.fixed <- cbind( c(1,3,9,10), c(-2, -1.2, 1.6, 2 ) )mod1e <- TAM::tam.jml( resp=resp, xsi.fixed=xsi.fixed )summary(mod1e)#*** Model in which also some person parameters theta are fixed# fix theta parameters of persons 2, 3, 4 and 33 to values -2.9, ...theta.fixed <- cbind( c(2,3,4,33), c( -2.9, 4, -2.9, -2.9 ) )mod1g <- TAM::tam.jml( resp=resp, xsi.fixed=xsi.fixed, theta.fixed=theta.fixed )# look at estimated resultsind.person <- c( 1:5, 30:33 )cbind( mod1g$WLE, mod1g$errorWLE )[ind.person,]############################################################################## EXAMPLE 2: Partial credit model#############################################################################data(data.gpcm, package="TAM")dat <- data.gpcm# JML estimationmod2 <- TAM::tam.jml(resp=dat)mod2$xsi # extract item parameterssummary(mod2)TAM::tam.fit(mod2) # item and person infit/outfit statistic#* estimate rating scale modelA <- TAM::designMatrices(resp=dat, modeltype="RSM")$A#* estimate model with design matrix Amod3 <- TAM::tam.jml(dat, A=A)summary(mod3)############################################################################## EXAMPLE 3: Facet model estimation using joint maximum likelihood# data.ex10; see also Example 10 in ?tam.mml#############################################################################data(data.ex10)dat <- data.ex10 ## > head(dat) ## pid rater I0001 I0002 I0003 I0004 I0005 ## 1 1 0 1 1 0 0 ## 1 2 1 1 1 1 0 ## 1 3 1 1 1 0 1 ## 2 2 1 1 1 0 1 ## 2 3 1 1 0 1 1facets <- dat[, "rater", drop=FALSE ] # define facet (rater)pid <- dat$pid # define person identifier (a person occurs multiple times)resp <- dat[, -c(1:2) ] # item response dataformulaA <- ~ item * rater # formula# use MML function only to restructure data and input obtained design matrices# and processed response data to tam.jml (-> therefore use only 2 iterations)mod3a <- TAM::tam.mml.mfr( resp=resp, facets=facets, formulaA=formulaA, pid=dat$pid, control=list(maxiter=2) )# use modified response data mod3a$resp and design matrix mod3a$Aresp1 <- mod3a$resp# JMLmod3b <- TAM::tam.jml( resp=resp1, A=mod3a$A, control=list(maxiter=200) )############################################################################## EXAMPLE 4: Multi faceted model with some anchored item and person parameters#############################################################################data(data.exJ03)resp <- data.exJ03$respX <- data.exJ03$X#*** (0) preprocess data with TAM::tam.mml.mfrmod0 <- TAM::tam.mml.mfr( resp=resp, facets=X, pid=X$rater, formulaA=~ leader + item + step, control=list(maxiter=2) )summary(mod0)#*** (1) estimation with tam.jml (no parameter fixings)# extract processed data and design matrix from tam.mml.mfrresp1 <- mod0$respA1 <- mod0$A# estimate model with tam.jmlmod1 <- TAM::tam.jml( resp=resp1, A=A1, control=list( Msteps=4, maxiter=100 ) )summary(mod1)#*** (2) fix some parameters (persons and items)# look at indices in mod1$xsimod1$xsi# fix step parametersxsi.index1 <- cbind( 21:25, c( -2.44, 0.01, -0.15, 0.01, 1.55 ) )# fix some item parameters of items 1,2,3,6 and 13xsi.index2 <- cbind( c(1,2,3,6,13), c(-2,-1,-1,-1.32, -1 ) )xsi.index <- rbind( xsi.index1, xsi.index2 )# fix some theta parameters of persons 1, 15 and 20theta.fixed <- cbind( c(1,15,20), c(0.4, 1, 0 ) )# estimate model, theta.fixed only works for version=1mod2 <- TAM::tam.jml( resp=resp1, A=A1, xsi.fixed=xsi.fixed, theta.fixed=theta.fixed, control=list( Msteps=4, maxiter=100) )summary(mod2)cbind( mod2$WLE, mod2$errorWLE )############################################################################## EXAMPLE 5: Disconnected item design############################################################################## define a disconnected design with two item sets,# bit random allocation of persons to item setsset.seed(878)ind1 <- 1:1000 # indices persons group 1ind2 <- 1001:3000 # indices persons group 2I <- 10 # number of items# simulate item responsesdat1 <- sirt::sim.raschtype( rnorm( length(ind1)), b=seq(-2,2,len=I) )colnames(dat1) <- paste0("A", 100+1:I)dat2 <- sirt::sim.raschtype( rnorm( length(ind2)), b=seq(-1,3,len=I) )colnames(dat2) <- paste0("B", 100+1:I)# merge datasetsdat <- plyr::rbind.fill(dat1, dat2)summary(dat)# define theta processing functiontheta_proc <- function(theta){ theta[ind1,1] <- theta[ind1,1] - mean( theta[ind1,1] ) theta[ind2,1] <- theta[ind2,1] - mean( theta[ind2,1] ) return(theta)}# JML estimationres <- TAM::tam.jml( dat, theta_proc=theta_proc )# check meansgroup <- c( rep(1,length(ind1)), rep(1,length(ind2)) )stats::aggregate( res$theta, list(group), mean )## End(Not run)Latent Regression Model
Description
This function fits a latent regression model\bold{\theta}=\bold{Y}\bold{\beta} + \bold{\varepsilon}.Only the individual likelihood evaluated at a\bold{\theta} grid is needed as the input. Like intam.mml a multivariate normal distribution is posedon the residual distribution. Plausible values can be drawn by subsequentapplication oftam.pv (see Example 1).
Usage
tam.latreg(like, theta=NULL, Y=NULL, group=NULL, formulaY=NULL, dataY=NULL, beta.fixed=FALSE, beta.inits=NULL, variance.fixed=NULL, variance.inits=NULL, est.variance=TRUE, pweights=NULL, pid=NULL, userfct.variance=NULL, variance.Npars=NULL, verbose=TRUE, control=list())## S3 method for class 'tam.latreg'summary(object,file=NULL,...)## S3 method for class 'tam.latreg'print(x,...)Arguments
like | Individual likelihood. This can be typically extracted from fitteditem response models by making use of |
theta | Used |
Y | A matrix of covariates in latent regression. Note that theintercept is automatically included as the first predictor. |
group | An optional vector of group identifiers |
formulaY | AnR formula for latent regression. Transformations of predictorsin |
dataY | An optional data frame with possible covariates |
beta.fixed | A matrix with three columns for fixing regression coefficients.1st column: Index of |
beta.inits | A matrix (same format as in |
variance.fixed | An optional matrix with three columns for fixingentries in covariance matrix:1st column: dimension 1, 2nd column: dimension 2,3rd column: fixed value |
variance.inits | Initial covariance matrix in estimation. All matrix entries have to bespecified and this matrix is NOT in the same format like |
est.variance | Should the covariance matrix be estimated? This argumentapplies to estimated item slopes in |
pweights | An optional vector of person weights |
pid | An optional vector of person identifiers |
userfct.variance | Optional user customized function for variance specification(See Simulated Example 17). |
variance.Npars | Number of estimated parameters of variance matrixif a |
verbose | Optional logical indicating whether iteration should be displayed. |
control | List of control parameters, see |
object | Object of class |
file | A file name in which the summary output will be written |
x | Object of class |
... | Further arguments to be passed |
Value
Subset of values oftam.mml. In addition,means (M_post) and standard deviations (SD_post) are computed.
See Also
See alsotam.pv for plausible value imputation.
Examples
## Not run: ############################################################################## EXAMPLE 1: Unidimensional latent regression model with fitted IRT model in# the sirt package#############################################################################library(sirt)data(data.pisaRead, package="sirt")dat <- data.pisaRead$dataitems <- grep("R4", colnames(dat), value=TRUE ) # select test items from data# define testletstestlets <- substring( items, 1, 4 )itemcluster <- match( testlets, unique(testlets) )# fit Rasch copula model (only few iterations)mod <- sirt::rasch.copula2( dat[,items], itemcluster=itemcluster, mmliter=5)# extract individual likelihoodlike1 <- IRT.likelihood( mod )# fit latent regression model in TAMY <- dat[, c("migra", "hisei", "female") ]mod2 <- TAM::tam.latreg( like1, theta=attr(like1, "theta"), Y=Y, pid=dat$idstud )summary(mod2)# plausible value imputationpv2 <- TAM::tam.pv( mod2 )# create list of imputed datasetsY <- dat[, c("idstud", "idschool", "female", "hisei", "migra") ]pvnames <- c("PVREAD")datlist <- TAM::tampv2datalist( pv2, pvnames=pvnames, Y=Y, Y.pid="idstud")#--- fit some modelslibrary(mice)library(miceadds)# convert data list into a mice objectmids1 <- miceadds::datalist2mids( datlist )# perform an ANOVAmod3a <- with( mids1, stats::lm(PVREAD ~ hisei*migra) )summary( pool( mod3a ))mod3b <- miceadds::mi.anova( mids1, "PVREAD ~ hisei*migra" )############################################################################## EXAMPLE 2: data.pisaRead - fitted IRT model in mirt package#############################################################################library(sirt)library(mirt)data(data.pisaRead, package="sirt")dat <- data.pisaRead$data# define dataset with item responsesitems <- grep("R4", colnames(dat), value=TRUE )resp <- dat[,items]# define dataset with covariatesX <- dat[, c("female","hisei","migra") ]# fit 2PL model in mirtmod <- mirt::mirt( resp, 1, itemtype="2PL", verbose=TRUE)print(mod)# extract coefficientssirt::mirt.wrapper.coef(mod)# extract likelihoodlike <- IRT.likelihood(mod)str(like)# fit latent regression model in TAMmod2 <- TAM::tam.latreg( like, Y=X, pid=dat$idstud )summary(mod2)# plausible value imputationpv2 <- TAM::tam.pv( mod2, samp.regr=TRUE, nplausible=5 )# create list of imputed datasetsX <- dat[, c("idstud", "idschool", "female", "hisei", "migra") ]pvnames <- c("PVREAD")datlist <- TAM::tampv2datalist( pv2, pvnames=pvnames, Y=X, Y.pid="idstud")str(datlist)# regression using semTools packagelibrary(semTools)lavmodel <- " PVREAD ~ hisei + female "mod1a <- semTools::sem.mi( lavmodel, datlist)summary(mod1a, standardized=TRUE, rsquare=TRUE)############################################################################## EXAMPLE 3: data.Students - fitted confirmatory factor analysis in lavaan#############################################################################library(CDM)library(sirt)library(lavaan)data(data.Students, package="CDM")dat <- data.Studentsvars <- scan(what="character", nlines=1) urban female sc1 sc2 sc3 sc4 mj1 mj2 mj3 mj4dat <- dat[, vars]dat <- na.omit(dat)# fit confirmatory factor analysis in lavaanlavmodel <- " SC=~ sc1__sc4 SC ~~ 1*SC MJ=~ mj1__mj4 MJ ~~ 1*MJ SC ~~ MJ "# process lavaan syntaxres <- TAM::lavaanify.IRT( lavmodel, dat )# fit lavaan CFA modelmod1 <- lavaan::cfa( res$lavaan.syntax, dat, std.lv=TRUE)summary(mod1, standardized=TRUE, fit.measures=TRUE )# extract likelihoodlike1 <- TAM::IRTLikelihood.cfa( dat, mod1 )str(like1)# fit latent regression model in TAMX <- dat[, c("urban","female") ]mod2 <- TAM::tam.latreg( like1, Y=X )summary(mod2)# plausible value imputationpv2 <- TAM::tam.pv( mod2, samp.regr=TRUE, normal.approx=TRUE )# create list of imputed datasetsY <- dat[, c("urban", "female" ) ]pvnames <- c("PVSC", "PVMJ")datlist <- TAM::tampv2datalist( pv2, pvnames=pvnames, Y=Y )str(datlist)## End(Not run)Linking of Fitted Unidimensional Item Response Models inTAM
Description
Performs linking of fitted unidimensional item response models inTAMaccording to the Stocking-Lord and the Haebara method (Kolen & Brennan, 2014;Gonzales & Wiberg, 2017).Several studies can either be linked by a chain of linkings of two studies(method="chain") or a joint linking approach (method="joint")comprising all pairwise linkings.
The linking of two studies is implemented in thetam_linking_2studies function.
Usage
tam.linking(tamobj_list, type="Hae", method="joint", pow_rob_hae=1, eps_rob_hae=1e-4, theta=NULL, wgt=NULL, wgt_sd=2, fix.slope=FALSE, elim_items=NULL, par_init=NULL, verbose=TRUE)## S3 method for class 'tam.linking'summary(object, file=NULL, ...)## S3 method for class 'tam.linking'print(x, ...)tam_linking_2studies( B1, AXsi1, guess1, B2, AXsi2, guess2, theta, wgt, type, M1=0, SD1=1, M2=0, SD2=1, fix.slope=FALSE, pow_rob_hae=1, eps_rob_hae=1e-4)## S3 method for class 'tam_linking_2studies'summary(object, file=NULL, ...)## S3 method for class 'tam_linking_2studies'print(x, ...)Arguments
tamobj_list | List of fitted objects inTAM |
type | Type of linking method: |
method | Chain linking ( |
pow_rob_hae | Power for robust Heabara linking. The value must be largerthan 0 or equal to 0. |
eps_rob_hae | Value |
theta | Grid of |
wgt | Weights defined for the |
wgt_sd | Standard deviation for |
fix.slope | Logical indicating whether the slope transformation constant is fixed to 1. |
elim_items | List of vectors refering to items which should be removedfrom linking (see Model 'lmod2' in Example 1) |
par_init | Optional vector with initial parameter values |
verbose | Logical indicating progress of linking computation |
object | Object of class |
x | Object of class |
file | A file name in which the summary output will be written |
... | Further arguments to be passed |
B1 | Array |
AXsi1 | Matrix |
guess1 | Guessing parameter for first study |
B2 | Array |
AXsi2 | Matrix |
guess2 | Guessing parameter for second study |
M1 | Mean of first study |
SD1 | Standard deviation of first study |
M2 | Mean of second study |
SD2 | Standard deviation of second study |
Details
The Haebara linking is defined by minimizing the loss function
\sum_i \sum_k \int \left ( P_{ik} ( \theta ) - P_{ik}^\ast ( \theta ) \right )^2
A robustification of Haebara linking minimizes the loss function
\sum_i \sum_k \int \left ( P_{ik} ( \theta ) - P_{ik}^\ast ( \theta ) \right )^p
with a powerp (defined inpow_rob_hae) smaller than 2. He, Cui andOsterlind (2015) considerp=1.
Value
List containing entries
parameters_list | List containing transformed item parameters |
linking_list | List containing results of each linking in thelinking chain |
M_SD | Mean and standard deviation for each study after linking |
trafo_items | Transformation constants for item parameters |
trafo_persons | Transformation constants for person parameters |
References
Battauz, M. (2015).equateIRT: AnR package for IRT test equating.Journal of Statistical Software, 68(7), 1-22.doi:10.18637/jss.v068.i07
Gonzalez, J., & Wiberg, M. (2017).Applying test equating methods: UsingR. New York, Springer.doi:10.1007/978-3-319-51824-4
He, Y., Cui, Z., & Osterlind, S. J. (2015). New robust scale transformation methods in thepresence of outlying common items.Applied Psychological Measurement, 39(8), 613-626.doi:10.1177/0146621615587003
Kolen, M. J., & Brennan, R. L. (2014).Test equating, scaling, and linking:Methods and practices. New York, Springer.doi:10.1007/978-1-4939-0317-7
Weeks, J. P. (2010).plink: AnR package for linking mixed-format testsusing IRT-based methods.Journal of Statistical Software, 35(12), 1-33.doi:10.18637/jss.v035.i12
See Also
Linking or equating of item response models can be also conducted withplink(Weeks, 2010),equate,equateIRT (Battauz, 2015),equateMultiple,kequate andirteQ packages.
See also thesirt::linking.haberman,sirt::invariance.alignment andsirt::linking.haebara functionsin thesirt package.
Examples
## Not run: ############################################################################## EXAMPLE 1: Linking dichotomous data with the 2PL model#############################################################################data(data.ex16)dat <- data.ex16items <- colnames(dat)[-c(1,2)]# fit grade 1rdat1 <- TAM::tam_remove_missings( dat[ dat$grade==1, ], items=items )mod1 <- TAM::tam.mml.2pl( resp=rdat1$resp[, rdat1$items], pid=rdat1$dat$idstud )summary(mod1)# fit grade 2rdat2 <- TAM::tam_remove_missings( dat[ dat$grade==2, ], items=items )mod2 <- TAM::tam.mml.2pl( resp=rdat2$resp[, rdat2$items], pid=rdat2$dat$idstud )summary(mod2)# fit grade 3rdat3 <- TAM::tam_remove_missings( dat[ dat$grade==3, ], items=items )mod3 <- TAM::tam.mml.2pl( resp=rdat3$resp[, rdat3$items], pid=rdat3$dat$idstud )summary(mod3)# define list of fitted modelstamobj_list <- list( mod1, mod2, mod3 )#-- link item response modelslmod <- TAM::tam.linking( tamobj_list)summary(lmod)# estimate WLEs based on transformed item parametersparm_list <- lmod$parameters_list# WLE grade 1arglist <- list( resp=mod1$resp, B=parm_list[[1]]$B, AXsi=parm_list[[1]]$AXsi )wle1 <- TAM::tam.mml.wle(tamobj=arglist)# WLE grade 2arglist <- list( resp=mod2$resp, B=parm_list[[2]]$B, AXsi=parm_list[[2]]$AXsi )wle2 <- TAM::tam.mml.wle(tamobj=arglist)# WLE grade 3arglist <- list( resp=mod3$resp, B=parm_list[[3]]$B, AXsi=parm_list[[3]]$AXsi )wle3 <- TAM::tam.mml.wle(tamobj=arglist)# compare result with chain linkinglmod1b <- TAM::tam.linking(tamobj_list)summary(lmod1b)#-- linking with some eliminated items# remove three items from first group and two items from third groupelim_items <- list( c("A1", "E2","F1"), NULL, c("F1","F2") )lmod2 <- TAM::tam.linking(tamobj_list, elim_items=elim_items)summary(lmod2)#-- Robust Haebara linking with p=1lmod3a <- TAM::tam.linking(tamobj_list, type="RobHae", pow_rob_hae=1)summary(lmod3a)#-- Robust Haeabara linking with initial parameters and prespecified epsilon valuepar_init <- lmod3a$parlmod3b <- TAM::tam.linking(tamobj_list, type="RobHae", pow_rob_hae=.1, eps_rob_hae=1e-3, par_init=par_init)summary(lmod3b)############################################################################## EXAMPLE 2: Linking polytomous data with the partial credit model#############################################################################data(data.ex17)dat <- data.ex17items <- colnames(dat)[-c(1,2)]# fit grade 1rdat1 <- TAM::tam_remove_missings( dat[ dat$grade==1, ], items=items )mod1 <- TAM::tam.mml.2pl( resp=rdat1$resp[, rdat1$items], pid=rdat1$dat$idstud )summary(mod1)# fit grade 2rdat2 <- TAM::tam_remove_missings( dat[ dat$grade==2, ], items=items )mod2 <- TAM::tam.mml.2pl( resp=rdat2$resp[, rdat2$items], pid=rdat2$dat$idstud )summary(mod2)# fit grade 3rdat3 <- TAM::tam_remove_missings( dat[ dat$grade==3, ], items=items )mod3 <- TAM::tam.mml.2pl( resp=rdat3$resp[, rdat3$items], pid=rdat3$dat$idstud )summary(mod3)# list of fitted TAM modelstamobj_list <- list( mod1, mod2, mod3 )#-- linking: fix slope because partial credit model is fittedlmod <- TAM::tam.linking( tamobj_list, fix.slope=TRUE)summary(lmod)# WLEs can be estimated in the same way as in Example 1.############################################################################## EXAMPLE 3: Linking dichotomous data with the multiple group 2PL models#############################################################################data(data.ex16)dat <- data.ex16items <- colnames(dat)[-c(1,2)]# fit grade 1rdat1 <- TAM::tam_remove_missings( dat[ dat$grade==1, ], items=items )# create some grouping variablegroup <- ( seq( 1, nrow( rdat1$dat ) ) %% 3 ) + 1mod1 <- TAM::tam.mml.2pl( resp=rdat1$resp[, rdat1$items], pid=rdat1$dat$idstud, group=group)summary(mod1)# fit grade 2rdat2 <- TAM::tam_remove_missings( dat[ dat$grade==2, ], items=items )group <- 1*(rdat2$dat$dat$idstud > 500)mod2 <- TAM::tam.mml.2pl( resp=rdat2$resp[, rdat2$items], pid=rdat2$dat$dat$idstud, group=group)summary(mod2)# fit grade 3rdat3 <- TAM::tam_remove_missings( dat[ dat$grade==3, ], items=items )mod3 <- TAM::tam.mml.2pl( resp=rdat3$resp[, rdat3$items], pid=rdat3$dat$idstud )summary(mod3)# define list of fitted modelstamobj_list <- list( mod1, mod2, mod3 )#-- link item response modelslmod <- TAM::tam.linking( tamobj_list)############################################################################## EXAMPLE 4: Linking simulated dichotomous data with two groups#############################################################################library(sirt)#*** simulate dataN <- 3000 # number of personsI <- 30 # number of itemsb <- seq(-2,2, length=I)# data for group 1dat1 <- sirt::sim.raschtype( rnorm(N, mean=0, sd=1), b=b )# data for group 2dat2 <- sirt::sim.raschtype( rnorm(N, mean=1, sd=.6), b=b )# fit group 1mod1 <- TAM::tam.mml.2pl( resp=dat1 )summary(mod1)# fit group 2mod2 <- TAM::tam.mml.2pl( resp=dat2 )summary(mod2)# define list of fitted modelstamobj_list <- list( mod1, mod2 )#-- link item response modelslmod <- TAM::tam.linking( tamobj_list)summary(lmod)# estimate WLEs based on transformed item parametersparm_list <- lmod$parameters_list# WLE grade 1arglist <- list( resp=mod1$resp, B=parm_list[[1]]$B, AXsi=parm_list[[1]]$AXsi )wle1 <- TAM::tam.mml.wle(tamobj=arglist)# WLE grade 2arglist <- list( resp=mod2$resp, B=parm_list[[2]]$B, AXsi=parm_list[[2]]$AXsi )wle2 <- TAM::tam.mml.wle(tamobj=arglist)summary(wle1)summary(wle2)# estimation with linked and fixed item parameters for group 2B <- parm_list[[2]]$Bxsi.fixed <- cbind( 1:I, -parm_list[[2]]$AXsi[,2] )mod2f <- TAM::tam.mml( resp=dat2, B=B, xsi.fixed=xsi.fixed )summary(mod2f)## End(Not run)Test Analysis Modules: Marginal Maximum Likelihood Estimation
Description
Modules for psychometric test analysis demonstratedwith the help of artificial example data.The package includes MML and JML estimation ofuni- and multidimensional IRT (Rasch, 2PL, Generalized PartialCredit, Rating Scale, Multi Facets, Nominal Item Response)models, fit statistic computation, standard error estimation, aswell as plausible value imputation and weighted likelihoodestimation of ability.
Usage
tam(resp, irtmodel="1PL", formulaA=NULL, ...)tam.mml(resp, Y=NULL, group=NULL, irtmodel="1PL", formulaY=NULL, dataY=NULL, ndim=1, pid=NULL, xsi.fixed=NULL, xsi.inits=NULL, beta.fixed=NULL, beta.inits=NULL, variance.fixed=NULL, variance.inits=NULL, est.variance=TRUE, constraint="cases", A=NULL, B=NULL, B.fixed=NULL, Q=NULL, est.slopegroups=NULL, E=NULL, pweights=NULL, userfct.variance=NULL, variance.Npars=NULL, item.elim=TRUE, verbose=TRUE, control=list() )tam.mml.2pl(resp, Y=NULL, group=NULL, irtmodel="2PL", formulaY=NULL, dataY=NULL, ndim=1, pid=NULL, xsi.fixed=NULL, xsi.inits=NULL, beta.fixed=NULL, beta.inits=NULL, variance.fixed=NULL, variance.inits=NULL, est.variance=FALSE, A=NULL, B=NULL, B.fixed=NULL, Q=NULL, est.slopegroups=NULL, E=NULL, gamma.init=NULL, pweights=NULL, userfct.variance=NULL, variance.Npars=NULL, item.elim=TRUE, verbose=TRUE, control=list() )tam.mml.mfr(resp, Y=NULL, group=NULL, irtmodel="1PL", formulaY=NULL, dataY=NULL, ndim=1, pid=NULL, xsi.fixed=NULL, xsi.setnull=NULL, xsi.inits=NULL, beta.fixed=NULL, beta.inits=NULL, variance.fixed=NULL, variance.inits=NULL, est.variance=TRUE, formulaA=~item+item:step, constraint="cases", A=NULL, B=NULL, B.fixed=NULL, Q=NULL, facets=NULL, est.slopegroups=NULL, E=NULL, pweights=NULL, verbose=TRUE, control=list(), delete.red.items=TRUE )## S3 method for class 'tam'summary(object, file=NULL, ...)## S3 method for class 'tam.mml'summary(object, file=NULL, ...)## S3 method for class 'tam'print(x, ...)## S3 method for class 'tam.mml'print(x, ...)Arguments
resp | Data frame with polytomous item responses |
Y | A matrix of covariates in latent regression. Note that theintercept is automatically included as the first predictor. |
group | An optional vector of group identifiers |
irtmodel | For fixed item slopes (in |
formulaY | AnR formula for latent regression. Transformations of predictorsin |
dataY | An optional data frame with possible covariates |
ndim | Number of dimensions (is not needed to determined by the user) |
pid | An optional vector of person identifiers |
xsi.fixed | A matrix with two columns for fixing |
xsi.setnull | A vector of strings indicating which |
xsi.inits | A matrix with two columns (in the same way defined as in |
beta.fixed | A matrix with three columns for fixing regression coefficients.1st column: Index of |
beta.inits | A matrix (same format as in |
variance.fixed | An optional matrix with three columns for fixingentries in covariance matrix:1st column: dimension 1, 2nd column: dimension 2,3rd column: fixed value |
variance.inits | Initial covariance matrix in estimation. All matrix entries have to bespecified and this matrix is NOT in the same format like |
est.variance | Should the covariance matrix be estimated? This argumentapplies to estimated item slopes in |
constraint | Set sum constraint for parameter identificationfor |
A | An optional array of dimension |
B | An optional array of dimension |
B.fixed | An optional matrix with four columns for fixing |
Q | An optional |
est.slopegroups | A vector of integers of length |
E | An optional design matrix for estimating item slopesin the generalized partial credit model ( |
gamma.init | Optional initial |
pweights | An optional vector of person weights |
formulaA | Design formula (only applies to |
facets | A data frame with facet entries (only applies to |
userfct.variance | Optional user customized function for variance specification(See Simulated Example 17). |
variance.Npars | Number of estimated parameters of variance matrixif a |
item.elim | Optional logical indicating whether an item with hasonly zero entries should be removed from the analysis. The defaultis |
verbose | Logical indicating whether output shouldbe printed during iterations. This argument replaces |
control | A list of control arguments for the algorithm:
|
delete.red.items | An optional logical indicating whether redundantgeneralized items (with no observations) should be eliminated. |
object | Object of class |
file | A file name in which the summary output should be written(only for |
... | Further arguments to be passed |
x | Object of class |
Details
The multidimensional item response model inTAM isdescribed in Adams, Wilson and Wu (1997) or Adams and Wu (2007).
The data frameresp contains item responses ofN persons (in rows)atI items (in columns), each item having at mostK categoriesk=0,...,K.The item response model hasD dimensions of the\theta abilityvector and can be written as
P( X_{pi}=k | \theta_p ) \propto exp( b_{ik} \theta_p + a_{ik} \xi )
The symbol\propto means that response probabilities are normalized suchthat \sum _k P( X_{pi}=k | \theta_p )=1.
Item category thresholds for itemi in categorykare written as a linear combinationa_i \xi where the vector\xi of lengthN_\xicontains generalized item parameters andA=( a_{ik} )_{ik}=( a_i )_{i} isa three-dimensional design array (specified inA).
The scoring vectorb_{ik} contains the fixed (intam.mml)or estimated (intam.mml.2pl) scores of itemi in categorykon dimensiond.
Fortam.mml.2pl andirtmodel="GPCM.design", item slopesa_ican be written as a linear combinationa_i=( E \gamma)_iof basis item slopes which is an analogueof the LLTM for item slopes (see Example 7; Embretson, 1999).
The latent regression model regresses the latent trait\theta_pon covariatesY which results in
\theta_p=Y \beta + \epsilon_p, \epsilon_p \sim N_D ( 0, \Sigma )
Where\beta is aN_Y timesD matrix of regressioncoefficients forN_Y covariates inY.
The multiple group model for groupsg=1,...,G is implemented for unidimensional and multidimensional itemresponse models. In this case, variance heterogeneity is allowed
\theta_p=Y \beta + \epsilon_p, \epsilon_p \sim N ( 0, \sigma_g^2 )
Integration: Uni- and multidimensional integrals are approximated byposing a uni- or multivariate normality assumption. The default is Gaussianquadrature with nodes defined incontrol$nodes. ForD-dimensionalIRT models, theD-dimensional cube consisting of the vectorcontrol$nodes in all dimensions is used. If the user specifiescontrol$snodes with a value larger than zero, then Quasi-Monte Carlointegration (Pan & Thomas, 2007; Gonzales et al., 2006) withcontrol$snodes is used(becausecontrol$QMC=TRUE is set by default). Ifcontrol$QMC=FALSE is specified, then stochastic (Monte Carlo) integrationis employed withcontrol$snodes stochastic nodes.
Value
A list with following entries:
xsi | Vector of |
xsi.facets | Data frame of |
beta | Matrix of |
variance | Covariance matrix. In case of multiple groups,it is a vector indicating heteroscedastic variances |
item | Data frame with item parameters. The column |
item_irt | IRT parameterization of item parameters |
person | Matrix with person parameter estimates. |
pid | Vector of person identifiers |
EAP.rel | EAP reliability |
post | Posterior distribution for item response pattern |
rprobs | A three-dimensional array with estimated response probabilities(dimensions are items |
itemweight | Matrix of item weights |
theta | Theta grid |
n.ik | Array of expected counts: theta class |
pi.k | Marginal trait distribution at grid |
Y | Matrix of covariates |
resp | Original data frame |
resp.ind | Response indicator matrix |
group | Group identifier |
G | Number of groups |
formulaY | Formula for latent regression |
dataY | Data frame for latent regression |
pweights | Person weights |
time | Computation time |
A | Design matrix |
B | Fixed or estimated loading matrix |
se.B | Standard errors of |
nitems | Number of items |
maxK | Maximum number of categories |
AXsi | Estimated item intercepts |
AXsi_ | Estimated item intercepts - |
se.AXsi | Standard errors of |
nstud | Number of persons |
resp.ind.list | List of response indicator vectors |
hwt | Individual posterior distribution |
like | Individual likelihood |
ndim | Number of dimensions |
xsi.fixed | Fixed |
xsi.fixed.estimated | Matrix of estimated |
B.fixed | Fixed loading parameters (only applies to |
B.fixed.estimated | Matrix of estimated |
est.slopegroups | An index vector of item groups of common slopeparameters (only applies to |
E | Design matrix for estimated item slopes in the generalized partialcredit model (only applies to |
basispar | Vector of |
formulaA | Design formula (only applies to |
facets | Data frame with facet entries (only applies to |
variance.fixed | Fixed covariance matrix |
nnodes | Number of theta nodes |
deviance | Final deviance |
ic | Vector with information criteria |
deviance.history | Deviance history in iterations |
control | List of control arguments |
latreg_stand | List containing standardized regression coefficients |
... | Further values |
Note
For more than three dimensions, quasi-Monte Carlo or stochastic integrationis recommended because otherwise problems in memory allocation and largecomputation time will result. Choose incontrol a suitable value ofthe number of quasi Monte Carlo or stochastic nodessnodes(say, larger than 1000). See Pan and Thompson (2007) or Gonzales et al. (2006)for more details.
In faceted models (tam.mml.mfr), parameters which cannot be estimatedare fixed to99.
Several choices can be made if your model does not converge. First, the numberof iterations within a M step can be increased (Msteps=10).Second, the absolute value of increments can be forced with increasingiterations (set a value higher than 1 tomax.increment, maybe 1.05).Third, change in estimated parameters can be stabilized byfac.oldxsi forwhich a value of 0 (the default) and a value of 1 can be chosen. We recommendvalues between .5 and .8 if your model does not converge.
References
Adams, R. J., Wilson, M., & Wu, M. (1997).Multilevel item response models: An approach to errors invariables regression.Journal of Educational and BehavioralStatistics, 22, 47-76.doi:10.3102/10769986022001047
Adams, R. J., & Wu, M. L. (2007). The mixed-coefficients multinomial logit model.A generalized form of the Rasch model. In M. von Davier & C. H. Carstensen (Eds.),Multivariate and mixture distribution Rasch models: Extensions and applications(pp. 55-76). New York: Springer.doi:10.1007/978-0-387-49839-3_4
Embretson, S. E. (1999). Generating items during testing:Psychometric issues and models.Psychometrika, 64, 407-433.doi:10.1007/BF02294564
Gonzalez, J., Tuerlinckx, F., De Boeck, P., & Cools, R. (2006).Numerical integration in logistic-normal models.Computational Statistics & Data Analysis, 51, 1535-1548.doi:10.1016/j.csda.2006.05.003
Pan, J., & Thompson, R. (2007). Quasi-Monte Carlo estimation ingeneralized linear mixed models.Computational Statistics &Data Analysis, 51, 5765-5775.doi:10.1016/j.csda.2006.10.003
Ramsay, J. O. (1975). Solving implicit equations in psychometric data analysis.Psychometrika, 40(3), 337-360.doi:10.1007/BF02291762
Yu, Y. (2012). Monotonically overrelaxed EM algorithms.Journal of Computational and Graphical Statistics, 21(2), 518-537.doi:10.1080/10618600.2012.672115
Wu, M. L., Adams, R. J., Wilson, M. R. & Haldane, S. (2007).ACER ConQuest Version 2.0. Mulgrave.https://shop.acer.edu.au/acer-shop/group/CON3.
See Also
Seedata.cqc01 for more examples which is are similar to the onesin the ConQuest manual (Wu, Adams, Wilson & Haldane, 2007).
Seetam.jml for joint maximum likelihood estimation.
Standard errors are estimated by a rather crude (but quick) approximation.Usetam.se for improved standard errors.
For model comparisons seeanova.tam.
Seesirt::tam2mirt for convertingtam objects into objects of classmirt::mirt in themirt package.
Examples
############################################################################## EXAMPLE 1: dichotomous data# data.sim.rasch: 2000 persons, 40 items#############################################################################data(data.sim.rasch)#************************************************************# Model 1: Rasch model (MML estimation)mod1 <- TAM::tam.mml(resp=data.sim.rasch)# extract item parametersmod1$item # item difficulties## Not run: # WLE estimationwle1 <- TAM::tam.wle( mod1 )# item fitfit1 <- TAM::tam.fit(mod1)# plausible value imputationpv1 <- TAM::tam.pv(mod1, normal.approx=TRUE, ntheta=300)# standard errorsse1 <- TAM::tam.se( mod1 )# summarysummary(mod1)#-- specification with tamaantammodel <- " LAVAAN MODEL: F=~ I1__I40; F ~~ F ITEM TYPE: ALL(Rasch) "mod1t <- TAM::tamaan( tammodel, data.sim.rasch)summary(mod1t)#************************************************************# Model 1a: Rasch model with fixed item difficulties from 'mod1'xsi0 <- mod1$xsi$xsixsi.fixed <- cbind( 1:(length(xsi0)), xsi0 ) # define vector with fixed item difficultiesmod1a <- TAM::tam.mml( resp=data.sim.rasch, xsi.fixed=xsi.fixed )summary(mod1a)# Usage of the output value mod1$xsi.fixed.estimated has the right format# as the input of xsi.fixedmod1aa <- TAM::tam.mml( resp=data.sim.rasch, xsi.fixed=mod1$xsi.fixed.estimated )summary(mod1b)#************************************************************# Model 1b: Rasch model with initial xsi parameters for items 2 (item difficulty b=-1.8),# item 4 (b=-1.6) and item 40 (b=2)xsi.inits <- cbind( c(2,4,40), c(-1.8,-1.6,2))mod1b <- TAM::tam.mml( resp=data.sim.rasch, xsi.inits=xsi.inits )#-- tamaan specificationtammodel <- " LAVAAN MODEL: F=~ I1__I40 F ~~ F # Fix item difficulties. Note that item intercepts instead of difficulties # must be specified. I2 | 1.8*t1 I4 | 1.6*t1 ITEM TYPE: ALL(Rasch) "mod1bt <- TAM::tamaan( tammodel, data.sim.rasch)summary(mod1bt)#************************************************************# Model 1c: 1PL estimation with sum constraint on item difficultiesdat <- data.sim.rasch# modify A design matrix to include the sum constraintdes <- TAM::designMatrices(resp=dat)A1 <- des$A[,, - ncol(dat) ]A1[ ncol(dat),2, ] <- 1A1[,2,]# estimate modelmod1c <- TAM::tam.mml( resp=dat, A=A1, beta.fixed=FALSE, control=list(fac.oldxsi=.1) )summary(mod1c)#************************************************************# Model 1d: estimate constraint='items' using tam.mml.mfrformulaA=~ 0 + itemmod1d <- TAM::tam.mml.mfr( resp=dat, formulaA=formulaA, control=list(fac.oldxsi=.1), constraint="items")summary(mod1d)#************************************************************# Model 1e: This sum constraint can also be obtained by using the argument# constraint="items" in tam.mmlmod1e <- TAM::tam.mml( resp=data.sim.rasch, constraint="items" )summary(mod1e)#************************************************************# Model 1d2: estimate constraint='items' using tam.mml.mfr# long format response dataresp.long <- c(dat)# pid and item facet specifications are necessary# Note, that we recommend the facet labels to be sortable in the same order that the# results are desired.# compare to: facets <- data.frame( "item"=rep(colnames(dat), each=nrow(dat)) )pid <- rep(1:nrow(dat), ncol(dat))itemnames <- paste0("I", sprintf(paste('%0', max(nchar(1:ncol(dat))), 'i', sep='' ), c(1:ncol(dat)) ) )facets <- data.frame( "item_"=rep(itemnames, each=nrow(dat)) )formulaA=~ 0 + item_mod1d2 <- TAM::tam.mml.mfr( resp=resp.long, formulaA=formulaA, control=list(fac.oldxsi=.1), constraint="items", facets=facets, pid=pid)stopifnot( all(mod1d$xsi.facets$xsi==mod1d2$xsi.facets$xsi) )## End(Not run)#************************************************************# Model 2: 2PL modelmod2 <- TAM::tam.mml.2pl(resp=data.sim.rasch,irtmodel="2PL")# extract item parametersmod2$xsi # item difficultiesmod2$B # item slopes#--- tamaan specificationtammodel <- " LAVAAN MODEL: F=~ I1__I40 F ~~ 1*F # item type of 2PL is the default for dichotomous data "# estimate modelmod2t <- TAM::tamaan( tammodel, data.sim.rasch)summary(mod2t)## Not run: #************************************************************# Model 2a: 2PL with fixed item difficulties and slopes from 'mod2'xsi0 <- mod2$xsi$xsixsi.fixed <- cbind( 1:(length(xsi0)), xsi0 ) # define vector with fixed item difficultiesmod2a <- TAM::tam.mml( resp=data.sim.rasch, xsi.fixed=xsi.fixed, B=mod2$B # fix slopes )summary(mod2a)mod2a$B # inspect used slope matrix#************************************************************# Model 3: constrained 2PL estimation# estimate item parameters in different slope groups# items 1-10, 21-30 group 1# items 11-20 group 2 and items 31-40 group 3est.slope <- rep(1,40)est.slope[ 11:20 ] <- 2est.slope[ 31:40 ] <- 3mod3 <- TAM::tam.mml.2pl( resp=data.sim.rasch, irtmodel="2PL.groups", est.slopegroups=est.slope )mod3$Bsummary(mod3)#--- tamaan specification (A)tammodel <- " LAVAAN MODEL: F=~ lam1*I1__I10 + lam2*I11__I20 + lam1*I21__I30 + lam3*I31__I40; F ~~ 1*F "# estimate modelmod3tA <- TAM::tamaan( tammodel, data.sim.rasch)summary(mod3tA)#--- tamaan specification (alternative B)tammodel <- " LAVAAN MODEL: F=~ a1__a40*I1__I40; F ~~ 1*F MODEL CONSTRAINT: a1__a10==lam1 a11__a20==lam2 a21__a30==lam1 a31__a40==lam3 "mod3tB <- TAM::tamaan( tammodel, data.sim.rasch)summary(mod3tB)#--- tamaan specification (alternative C using DO operator)tammodel <- " LAVAAN MODEL: DO(1,10,1) F=~ lam1*I% DOEND DO(11,20,1) F=~ lam2*I% DOEND DO(21,30,1) F=~ lam1*I% DOEND DO(31,40,1) F=~ lam3*I% DOEND F ~~ 1*F "# estimate modelmod3tC <- TAM::tamaan( tammodel, data.sim.rasch)summary(mod3tC)############################################################################## EXAMPLE 2: Unidimensional calibration with latent regressors############################################################################## (1) simulate dataset.seed(6778) # set simulation seedN <- 2000 # number of persons# latent regressors YY <- cbind( stats::rnorm( N, sd=1.5), stats::rnorm(N, sd=.3 ) )# simulate thetatheta <- stats::rnorm( N ) + .4 * Y[,1] + .2 * Y[,2] # latent regression model# number of itemsI <- 40p1 <- stats::plogis( outer( theta, seq( -2, 2, len=I ), "-" ) )# simulate response matrixresp <- 1 * ( p1 > matrix( stats::runif( N*I ), nrow=N, ncol=I ) )colnames(resp) <- paste("I", 1:I, sep="")# (2) estimate modelmod2_1 <- TAM::tam.mml(resp=resp, Y=Y)summary(mod2_1)# (3) setting initial values for beta coefficients# beta_2=.20, beta_3=.35 for dimension 1beta.inits <- cbind( c(2,3), 1, c(.2, .35 ) )mod2_2 <- TAM::tam.mml(resp=resp, Y=Y, beta.inits=beta.inits)# (4) fix intercept to zero and third coefficient to .3beta.fixed <- cbind( c(1,3), 1, c(0, .3 ) )mod2_3 <- TAM::tam.mml(resp=resp, Y=Y, beta.fixed=beta.fixed )# (5) same model but with R regression formula for YdataY <- data.frame(Y)colnames(dataY) <- c("Y1","Y2")mod2_4 <- TAM::tam.mml(resp=resp, dataY=dataY, formulaY=~ Y1+Y2 )summary(mod2_4)# (6) model with interaction of regressorsmod2_5 <- TAM::tam.mml(resp=resp, dataY=dataY, formulaY=~ Y1*Y2 )summary(mod2_5)# (7) no constraint on regressors (removing constraint from intercept)mod2_6 <- TAM::tam.mml(resp=resp, Y=Y, beta.fixed=FALSE )############################################################################## EXAMPLE 3: Multiple group estimation############################################################################## (1) simulate dataset.seed(6778)N <- 3000theta <- c( stats::rnorm(N/2,mean=0,sd=1.5), stats::rnorm(N/2,mean=.5,sd=1) )I <- 20p1 <- stats::plogis( outer( theta, seq( -2, 2, len=I ), "-" ) )resp <- 1 * ( p1 > matrix( stats::runif( N*I ), nrow=N, ncol=I ) )colnames(resp) <- paste("I", 1:I, sep="")group <- rep(1:2, each=N/2 )# (2) estimate modelmod3_1 <- TAM::tam.mml( resp, group=group )summary(mod3_1)############################################################################## EXAMPLE 4: Multidimensional estimation# with two dimensional theta's - simulate some bivariate data,# and regressors# 40 items: first 20 items load on dimension 1,# second 20 items load on dimension 2############################################################################## (1) simulate some dataset.seed(6778)library(mvtnorm)N <- 1000Y <- cbind( stats::rnorm( N ), stats::rnorm(N) )theta <- mvtnorm::rmvnorm( N,mean=c(0,0), sigma=matrix( c(1,.5,.5,1), 2, 2 ))theta[,1] <- theta[,1] + .4 * Y[,1] + .2 * Y[,2] # latent regression modeltheta[,2] <- theta[,2] + .8 * Y[,1] + .5 * Y[,2] # latent regression modelI <- 20p1 <- stats::plogis( outer( theta[,1], seq( -2, 2, len=I ), "-" ) )resp1 <- 1 * ( p1 > matrix( stats::runif( N*I ), nrow=N, ncol=I ) )p1 <- stats::plogis( outer( theta[,2], seq( -2, 2, len=I ), "-" ) )resp2 <- 1 * ( p1 > matrix( stats::runif( N*I ), nrow=N, ncol=I ) )resp <- cbind(resp1,resp2)colnames(resp) <- paste("I", 1:(2*I), sep="")# (2) define loading MatrixQ <- array( 0, dim=c( 2*I, 2 ))Q[cbind(1:(2*I), c( rep(1,I), rep(2,I) ))] <- 1# (3) estimate models#************************************************************# Model 4.1: Rasch model: without regressorsmod4_1 <- TAM::tam.mml( resp=resp, Q=Q )#--- tamaan specificationtammodel <- " LAVAAN MODEL: F1=~ 1*I1__I20 F2=~ 1*I21__I40 # Alternatively to the factor 1 one can use the item type Rasch F1 ~~ F1 F2 ~~ F2 F1 ~~ F2 "mod4_1t <- TAM::tamaan( tammodel, resp, control=list(maxiter=100))summary(mod4_1t)#************************************************************# Model 4.1b: estimate model with sum constraint of items for each dimensionmod4_1b <- TAM::tam.mml( resp=resp, Q=Q,constraint="items")#************************************************************# Model 4.2: Rasch model: set covariance between dimensions to zerovariance_fixed <- cbind( 1, 2, 0 )mod4_2 <- TAM::tam.mml( resp=resp, Q=Q, variance.fixed=variance_fixed )summary(mod4_2)#--- tamaan specificationtammodel <- " LAVAAN MODEL: F1=~ I1__I20 F2=~ I21__I40 F1 ~~ F1 F2 ~~ F2 F1 ~~ 0*F2 ITEM TYPE: ALL(Rasch) "mod4_2t <- TAM::tamaan( tammodel, resp)summary(mod4_2t)#************************************************************# Model 4.3: 2PL modelmod4_3 <- TAM::tam.mml.2pl( resp=resp, Q=Q, irtmodel="2PL" )#--- tamaan specificationtammodel <- " LAVAAN MODEL: F1=~ I1__I20 F2=~ I21__I40 F1 ~~ F1 F2 ~~ F2 F1 ~~ F2 "mod4_3t <- TAM::tamaan( tammodel, resp )summary(mod4_3t)#************************************************************# Model 4.4: Rasch model with 2000 quasi monte carlo nodes# -> nodes are useful for more than 3 or 4 dimensionsmod4_4 <- TAM::tam.mml( resp=resp, Q=Q, control=list(snodes=2000) )#************************************************************# Model 4.5: Rasch model with 2000 stochastic nodesmod4_5 <- TAM::tam.mml( resp=resp, Q=Q,control=list(snodes=2000,QMC=FALSE))#************************************************************# Model 4.6: estimate two dimensional Rasch model with regressorsmod4_6 <- TAM::tam.mml( resp=resp, Y=Y, Q=Q )#--- tamaan specificationtammodel <- " LAVAAN MODEL: F1=~ I1__I20 F2=~ I21__I40 F1 ~~ F1 F2 ~~ F2 F1 ~~ F2 ITEM TYPE: ALL(Rasch) "mod4_6t <- TAM::tamaan( tammodel, resp, Y=Y )summary(mod4_6t)############################################################################## EXAMPLE 5: 2-dimensional estimation with within item dimensionality#############################################################################library(mvtnorm)# (1) simulate dataset.seed(4762)N <- 2000 # 2000 personsY <- stats::rnorm( N )theta <- mvtnorm::rmvnorm( N,mean=c(0,0), sigma=matrix( c(1,.5,.5,1), 2, 2 ))I <- 10# 10 items load on the first dimensionp1 <- stats::plogis( outer( theta[,1], seq( -2, 2, len=I ), "-" ) )resp1 <- 1 * ( p1 > matrix( stats::runif( N*I ), nrow=N, ncol=I ) )# 10 items load on the second dimensionp1 <- stats::plogis( outer( theta[,2], seq( -2, 2, len=I ), "-" ) )resp2 <- 1 * ( p1 > matrix( stats::runif( N*I ), nrow=N, ncol=I ) )# 20 items load on both dimensionsp1 <- stats::plogis( outer( 0.5*theta[,1] + 1.5*theta[,2], seq(-2,2,len=2*I ), "-" ))resp3 <- 1 * ( p1 > matrix( stats::runif( N*2*I ), nrow=N, ncol=2*I ) )#Combine the two sets of items into one response matrixresp <- cbind(resp1, resp2, resp3 )colnames(resp) <- paste("I", 1:(4*I), sep="")# (2) define loading matrixQ <- cbind(c(rep(1,10),rep(0,10),rep(1,20)), c(rep(0,10),rep(1,10),rep(1,20)))# (3) model: within item dimensionality and 2PL estimationmod5 <- TAM::tam.mml.2pl(resp, Q=Q, irtmodel="2PL" )summary(mod5)# item difficultiesmod5$item# item loadingsmod5$B#--- tamaan specificationtammodel <- " LAVAAN MODEL: F1=~ I1__I10 + I21__I40 F2=~ I11__I20 + I21__I40 F1 ~~ 1*F1 F1 ~~ F2 F2 ~~ 1*F2 "mod5t <- TAM::tamaan( tammodel, resp, control=list(maxiter=10))summary(mod5t)############################################################################## EXAMPLE 6: ordered data - Generalized partial credit model#############################################################################data(data.gpcm, package="TAM")#************************************************************# Ex6.1: Nominal response model (irtmodel="2PL")mod6_1 <- TAM::tam.mml.2pl( resp=data.gpcm, irtmodel="2PL", control=list(maxiter=200) )mod6_1$item # item interceptsmod6_1$B # for every category a separate slope parameter is estimated# reestimate the model with fixed item parametersmod6_1a <- TAM::tam.mml.2pl( resp=data.gpcm, irtmodel="2PL", xsi.fixed=mod6_1$xsi.fixed.estimated, B.fixed=mod6_1$B.fixed.estimated, est.variance=TRUE )# estimate the model with initial item parameters from mod6_1mod6_1b <- TAM::tam.mml.2pl( resp=data.gpcm, irtmodel="2PL", xsi.inits=mod6_1$xsi.fixed.estimated, B=mod6_1$B )#************************************************************# Ex6.2: Generalized partial credit modelmod6_2 <- TAM::tam.mml.2pl( resp=data.gpcm, irtmodel="GPCM", control=list(maxiter=200))mod6_2$B[,2,] # joint slope parameter for all categories#************************************************************# Ex6.3: some fixed entries of slope matrix B# B: nitems x maxK x ndim# ( number of items x maximum number of categories x number of dimensions)# set two constraintsB.fixed <- matrix( 0, 2, 4 )# set second item, score of 2 (category 3), at first dimension to 2.3B.fixed[1,] <- c(2,3,1,2.3)# set third item, score of 1 (category 2), at first dimension to 1.4B.fixed[2,] <- c(3,2,1,1.4)# estimate item parameter with variance fixed (by default)mod6_3 <- TAM::tam.mml.2pl( resp=data.gpcm, irtmodel="2PL", B.fixed=B.fixed, control=list( maxiter=200) )mod6_3$B#************************************************************# Ex 6.4: estimate the same model, but estimate variancemod6_4 <- TAM::tam.mml.2pl( resp=data.gpcm, irtmodel="2PL", B.fixed=B.fixed, est.variance=TRUE, control=list( maxiter=350) )mod6_4$B#************************************************************# Ex 6.5: partial credit modelmod6_5 <- TAM::tam.mml( resp=data.gpcm,control=list( maxiter=200) )mod6_5$B#************************************************************# Ex 6.6: partial credit model: Conquest parametrization 'item+item*step'mod6_6 <- TAM::tam.mml( resp=data.gpcm, irtmodel="PCM2" )summary(mod6_6)# estimate mod6_6 applying the sum constraint of item difficulties# modify design matrix of xsi paramtersA1 <- TAM::.A.PCM2(resp=data.gpcm )A1[3,2:4,"Comfort"] <- 1:3A1[3,2:4,"Work"] <- 1:3A1 <- A1[,, -3] # remove Benefit xsi item parameter# estimate modelmod6_6b <- TAM::tam.mml( resp=data.gpcm, A=A1, beta.fixed=FALSE )summary(mod6_6b)# estimate model with argument constraint="items"mod6_6c <- TAM::tam.mml( resp=data.gpcm, irtmodel="PCM2", constraint="items")# estimate mod6_6 using tam.mml.mfrmod6_6d <- TAM::tam.mml.mfr( resp=data.gpcm, formulaA=~ 0 + item + item:step, control=list(fac.oldxsi=.1), constraint="items" )summary(mod6_6d)#************************************************************# Ex 6.7: Rating scale model: Conquest parametrization 'item+step'mod6_7 <- TAM::tam.mml( resp=data.gpcm, irtmodel="RSM" )summary(mod6_7)#************************************************************# Ex 6.8: sum constraint on item difficulties# partial credit model: ConQuest parametrization 'item+item*step'# polytomous scored TIMMS data# compare to Example 16#data(data.timssAusTwn.scored)dat <- data.timssAusTwn.scored[,1:11]## > tail(sort(names(dat)),1) # constrained item## [1] "M032761"# modify design matrix of xsi paramtersA1 <- TAM::.A.PCM2( resp=dat )# constrained item loads on every other main item parameter# with opposing margin it had been loaded on its own main item parameterA1["M032761",,setdiff(colnames(dat), "M032761")] <- -A1["M032761",,"M032761"]# remove main item parameter for constrained itemA1 <- A1[,, setdiff(dimnames(A1)[[3]],"M032761")]# estimate modelmod6_8a <- TAM::tam.mml( resp=dat, A=A1, beta.fixed=FALSE )summary(mod6_8a)# extract fixed item parameter for item M032761## - sum(mod6_8a$xsi[setdiff(colnames(dat), "M032761"),"xsi"])# estimate mod6_8a using tam.mml.mfr## fixed a bug in 'tam.mml.mfr' for differing number of categories## per item -> now a xsi vector with parameter fixings to values## of 99 is usedmod6_8b <- TAM::tam.mml.mfr( resp=dat, formulaA=~ 0 + item + item:step, control=list(fac.oldxsi=.1), constraint="items" )summary(mod6_8b)#************************************************************# Ex 6.9: sum constraint on item difficulties for irtmodel="PCM"data(data.timssAusTwn.scored)dat <- data.timssAusTwn.scored[,2:11]dat[ dat==9 ] <- NA# obtain the design matrix for the PCM parametrization and# the number of categories for each itemmaxKi <- apply(dat, 2, max, na.rm=TRUE)des <- TAM::designMatrices(resp=dat)A1 <- des$A# define the constrained item category and remove the respective parameter(par <- unlist( strsplit(dimnames(A1)[[3]][dim(A1)[3]], split="_") ))A1 <- A1[,,-dim(A1)[3]]# the item category loads on every other item category parameter with# opposing margin, balancing the number of categories for each itemitem.id <- which(colnames(dat)==par[1])cat.id <- maxKi[par[1]]+1loading <- 1/rep(maxKi, maxKi)loading <- loading [-which(names(loading)==par[1])[1]]A1[item.id, cat.id, ] <- loadingA1[item.id,,]# estimate modelmod6_9 <- TAM::tam.mml( resp=dat, A=A1, beta.fixed=FALSE )summary(mod6_9)## extract fixed item category parameter# calculate mean for each itemind.item.cat.pars <- sapply(colnames(dat), grep, rownames(mod6_8$xsi))item.means <- lapply(ind.item.cat.pars, function(ii) mean(mod6_8$xsi$xsi[ii]))# these sum up to the negative of the fixed parameterfix.par <- -sum( unlist(item.means), na.rm=TRUE)#************************************************************# Ex 6.10: Generalized partial credit model with equality constraints# on item discriminationsdata(data.gpcm)dat <- data.gpcm# Ex 6.10a: set all slopes of three items equal to each otherE <- matrix( 1, nrow=3, ncol=1 )mod6_10a <- TAM::tam.mml.2pl( dat, irtmodel="GPCM.design", E=E )summary(mod6_10a)mod6_10a$B[,,]# Ex 6.10b: equal slope for first and third itemE <- matrix( 0, nrow=3, ncol=2 )E[c(1,3),1] <- 1E[ 2, 2 ] <- 1mod6_10b <- TAM::tam.mml.2pl( dat, irtmodel="GPCM.design", E=E )summary(mod6_10b)mod6_10b$B[,,]############################################################################## EXAMPLE 7: design matrix for slopes for the generalized partial credit model############################################################################## (1) simulate data from a model with a (item slope) design matrix Eset.seed(789)I <- 42b <- seq( -2, 2, len=I)# create design matrix for loadingsE <- matrix( 0, I, 5 )E[ seq(1,I,3), 1 ] <- 1E[ seq(2,I,3), 2 ] <- 1E[ seq(3,I,3), 3 ] <- 1ind <- seq( 1, I, 2 ) ; E[ ind, 4 ] <- rep( c( .3, -.2 ), I )[ 1:length(ind) ]ind <- seq( 2, I, 4 ) ; E[ ind, 5 ] <- rep( .15, I )[ 1:length(ind) ]E# true basis slope parameterslambda <- c( 1, 1.2, 0.8, 1, 1.1 )# calculate item slopesa <- E %*% lambda# simulateN <- 4000theta <- stats::rnorm( N )aM <- outer( rep(1,N), a[,1] )bM <- outer( rep(1,N), b )pM <- stats::plogis( aM * ( matrix( theta, nrow=N, ncol=I ) - bM ) )dat <- 1 * ( pM > stats::runif( N*I ) )colnames(dat) <- paste("I", 1:I, sep="")# estimate modelmod7 <- TAM::tam.mml.2pl( resp=dat, irtmodel="GPCM.design", E=E )mod7$B# recalculate estimated basis parametersstats::lm( mod7$B[,2,1] ~ 0+ as.matrix(E ) ) ## Call: ## lm(formula=mod7$B[, 2, 1] ~ 0 + as.matrix(E)) ## Coefficients: ## as.matrix(E)1 as.matrix(E)2 as.matrix(E)3 as.matrix(E)4 as.matrix(E)5 ## 0.9904 1.1896 0.7817 0.9601 1.2132############################################################################## EXAMPLE 8: Differential item functioning ## A first example of a Multifaceted Rasch Model ## Facet is only female; 10 items are studied ##############################################################################data(data.ex08)formulaA <- ~ item+female+item*female# this formula is in R equivalent to 'item*female'resp <- data.ex08[["resp"]]facets <- as.data.frame( data.ex08[["facets"]] )#***# Model 8a: investigate gender DIF on all itemsmod8a <- TAM::tam.mml.mfr( resp=resp, facets=facets, formulaA=formulaA )summary(mod8a)#***# Model 8a 2: specification with long format response dataresp.long <- c( data.ex08[["resp"]] )pid <- rep( 1:nrow(data.ex08[["resp"]]), ncol(data.ex08[["resp"]]) )itemnames <- rep(colnames(data.ex08[["resp"]]), each=nrow(data.ex08[["resp"]]))facets.long <- cbind( data.frame( "item"=itemnames ), data.ex08[["facets"]][pid,,drop=F] )mod8a_2 <- TAM::tam.mml.mfr( resp=resp.long, facets=facets.long, formulaA=formulaA, pid=pid)stopifnot( all(mod8a$xsi.facets$xsi==mod8a_2$xsi.facets$xsi) )#***# Model 8b: Differential bundle functioning (DBF)# - investigate differential item functioning in item groups# modify pre-specified design matrix to define 'appropriate' DBF effectsformulaA <- ~ item*femaledes <- TAM::designMatrices.mfr( resp=resp, facets=facets, formulaA=formulaA)A1 <- des$A$A.3d# item group A: items 1-5# item group B: items 6-8# item group C: items 9-10A1 <- A1[,,1:13]dimnames(A1)[[3]][ c(12,13) ] <- c("A:female1", "B:female1")# item group AA1[,2,12] <- 0A1[c(1,5,7,9,11),2,12] <- -1A1[c(1,5,7,9,11)+1,2,12] <- 1# item group BA1[,2,13] <- 0A1[c(13,15,17),2,13] <- -1A1[c(13,15,17)+1,2,13] <- 1# item group C (define effect(A)+effect(B)+effect(C)=0)A1[c(19,3),2,c(12,13)] <- 1A1[c(19,3)+1,2,c(12,13)] <- -1# A1[,2,] # look at modified design matrix# estimate modelmod8b <- TAM::tam.mml( resp=des$gresp$gresp.noStep, A=A1 )summary(mod8b)############################################################################## EXAMPLE 9: Multifaceted Rasch Model#############################################################################data(data.sim.mfr)data(data.sim.facets)# two way interaction item and raterformulaA <- ~item+item:step + item*ratermod9a <- TAM::tam.mml.mfr( resp=data.sim.mfr, facets=data.sim.facets, formulaA=formulaA)mod9a$xsi.facetssummary(mod9a)# three way interaction item, female and raterformulaA <- ~item+item:step + female*rater + female*item*stepmod9b <- TAM::tam.mml.mfr( resp=data.sim.mfr, facets=data.sim.facets, formulaA=formulaA)summary(mod9b)############################################################################## EXAMPLE 10: Model with raters.# Persons are arranged in multiple rows which is indicated# by multiple person identifiers.#############################################################################data(data.ex10)dat <- data.ex10head(dat) ## pid rater I0001 I0002 I0003 I0004 I0005 ## 1 1 1 0 1 1 0 0 ## 451 1 2 1 1 1 1 0 ## 901 1 3 1 1 1 0 1 ## 452 2 2 1 1 1 0 1 ## 902 2 3 1 1 0 1 1facets <- dat[, "rater", drop=FALSE ] # define facet (rater)pid <- dat$pid # define person identifier (a person occurs multiple times)resp <- dat[, -c(1:2) ] # item response dataformulaA <- ~ item * rater # formulamod10 <- TAM::tam.mml.mfr( resp=resp, facets=facets, formulaA=formulaA, pid=dat$pid )summary(mod10)# estimate person parameter with WLEwmod10 <- TAM::tam.wle( mod10 )#--- Example 10a# compare model containing only itemformulaA <- ~ item + rater # pseudo formula for itemxsi.setnull <- "rater" # set all rater effects to zeromod10a <- TAM::tam.mml.mfr( resp=resp, facets=facets, formulaA=formulaA, xsi.setnull=xsi.setnull, pid=dat$pid, beta.fixed=cbind(1,1,0))summary(mod10a)# A shorter way for specifying this example isformulaA <- ~ item + 0*rater # set all rater effects to zeromod10a1 <- TAM::tam.mml.mfr( resp=resp, facets=facets, formulaA=formulaA, pid=dat$pid )summary(mod10a1)# tam.mml.mfr also appropriately extends the facets data frame with pseudo facets# if necessaryformulaA <- ~ item # omitting the rater termmod10a2 <- TAM::tam.mml.mfr( resp=resp, facets=facets, formulaA=formulaA, pid=dat$pid ) ## Item Parameters Xsi ## xsi se.xsi ## I0001 -1.931 0.111 ## I0002 -1.023 0.095 ## I0003 -0.089 0.089 ## I0004 1.015 0.094 ## I0005 1.918 0.110 ## psfPF11 0.000 0.000 ## psfPF12 0.000 0.000#***# Model 10_2: specification with long format response dataresp.long <- c(unlist( dat[, -c(1:2) ] ))pid <- rep( dat$pid, ncol(dat[, -c(1:2) ]) )itemnames <- rep(colnames(dat[, -c(1:2) ]), each=nrow(dat[, -c(1:2) ]))# quick note: the 'trick' to use pid as the row index of the facet (cf., used in Ex 8a_2)# is not working here, since pid already occures multiple times in the original response datafacets <- cbind( data.frame("item"=itemnames), dat[ rep(1:nrow(dat), ncol(dat[,-c(1:2)])), "rater",drop=F])mod10_2 <- TAM::tam.mml.mfr( resp=resp.long, facets=facets, formulaA=formulaA, pid=pid)stopifnot( all(mod10$xsi.facets$xsi==mod10_2$xsi.facets$xsi) )############################################################################## EXAMPLE 11: Dichotomous data with missing and omitted responses#############################################################################data(data.ex11) ; dat <- data.ex11#***# Model 11a: Calibration (item parameter estimating) in which omitted# responses (code 9) are set to missingdat1 <- dat[,-1]dat1[ dat1==9 ] <- NA# estimate Rasch modelmod11a <- TAM::tam.mml( resp=dat1 )summary(mod11a)# compute person parameterswmod11a <- TAM::tam.wle( mod11a )#***# Model 11b: Scaling persons (WLE estimation) setting omitted# responses as incorrect and using fixed# item parameters form Model 11a# set matrix with fixed item difficulties as the inputxsi1 <- mod11a$xsi # xsi output from Model 11axsi.fixed <- cbind( seq(1,nrow(xsi1) ), xsi1$xsi )# recode 9 to 0dat2 <- dat[,-1]dat2[ dat2==9 ] <- 0# run Rasch model with fixed item difficultiesmod11b <- TAM::tam.mml( resp=dat2, xsi.fixed=xsi.fixed )summary(mod11b)# WLE estimationwmod11b <- TAM::tam.wle( mod11b )############################################################################## EXAMPLE 12: Avoiding nonconvergence using the argument increment.factor#############################################################################data(data.ex12)dat <- data.ex12# non-convergence without increment.factormod1 <- TAM::tam.mml.2pl( resp=data.ex12, control=list( maxiter=1000) )# avoiding non-convergence with increment.factor=1.02mod2 <- TAM::tam.mml.2pl( resp=data.ex12, control=list( maxiter=1000, increment.factor=1.02) )summary(mod1)summary(mod2)############################################################################## EXAMPLE 13: Longitudinal data 'data.long' from sirt package#############################################################################library(sirt)data(data.long, package="sirt")dat <- data.long ## > colnames(dat) ## [1] "idstud" "I1T1" "I2T1" "I3T1" "I4T1" "I5T1" "I6T1" ## [8] "I3T2" "I4T2" "I5T2" "I6T2" "I7T2" "I8T2"## item 1 to 6 administered at T1 and items 3 to 8 at T2## items 3 to 6 are anchor items#***# Model 13a: 2-dimensional Rasch model assuming invariant item difficulties# define matrix loadingsQ <- matrix(0,12,2)colnames(Q) <- c("T1","T2")Q[1:6,1] <- 1 # items at T1Q[7:12,2] <- 1 # items at T2# assume equal item difficulty of I3T1 and I3T2, I4T1 and I4T2, ...# create draft design matrix and modify itA <- TAM::designMatrices(resp=data.long[,-1])$Adimnames(A)[[1]] <- colnames(data.long)[-1] ## > str(A) ## num [1:12, 1:2, 1:12] 0 0 0 0 0 0 0 0 0 0 ... ## - attr(*, "dimnames")=List of 3 ## ..$ : chr [1:12] "Item01" "Item02" "Item03" "Item04" ... ## ..$ : chr [1:2] "Category0" "Category1" ## ..$ : chr [1:12] "I1T1" "I2T1" "I3T1" "I4T1" ...A1 <- A[,, c(1:6, 11:12 ) ]dimnames(A1)[[3]] <- substring( dimnames(A1)[[3]],1,2)A1[7,2,3] <- -1 # difficulty(I3T1)=difficulty(I3T2)A1[8,2,4] <- -1 # I4T1=I4T2A1[9,2,5] <- A1[10,2,6] <- -1 ## > A1[,2,] ## I1 I2 I3 I4 I5 I6 I7 I8 ## I1T1 -1 0 0 0 0 0 0 0 ## I2T1 0 -1 0 0 0 0 0 0 ## I3T1 0 0 -1 0 0 0 0 0 ## I4T1 0 0 0 -1 0 0 0 0 ## I5T1 0 0 0 0 -1 0 0 0 ## I6T1 0 0 0 0 0 -1 0 0 ## I3T2 0 0 -1 0 0 0 0 0 ## I4T2 0 0 0 -1 0 0 0 0 ## I5T2 0 0 0 0 -1 0 0 0 ## I6T2 0 0 0 0 0 -1 0 0 ## I7T2 0 0 0 0 0 0 -1 0 ## I8T2 0 0 0 0 0 0 0 -1# estimate model# set intercept of second dimension (T2) to zerobeta.fixed <- cbind( 1, 2, 0 )mod13a <- TAM::tam.mml( resp=data.long[,-1], Q=Q, A=A1, beta.fixed=beta.fixed)summary(mod13a)#--- tamaan specificationtammodel <- " LAVAAN MODEL: T1=~ 1*I1T1__I6T1 T2=~ 1*I3T2__I8T2 T1 ~~ T1 T2 ~~ T2 T1 ~~ T2 # constraint on item difficulties I3T1 + I3T2 | b3*t1 I4T1 + I4T2 | b4*t1 I5T1 + I5T2 | b5*t1 I6T1 + I6T2 | b6*t1 "# The constraint on item difficulties can be more efficiently written as ## DO(3,6,1) ## I%T1 + I%T2 | b%*t1 ## DOEND# estimate modelmod13at <- TAM::tamaan( tammodel, resp=data.long, beta.fixed=beta.fixed )summary(mod13at)#***# Model 13b: invariant item difficulties with zero mean item difficulty# of anchor itemsA <- TAM::designMatrices(resp=data.long[,-1])$Adimnames(A)[[1]] <- colnames(data.long)[-1]A1 <- A[,, c(1:5, 11:12 ) ]dimnames(A1)[[3]] <- substring( dimnames(A1)[[3]],1,2)A1[7,2,3] <- -1 # difficulty(I3T1)=difficulty(I3T2)A1[8,2,4] <- -1 # I4T1=I4T2A1[9,2,5] <- -1A1[6,2,3] <- A1[6,2,4] <- A1[6,2,5] <- 1 # I6T1=-(I3T1+I4T1+I5T1)A1[10,2,3] <- A1[10,2,4] <- A1[10,2,5] <- 1 # I6T2=-(I3T2+I4T2+I5T2)A1[,2,] ## I1 I2 I3 I4 I5 I7 I8 ## I1T1 -1 0 0 0 0 0 0 ## I2T1 0 -1 0 0 0 0 0 ## I3T1 0 0 -1 0 0 0 0 ## I4T1 0 0 0 -1 0 0 0 ## I5T1 0 0 0 0 -1 0 0 ## I6T1 0 0 1 1 1 0 0 ## I3T2 0 0 -1 0 0 0 0 ## I4T2 0 0 0 -1 0 0 0 ## I5T2 0 0 0 0 -1 0 0 ## I6T2 0 0 1 1 1 0 0 ## I7T2 0 0 0 0 0 -1 0 ## I8T2 0 0 0 0 0 0 -1mod13b <- TAM::tam.mml( resp=data.long[,-1], Q=Q, A=A1, beta.fixed=FALSE)summary(mod13b)#***# Model 13c: longitudinal polytomous data## modifiy Items I1T1, I4T1, I4T2 in order to be trichotomous (codes: 0,1,2)set.seed(42)dat <- data.longdat[(1:50),2] <- sample(c(0,1,2), 50, replace=TRUE)dat[(1:50),5] <- sample(c(0,1,2), 50, replace=TRUE)dat[(1:50),9] <- sample(c(0,1,2), 50, replace=TRUE) ## > colnames(dat) ## [1] "idstud" "I1T1" "I2T1" "I3T1" "I4T1" "I5T1" "I6T1" ## [8] "I3T2" "I4T2" "I5T2" "I6T2" "I7T2" "I8T2"## item 1 to 6 administered at T1, items 3 to 8 at T2## items 3 to 6 are anchor items# (1) define matrix loadingsQ <- matrix(0,12,2)colnames(Q) <- c("T1","T2")Q[1:6,1] <- 1 # items at T1Q[7:12,2] <- 1 # items at T2# (2) assume equal item difficulty of anchor items# create draft design matrix and modify itA <- TAM::designMatrices(resp=dat[,-1])$Adimnames(A)[[1]] <- colnames(dat)[-1] ## > str(A) ## num [1:12, 1:3, 1:15] 0 0 0 0 0 0 0 0 0 0 ... ## - attr(*, "dimnames")=List of 3 ## ..$ : chr [1:12] "I1T1" "I2T1" "I3T1" "I4T1" ... ## ..$ : chr [1:3] "Category0" "Category1" "Category2" ## ..$ : chr [1:15] "I1T1_Cat1" "I1T1_Cat2" "I2T1_Cat1" "I3T1_Cat1" ...# define matrix A# Items 1 to 3 administered at T1, Items 3 to 6 are anchor items# Item 7 to 8 administered at T2# Item I1T1, I4T1, I4T2 are trichotomous (codes: 0,1,2)A1 <- A[,, c(1:8, 14:15) ]dimnames(A1)[[3]] <- gsub("T1|T2", "", dimnames(A1)[[3]])# Modifications are shortened compared to Model 13 a, but are still validA1[7,,] <- A1[3,,] # item 7, i.e. I3T2, loads on same parameters as # item 3, I3T1A1[8,,] <- A1[4,,] # same for item 8 and item 4A1[9,,] <- A1[5,,] # same for item 9 and item 5A1[10,,] <- A1[6,,] # same for item 10 and item 6 ## > A1[8,,] ## I1_Cat1 I1_Cat2 I2_Cat1 I3_Cat1 I4_Cat1 I4_Cat2 I5_Cat1 ... ## Category0 0 0 0 0 0 0 0 ## Category1 0 0 0 0 -1 0 0 ## Category2 0 0 0 0 -1 -1 0# (3) estimate model# set intercept of second dimension (T2) to zerobeta.fixed <- cbind( 1, 2, 0 )mod13c <- TAM::tam.mml( resp=dat[,-1], Q=Q, A=A1, beta.fixed=beta.fixed, irtmodel="PCM")summary(mod13c)wle.mod13c <- TAM::tam.wle(mod13c) # WLEs of dimension T1 and T2############################################################################## EXAMPLE 14: Facet model with latent regression#############################################################################data( data.ex14 )dat <- data.ex14#***# Model 14a: facet modelresp <- dat[, paste0("crit",1:7,sep="") ] # item datafacets <- data.frame( "rater"=dat$rater ) # define facetsformulaA <- ~item+item*step + ratermod14a <- TAM::tam.mml.mfr( resp, facets=facets, formulaA=formulaA, pid=dat$pid )summary(mod14a)#***# Model 14b: facet model with latent regression# Note that dataY must correspond to rows in resp and facets which means# that there must be the same rows in Y for a person with multiple rows# in respdataY <- dat[, c("X1","X2") ] # latent regressorsformulaY <- ~ X1+X2 # latent regression formulamod14b <- TAM::tam.mml.mfr( resp, facets=facets, formulaA=formulaA, dataY=dataY, formulaY=formulaY, pid=dat$pid)summary(mod14b)#***# Model 14c: Multi-facet model with item slope estimation# use design matrix and modified response data from Model 1# item-specific slopesresp1 <- mod14a$resp # extract response data with generalized itemsA <- mod14a$A # extract design matrix for item interceptscolnames(resp1)# define design matrix for slopesE <- matrix( 0, nrow=ncol(resp1), ncol=7 )colnames(E) <- paste0("crit",1:7)rownames(E) <- colnames(resp1)E[ cbind( 1:(7*7), rep(1:7,each=7) ) ] <- 1mod14c <- TAM::tam.mml.2pl( resp=resp1, A=A, irtmodel="GPCM.design", E=E, control=list(maxiter=100) )summary(mod14c)############################################################################## EXAMPLE 15: Coping with nonconvergent models#############################################################################data(data.ex15)data <- data.ex15# facet model 'group*item' is of interest#***# Model 15a:mod15a <- TAM::tam.mml.mfr(resp=data[,-c(1:2)],facets=data[,"group",drop=FALSE], formulaA=~ item + group*item, pid=data$pid )# See output: ## ## Iteration 47 2013-09-10 16:51:39 ## E Step ## M Step Intercepts |---- ## Deviance=75510.2868 | Deviance change: -595.0609 ## !!! Deviance increases! !!!! ## !!! Choose maybe fac.oldxsi > 0 and/or increment.factor > 1 !!!! ## Maximum intercept parameter change: 0.925045 ## Maximum regression parameter change: 0 ## Variance: 0.9796 | Maximum change: 0.009226#***# Model 15b: Follow the suggestions of changing the default of fac.oldxsi and# increment.factormod15b <- TAM::tam.mml.mfr(resp=data[,-c(1:2)],facets=data[,"group",drop=FALSE], formulaA=~ group*item, pid=data$pid, control=list( increment.factor=1.03, fac.oldxsi=.4 ) )#***# Model 15c: Alternatively, just choose more iterations in M-step by "Msteps=10"mod15c <- TAM::tam.mml.mfr(resp=data[,-c(1:2)],facets=data[,"group",drop=FALSE], formulaA=~ item + group*item, pid=data$pid, control=list(maxiter=250, Msteps=10))############################################################################## EXAMPLE 16: Differential item function for polytomous items and# differing number of response options per item#############################################################################data(data.timssAusTwn.scored)dat <- data.timssAusTwn.scored# extract item response dataresp <- dat[, sort(grep("M", colnames(data.timssAusTwn.scored), value=TRUE)) ]# some descriptivespsych::describe(resp)# define facets: 'cnt' is group identifierfacets <- data.frame( "cnt"=dat$IDCNTRY)# create design matricesdes2 <- TAM::designMatrices.mfr2( resp=resp, facets=facets, formulaA=~item*step + item*cnt)# restructured data set: pseudoitem=item x countryresp2 <- des2$gresp$gresp.noStep# A design matrixA <- des2$A$A.3d # redundant xsi parameters must be eliminated from design matrixxsi.elim <- des2$xsi.elimA <- A[,, - xsi.elim[,2] ]# extract loading matrix BB <- des2$B$B.3d# estimate modelmod1 <- TAM::tam.mml( resp=resp2, A=A, B=B, control=list(maxiter=100) )summary(mod1)# The sum of all DIF parameters is set to zero. The DIF parameter for the last# item is therefore obtainedxsi1 <- mod1$xsidifxsi <- xsi1[ intersect( grep("cnt",rownames(xsi1)), grep("M03",rownames(xsi1))), ] - colSums(difxsi) # this is the DIF effect of the remaining item############################################################################## EXAMPLE 17: Several multidimensional and subdimension models#############################################################################library(mirt)#*** (1) simulate data in mirt packageset.seed(9897)# simulate data according to the four-dimensional Rasch model# variancesvariances <- c( 1.45, 1.74, .86, 1.48 )# correlationscorrs <- matrix( 1, 4, 4 )dd1 <- 1 ; dd2 <- 2 ; corrs[dd1,dd2] <- corrs[dd2,dd1] <- .88dd1 <- 1 ; dd2 <- 3 ; corrs[dd1,dd2] <- corrs[dd2,dd1] <- .85dd1 <- 1 ; dd2 <- 4 ; corrs[dd1,dd2] <- corrs[dd2,dd1] <- .87dd1 <- 2 ; dd2 <- 3 ; corrs[dd1,dd2] <- corrs[dd2,dd1] <- .84dd1 <- 2 ; dd2 <- 4 ; corrs[dd1,dd2] <- corrs[dd2,dd1] <- .90dd1 <- 3 ; dd2 <- 4 ; corrs[dd1,dd2] <- corrs[dd2,dd1] <- .90# covariance matrixcovar <- outer( sqrt( variances), sqrt(variances) )*corrs# item thresholds and item discriminationsd <- matrix( stats::runif(40, -2, 2 ), ncol=1 )a <- matrix(NA, nrow=40,ncol=4)a[1:10,1] <- a[11:20,2] <- a[21:30,3] <- a[31:40,4] <- 1# simulate datadat <- mirt::simdata(a=a, d=d, N=1000, itemtype="dich", sigma=covar )# define Q-matrix for testlet and subdimension models estimated belowQ <- matrix( 0, nrow=40, ncol=5 )colnames(Q) <- c("g", paste0( "subd", 1:4) )Q[,1] <- 1Q[1:10,2] <- Q[11:20,3] <- Q[21:30,4] <- Q[31:40,5] <- 1# define maximum number of iterations and number of quasi monte carlo nodes# maxit <- 5 ; snodes <- 300 # this specification is only for speed reasonsmaxit <- 200 ; snodes <- 1500#*****************# Model 1: Rasch testlet model#*****************# define a user function for restricting the variance according to the# Rasch testlet modelvariance.fct1 <- function( variance ){ ndim <- ncol(variance) variance.new <- matrix( 0, ndim, ndim ) diag(variance.new) <- diag(variance) variance <- variance.new return(variance) }variance.Npars <- 5 # number of estimated parameters in variance matrix# estimation using tam.mmlmod1 <- TAM::tam.mml( dat, Q=Q, userfct.variance=variance.fct1, variance.Npars=variance.Npars, control=list(maxiter=maxit, QMC=TRUE, snodes=snodes))summary(mod1)#*****************# Model 2: Testlet model with correlated testlet effects#*****************# specify a testlet model with general factor g and testlet effects# u_1,u_2,u_3 and u_4. Assume that Cov(g,u_t)=0 for all t=1,2,3,4.# Additionally, assume that \sum_t,t' Cov( u_t, u_t')=0, i.e.# the sum of all testlet covariances is equal to zero#=> testlet effects are uncorrelated on average.# set Cov(g,u_t)=0 and sum of all testlet covariances equals to zerovariance.fct2 <- function( variance ){ ndim <- ncol(variance) variance.new <- matrix( 0, ndim, ndim ) diag(variance.new) <- diag(variance) variance.new[1,2:ndim] <- variance.new[2:ndim,1] <- 0 # calculate average covariance between testlets v1 <- variance[ -1, -1] - variance.new[-1,-1] M1 <- sum(v1) / ( ( ndim-1)^2 - ( ndim - 1)) v1 <- v1 - M1 variance.new[ -1, -1 ] <- v1 diag(variance.new) <- diag(variance) variance <- variance.new return(variance) }variance.Npars <- 1 + 4 + (4*3)/2 - 1# estimate model in TAMmod2 <- TAM::tam.mml( dat, Q=Q, userfct.variance=variance.fct2, variance.Npars=variance.Npars, control=list(maxiter=maxit, QMC=TRUE, snodes=snodes) )summary(mod2)#*****************# Model 3: Testlet model with correlated testlet effects (different identification)#*****************# Testlet model like in Model 2. But now the constraint is# \sum _t,t' Cov(u_t, u_t') + \sum_t Var(u_t)=0, i.e.# the sum of all testlet covariances and variances is equal to zero.variance.fct3 <- function( variance ){ ndim <- ncol(variance) variance.new <- matrix( 0, ndim, ndim ) diag(variance.new) <- diag(variance) variance.new[1,2:ndim] <- variance.new[2:ndim,1] <- 0 # calculate average covariance and variance between testlets v1 <- variance[ -1, -1] M1 <- mean(v1) v1 <- v1 - M1 variance.new[ -1, -1 ] <- v1 # ensure positive definiteness of covariance matrix eps <- 10^(-2) diag(variance.new) <- diag( variance.new) + eps variance.new <- psych::cor.smooth( variance.new ) # smoothing in psych variance <- variance.new return(variance) }variance.Npars <- 1 + 4 + (4*3)/2 - 1# estimate model in TAMmod3 <- TAM::tam.mml( dat, Q=Q, userfct.variance=variance.fct3, variance.Npars=variance.Npars, control=list(maxiter=maxit, QMC=TRUE, snodes=snodes) )summary(mod3)#*****************# Model 4: Rasch subdimension model#*****************# The Rasch subdimension model is specified according to Brandt (2008).# The fourth testlet effect is defined as u4=- (u1+u2+u3)# specify an alternative Q-matrix with 4 dimensionsQ2 <- Q[,-5]Q2[31:40,2:4] <- -1# set Cov(g,u1)=Cov(g,u2)=Cov(g,u3)=0variance.fixed <- rbind( c(1,2,0), c(1,3,0), c(1,4,0) )# estimate model in TAMmod4 <- TAM::tam.mml( dat, Q=Q2,variance.fixed=variance.fixed, control=list(maxiter=maxit, QMC=TRUE, snodes=snodes) )summary(mod4)#*****************# Model 5: Higher-order model#*****************# A four-dimensional model with a higher-order factor is specified.# F_t=a_t g + eps_gQ3 <- Q[,-1]# define fitting function using the lavaan package and ULS estimationN0 <- nrow(dat) # sample size of datasetlibrary(lavaan) # requires lavaan package for fitting covariancevariance.fct5 <- function( variance ){ ndim <- ncol(variance) rownames(variance) <- colnames(variance) <- paste0("F",1:ndim) lavmodel <- paste0( "FHO=~", paste0( paste0( "F", 1:ndim ), collapse="+" ) ) lavres <- lavaan::cfa( model=lavmodel, sample.cov=variance, estimator="ULS", std.lv=TRUE, sample.nobs=N0) variance.new <- fitted(lavres)$cov variance <- variance.new # print coefficients cat( paste0( "\n **** Higher order loadings: ", paste0( paste0( round( coef(lavres)[ 1:ndim ], 3 )), collapse=" ") ), "\n") return(variance) }variance.Npars <- 4+4# estimate model in TAMmod5 <- TAM::tam.mml( dat, Q=Q3, userfct.variance=variance.fct5, variance.Npars=variance.Npars, control=list(maxiter=maxit, QMC=TRUE, snodes=snodes) )summary(mod5)#*****************# Model 6: Generalized Rasch subdimension model (Brandt, 2012)#*****************Q2 <- Q[,-5]Q2[31:40,2:4] <- -1# fixed covariancesvariance.fixed2 <- rbind( c(1,2,0), c(1,3,0), c(1,4,0) )# design matrix for item loading parameters# items x category x dimension x xsi parameterE <- array( 0, dim=c( 40, 2, 4, 4 ) )E[ 1:10, 2, c(1,2), 1 ] <- 1E[ 11:20, 2, c(1,3), 2 ] <- 1E[ 21:30, 2, c(1,4), 3 ] <- 1E[ 31:40, 2, 1, 4 ] <- 1E[ 31:40, 2, 2:4, 4 ] <- -1# constraint on slope parameters, see Brandt (2012)gammaconstr <- function( gammaslope ){ K <- length( gammaslope) g1 <- sum( gammaslope^2 ) gammaslope.new <- sqrt(K) / sqrt(g1) * gammaslope return(gammaslope.new) }# estimate modelmod6 <- TAM::tam.mml.3pl( dat, E=E, Q=Q2, variance.fixed=variance.fixed2, skillspace="normal", userfct.gammaslope=gammaconstr, gammaslope.constr.Npars=1, control=list(maxiter=maxit, QMC=TRUE, snodes=snodes ) )summary(mod6)############################################################################## EXAMPLE 18: Partial credit model with dimension-specific sum constraints# on item difficulties#############################################################################data(data.Students, package="CDM")dat <- data.Students[, c( paste0("sc",1:4), paste0("mj",1:4) ) ]# specify dimensions in Q-matrixQ <- matrix( 0, nrow=8, ncol=2 )Q[1:4,1] <- Q[5:8,2] <- 1# partial credit model with some constraint on item parametersmod1 <- TAM::tam.mml( dat, Q=Q, irtmodel="PCM2", constraint="items")summary(mod1)############################################################################## EXAMPLE 19: Partial credit scoring: 0.5 points for partial credit items# and 1 point for dichotomous items#############################################################################data(data.timssAusTwn.scored)dat <- data.timssAusTwn.scored# extrcat item response datadat <- dat[, grep("M03", colnames(dat) ) ]# select items with do have maximum score of 2 (polytomous items)ind <- which( apply( dat, 2, max, na.rm=TRUE )==2 )I <- ncol(dat)# define Q-matrix with scoring variantQ <- matrix( 1, nrow=I, ncol=1 )Q[ ind, 1 ] <- .5 # score of 0.5 for polyomous items# estimate modelmod1 <- TAM::tam.mml( dat, Q=Q, irtmodel="PCM2", control=list(nodes=seq(-10,10,len=21)))summary(mod1)############################################################################## EXAMPLE 20: Specification of loading matrix in multidimensional model#############################################################################data(data.gpcm)psych::describe(data.gpcm)resp <- data.gpcm# define three dimensions and different loadings of item categories# on these dimensions in B loading matrixI <- 3 # 3 itemsD <- 3 # 3 dimensions# define loading matrix B# 4 categories for each item (0,1,2,3)B <- array( 0, dim=c(I,4,D) )for (ii in 1:I){ B[ ii, 1:4, 1 ] <- 0:3 B[ ii, 1,2 ] <- 1 B[ ii, 4,3 ] <- 1 }dimnames(B)[[1]] <- colnames(resp)B[1,,] ## > B[1,,] ## [,1] [,2] [,3] ## [1,] 0 1 0 ## [2,] 1 0 0 ## [3,] 2 0 0 ## [4,] 3 0 1#-- test runmod1 <- TAM::tam.mml( resp, B=B, control=list( snodes=1000, maxiter=5) )summary(mod1)# Same model with TAM::tam.mml.3pl insteaddim4 <- sum(apply(B, c(1, 3), function(x) any(!(x==0))))E1 <- array(0, dim=c(dim(B), dim4))kkk <- 0for (iii in seq_len(dim(E1)[1])) { for (jjj in seq_len(dim(E1)[3])) { if (any(B[iii,, jjj] !=0)) { kkk <- kkk + 1 E1[iii,, jjj, kkk] <- B[iii,, jjj] } }}if (kkk !=dim4) stop("Something went wrong in the loop, because 'kkk !=dim4'.")mod2 <- TAM::tam.mml.3pl(resp, E=E1, est.some.slopes=FALSE, control=list(maxiter=50))summary(mod2)cor(mod1$person$EAP.Dim3, mod2$person$EAP.Dim3)cor(mod1$person$EAP.Dim2, mod2$person$EAP.Dim2)cor(mod1$person$EAP.Dim1, mod2$person$EAP.Dim1)cor(mod1$xsi$xsi, mod2$xsi$xsi)############################################################################## EXAMPLE 21: Acceleration of EM algorithm | dichotomous data#############################################################################N <- 1000 # number of personsI <- 100 # number of itemsset.seed(987)# simulate data according to the Rasch modeldat <- sirt::sim.raschtype( stats::rnorm(N), b=seq(-2,2,len=I) )# estimate modelsmod1n <- TAM::tam.mml( resp=dat, control=list( acceleration="none") ) # no acceler.mod1y <- TAM::tam.mml( resp=dat, control=list( acceleration="Yu") ) # Yu acceler.mod1r <- TAM::tam.mml( resp=dat, control=list( acceleration="Ramsay") ) # Ramsay acceler.# compare number of iterationsmod1n$iter ; mod1y$iter ; mod1r$iter# log-likelihood valueslogLik(mod1n); logLik(mod1y) ; logLik(mod1r)############################################################################## EXAMPLE 22: Acceleration of EM algorithm | polytomous data#############################################################################data(data.gpcm)dat <- data.gpcm# no accelerationmod1n <- TAM::tam.mml.2pl( resp=dat, irtmodel="GPCM", control=list( conv=1E-4, acceleration="none") )# Yu accelerationmod1y <- TAM::tam.mml.2pl( resp=dat, irtmodel="GPCM", control=list( conv=1E-4, acceleration="Yu") )# Ramsay accelerationmod1r <- TAM::tam.mml.2pl( resp=dat, irtmodel="GPCM", control=list( conv=1E-4, acceleration="Ramsay") )# number of iterationsmod1n$iter ; mod1y$iter ; mod1r$iter############################################################################## EXAMPLE 23: Multidimensional polytomous Rasch model in which# dimensions are defined by categories#############################################################################data(data.Students, package="CDM")dat <- data.Students[, grep( "act", colnames(data.Students) ) ]# define multidimensional model in which categories of item define dimensions# * Category 0 -> loading of one on Dimension 0# * Category 1 -> no loadings# * Category 2 -> loading of one on Dimension 2# extract default design matricesres <- TAM::designMatrices( resp=dat )A <- res$AB0 <- 0*res$B# create design matrix BB <- array( 0, dim=c( dim(B0)[c(1,2) ], 2 ) )dimnames(B)[[1]] <- dimnames(B0)[[1]]dimnames(B)[[2]] <- dimnames(B0)[[2]]dimnames(B)[[3]] <- c( "Dim0", "Dim2" )B[,1,1] <- 1B[,3,2] <- 1# estimate multdimensional Rasch modelmod1 <- TAM::tam.mml( resp=dat, A=A, B=B, control=list( maxiter=100) )summary(mod1)# alternative definition of B# * Category 1: negative loading on Dimension 1 and Dimension 2B <- array( 0, dim=c( dim(B0)[c(1,2) ], 2 ) )dimnames(B)[[1]] <- dimnames(B0)[[1]]dimnames(B)[[2]] <- dimnames(B0)[[2]]dimnames(B)[[3]] <- c( "Dim0", "Dim2" )B[,1, 1] <- 1B[,3, 2] <- 1B[,2, c(1,2)] <- -1# estimate modelmod2 <- TAM::tam.mml( resp=dat, A=A, B=B, control=list( maxiter=100) )summary(mod2)############################################################################## EXAMPLE 24: Sum constraint on item-category parameters in partial credit model#############################################################################data(data.gpcm,package="TAM")dat <- data.gpcm# check number of categoriesc1 <- TAM::tam.ctt3(dat)#--- fit with PCMmod1 <- TAM::tam.mml( dat )summary(mod1, file="mod1")#--- fit with constraint on sum of categories#** redefine design matrixA1 <- 0*mod1$AA1 <- A1[,, - dim(A1)[[3]]]str(A1)NP <- dim(A1)[[3]]# define item category parametersA1[1,2,1] <- A1[1,3,2] <- A1[1,4,3] <- -1A1[2,2,4] <- A1[2,3,5] <- A1[2,4,6] <- -1A1[3,2,7] <- A1[3,3,8] <- -1A1[3,4,1:8] <- 1# check definitionA1[1,,]A1[2,,]A1[3,,]#** estimate modelmod2 <- TAM::tam.mml( dat, A=A1, beta.fixed=FALSE)summary(mod2, file="mod2")#--- compare model fitIRT.compareModels(mod1, mod2 ) # -> equivalent model fit############################################################################## EXAMPLE 25: Different GPCM parametrizations in IRT packages#############################################################################library(TAM)library(mirt)library(ltm)data(data.gpcm, package="TAM")dat <- data.gpcm#*** TAMmod1 <- TAM::tam.mml.2pl(dat, irtmodel="GPCM")#*** mirtmod2 <- mirt::mirt(dat, 1, itemtype="gpcm", verbose=TRUE)#*** ltmmod3 <- ltm::gpcm( dat, control=list(verbose=TRUE) )mod3b <- ltm::gpcm( dat, control=list(verbose=TRUE), IRT.param=FALSE)#-- comparison log likelihoodlogLik(mod1)logLik(mod2)logLik(mod3)logLik(mod3b)#*** intercept parametrization (like in TAM)# TAMmod1$B[,2,1] # slopemod1$AXsi # intercepts# mirtcoef(mod2)# ltmcoef(mod3b, IRT.param=FALSE)[, c(4,1:3)]#*** IRT parametrization# TAMmod1$AXsi / mod1$B[,2,1]# mirtcoef(mod2, IRTpars=TRUE)# ltmcoef(mod3)[, c(4,1:3)]############################################################################## EXAMPLE 26: Differential item functioning in multdimensional models#############################################################################data(data.ex08, package="TAM")formulaA <- ~ item+female+item*femaleresp <- data.ex08[["resp"]]facets <- as.data.frame(data.ex08[["facets"]])#*** Model 8a: investigate gender DIF in undimensional modelmod8a <- TAM::tam.mml.mfr(resp=resp, facets=facets, formulaA=formulaA)summary(mod8a)#*** multidimensional 2PL ModelI <- 10Q <- array(0, dim=c(I, 3))Q[cbind(1:I, c(rep(1, 3), rep(2, 3), rep(3, 4)))] <- 1rownames(Q) <- colnames(resp)mod3dim2pl <- TAM::tam.mml.2pl(resp=resp, Q=Q, irtmodel="2PL", control=list(snodes=2000))#*** Combine both approachesthisRows <- gsub("-.*", "", colnames(mod8a$resp)) #select item names#*** uniform DIF (note irtmodel="2PL.groups" & est.slopegroups)mod3dim2pl_udiff <- TAM::tam.mml.2pl(resp=mod8a$resp, A=mod8a$A, Q=Q[thisRows, ], irtmodel="2PL.groups", est.slopegroups=as.numeric(as.factor(thisRows)), control=list(snodes=2000))#*** non-uniform DIF (?); different slope parameters for each item administered to each groupmod3dim2pl_nudiff <- TAM::tam.mml.2pl(resp=mod8a$resp, A=mod8a$A, Q=Q[thisRows, ], irtmodel="2PL", control=list(snodes=2000))#*** check resultsprint(mod8a$xsi)print(mod3dim2pl_udiff$xsi)summary(mod3dim2pl_nudiff)#*** within item dimensionality (one item loads on two dimensions)Q2 <- QQ2[4,1] <- 1# uniform DIF (note irtmodel="2PL.groups" & est.slopegroups)mod3dim2pl_udiff2 <- TAM::tam.mml.2pl(resp=mod8a$resp, A=mod8a$A, Q=Q2[thisRows, ], irtmodel="2PL.groups", est.slopegroups=as.numeric(as.factor(thisRows)), control=list(snodes=2000))print(mod8a$xsi)print(mod3dim2pl_udiff2$xsi)print(mod3dim2pl_udiff2$xsi)############################################################################## EXAMPLE 27: IRT parameterization for generalized partial credit model (GPCM) in TAM##############################################################################--- read item parameterspars <- as.numeric(miceadds::scan.vec("0.19029 1.25309 0.51737 -1.77046 0.94803 0.19407 1.22680 0.34986 -1.57666 1.29726 -0.00888 1.07093 0.31662 -1.38755 1.14809 -0.33810 1.08205 0.48490 -1.56696 0.79547 -0.18866 0.99587 0.37880 -1.37468 0.81114" ))pars <- matrix( pars, nrow=5, byrow=TRUE)beta <- pars[,1]alpha <- pars[,5]tau <- pars[,2:4]#--- data simulation function for GPCMsim_gpcm_irt_param <- function(alpha, beta, tau, N, mu=0, sigma=1){ theta <- stats::rnorm(N, mean=mu, sd=sigma) I <- length(beta) K <- ncol(tau) dat <- matrix(0, nrow=N, ncol=I) colnames(dat) <- paste0("I",1:I) for (ii in 1:I){ probs <- matrix(0, nrow=N, ncol=K+1) for (kk in 1:K){ probs[,kk+1] <- probs[,kk] + alpha[ii]*( theta - beta[ii] - tau[ii,kk] ) } probs <- exp(probs) probs <- probs/rowSums(probs) rn <- stats::runif(N) cumprobs <- t(apply(probs,1,cumsum)) for (kk in 1:K){ dat[,ii] <- dat[,ii] + ( rn > cumprobs[,kk] ) } } return(dat)}#-- simulate dataN <- 20000 # number of personsset.seed(98)dat1 <- sim_gpcm_irt_param(alpha=alpha, beta=beta, tau=tau, N=N, mu=0, sigma=1)head(dat1)#* generate design matrix for IRT parameterizationA1 <- TAM::.A.PCM2( resp=dat1)#- estimate GPCM modelmod1 <- TAM::tam.mml.2pl( resp=dat1, irtmodel="GPCM", A=A1)summary(mod1)# compare true and estimated slope estimates (alpha)cbind( alpha, mod1$B[,2,] )# compare true and estimated item difficulties (beta)cbind( beta, mod1$xsi$xsi[1:5] / mod1$B[,2,1] )# compare true and estimated tau parameterscbind( tau[,-3], matrix( mod1$xsi$xsi[-c(1:5)], nrow=5, byrow=TRUE ) / mod1$B[,2,1] )## End(Not run)3PL Structured Item Response Model inTAM
Description
This estimates a 3PL model with design matrices for item slopes anditem intercepts. Discrete distributions of the latent variables areallowed which can be log-linearly smoothed.
Usage
tam.mml.3pl(resp, Y=NULL, group=NULL, formulaY=NULL, dataY=NULL, ndim=1, pid=NULL, xsi.fixed=NULL, xsi.inits=NULL, xsi.prior=NULL, beta.fixed=NULL, beta.inits=NULL, variance.fixed=NULL, variance.inits=NULL, est.variance=TRUE, A=NULL, notA=FALSE, Q=NULL, Q.fixed=NULL, E=NULL, gammaslope.des="2PL", gammaslope=NULL, gammaslope.fixed=NULL, est.some.slopes=TRUE, gammaslope.max=9.99, gammaslope.constr.V=NULL, gammaslope.constr.c=NULL, gammaslope.center.index=NULL, gammaslope.center.value=NULL, gammaslope.prior=NULL, userfct.gammaslope=NULL, gammaslope.constr.Npars=0, est.guess=NULL, guess=rep(0, ncol(resp)), guess.prior=NULL, max.guess=0.5, skillspace="normal", theta.k=NULL, delta.designmatrix=NULL, delta.fixed=NULL, delta.inits=NULL, pweights=NULL, item.elim=TRUE, verbose=TRUE, control=list(), Edes=NULL )## S3 method for class 'tam.mml.3pl'summary(object,file=NULL,...)## S3 method for class 'tam.mml.3pl'print(x,...)Arguments
resp | Data frame with polytomous item responses |
Y | A matrix of covariates in latent regression. Note that theintercept is automatically included as the first predictor. |
group | An optional vector of group identifiers |
formulaY | AnR formula for latent regression. Transformations of predictorsin |
dataY | An optional data frame with possible covariates |
ndim | Number of dimensions (is not needed to determined by the user) |
pid | An optional vector of person identifiers |
xsi.fixed | A matrix with two columns for fixing |
xsi.inits | A matrix with two columns (in the same way defined as in |
xsi.prior | Item-specific prior distribution for |
beta.fixed | A matrix with three columns for fixing regression coefficients.1st column: Index of |
beta.inits | A matrix (same format as in |
variance.fixed | An optional matrix. In case of a single group it is a matrix with three columns for fixingentries in covariance matrix:1st column: dimension 1, 2nd column: dimension 2,3rd column: fixed value of covariance/variance.In case of multiple groups, it is a matrix with four columns1st column: group index (from |
variance.inits | Initial covariance matrix in estimation. All matrix entries have to bespecified and this matrix is NOT in the same format like |
est.variance | Should the covariance matrix be estimated? This argumentapplies to estimated item slopes in |
A | An optional array of dimension |
notA | An optional logical indicating whether all entries inthe |
Q | An optional |
Q.fixed | Optional |
E | Optional design array for item slopes |
gammaslope.des | Optional string indicating type of item slope parameter to be estimated. |
gammaslope | Initial or fixed vector of |
gammaslope.fixed | An optional matrix containing fixed values in the |
est.some.slopes | An optional logical indicating whether some item slopes should be estimated. |
gammaslope.max | Value for absolute entries in |
gammaslope.constr.V | An optional constraint matrix |
gammaslope.constr.c | An optional constraint vector |
gammaslope.center.index | Indices of |
gammaslope.center.value | Specified values of sum ofsubset of |
gammaslope.prior | Item-specific prior distribution for |
userfct.gammaslope | A user specified function forconstraints or transformations of the |
gammaslope.constr.Npars | Number of constrained |
est.guess | An optional vector of integers indicating for which items a guessingparameter should be estimated. Same integers correspond to same estimatedguessing parameters. A value of 0 denotes an item for which no guessingparameter is estimated. |
guess | Fixed or initial guessing parameters |
guess.prior | Item-specific prior distribution for guessing parameters |
max.guess | Upper bound for guessing parameters |
skillspace | Skill space: normal distribution ( |
theta.k | A matrix of the |
delta.designmatrix | A design matrix of the log-linear model for the skill space in case of a discretedistribution ( |
delta.fixed | Fixed |
delta.inits | Optional initial matrix of |
pweights | Optional vector of person weights. |
item.elim | Optional logical indicating whether an item with hasonly zero entries should be removed from the analysis. The defaultis |
verbose | Logical indicating whether output shouldbe printed during iterations. This argument replaces |
control | See |
Edes | Compact form of design matrix. This argument is onlydefined for convenience for models with random startingvalues to avoid recalculations. |
object | Object of class |
file | A file name in which the summary output will be written |
x | Object of class |
... | Further arguments to be passed |
Details
The item response model for itemi and categoryh and no guessingparameters can be written as
P( X_{i}=h | \bold{\theta} ) \propto \exp( \sum_d b_{ihd} \theta_d + \sum_k a_{ih} \xi_k )
For item slopes, a linear decomposition is allowed
b_{ihd}=\sum_k e_{ihdk} \gamma_k
In case of a guessing parameter, the item response function is
P( X_{i}=h | \bold{\theta} )=c_i + ( 1 - c_i ) \cdot ( 1 + \exp( - \sum_d b_{ihd} \theta_d - \sum_k a_{ih} \xi_k ) )^{-1}
For possibilities of definitions of the design matrixE=(e_{ihdk})see Formann (2007), for the strongly related linear logistic latentclass model see Formann (1992). Linear constraints on\gammacan be specified by equationsV \gamma=c and using the argumentsgammaslope.constr.V andgammaslope.constr.c.
Like intam.mml, a multivariate linear regression
\bold{\theta}=Y \beta + \bold{\epsilon}
assuming a multivariate normal distribution on the residuals\bold{\epsilon}can be specified (skillspace="normal").
Alternatively, a log-linear distribution of the skill classesP(\theta)(skillspace="discrete")is performed
\log P(\theta )=D_{ \delta } \delta
See Xu andvon Davier (2008). The design matrixD_{\delta} can be specified indelta.designmatrix. The theta grid\bold{\theta} of the skill spacecan be defined intheta.k.
Value
The same output as intam.mml and additional entries
delta | Parameter vector |
gammaslope | Estimated |
se.gammaslope | Standard errors |
E | Used design matrix |
Edes | Used design matrix |
guess | Estimated |
se.guess | Standard errors |
Note
The implementation of the model builds on pieces work of Anton Formann.Seehttp://www.antonformann.at/ for more information.
References
Formann, A. K. (1992). Linear logistic latent class analysis for polytomous data.Journal of the American Statistical Association, 87, 476-486.doi:10.2307/2290280
Formann, A. K. (2007). (Almost) Equivalence between conditional and mixture maximumlikelihood estimates for some models of the Rasch type. In M. von Davier & C. H. Carstensen(Eds.),Multivariate and mixture distribution Rasch models (pp. 177-189).New York: Springer.doi:10.1007/978-0-387-49839-3_11
Xu, X., & von Davier, M. (2008).Fitting the structured general diagnosticmodel to NAEP data. ETS Research Report ETS RR-08-27. Princeton, ETS.doi:10.1002/j.2333-8504.2008.tb02113.x
See Also
See alsotam.mml.
See theCDM::slca function in theCDM packagefor a similar method.
Examples
## Not run: ############################################################################## EXAMPLE 1: Dichotomous data | data.sim.rasch#############################################################################data(data.sim.rasch)dat <- data.sim.rasch# some control argumentsctl.list <- list(maxiter=100) # increase the number of iterations in applications!#*** Model 1: Rasch model, normal trait distributionmod1 <- TAM::tam.mml.3pl(resp=dat, skillspace="normal", est.some.slopes=FALSE, control=ctl.list)summary(mod1)#*** Model 2: Rasch model, discrete trait distribution# choose theta gridtheta.k <- seq( -3, 3, len=7 ) # discrete theta grid distribution# define symmetric trait distributiondelta.designmatrix <- matrix( 0, nrow=7, ncol=4 )delta.designmatrix[4,1] <- 1delta.designmatrix[c(3,5),2] <- 1delta.designmatrix[c(2,6),3] <- 1delta.designmatrix[c(1,7),4] <- 1mod2 <- TAM::tam.mml.3pl(resp=dat, skillspace="discrete", est.some.slopes=FALSE, theta.k=theta.k, delta.designmatrix=delta.designmatrix, control=ctl.list)summary(mod2)#*** Model 3: 2PL modelmod3 <- TAM::tam.mml.3pl(resp=dat, skillspace="normal", gammaslope.des="2PL", control=ctl.list, est.variance=FALSE )summary(mod3)#*** Model 4: 3PL model# estimate guessing parameters for items 3,7,9 and 12I <- ncol(dat)est.guess <- rep(0, I )# set parameters 9 and 12 equal -> same integersest.guess[ c(3,7,9,12) ] <- c( 1, 3, 2, 2 )# starting values guessing parameterguess <- .2*(est.guess > 0)# estimate modelmod4 <- TAM::tam.mml.3pl(resp=dat, skillspace="normal", gammaslope.des="2PL", control=ctl.list, est.guess=est.guess, guess=guess, est.variance=FALSE)summary(mod4)#--- specification in tamaantammodel <- "LAVAAN MODEL: F1=~ I1__I40 F1 ~~ 1*F1 I3 + I7 ?=g1 I9 + I12 ?=g912 * g1 "mod4a <- TAM::tamaan( tammodel, resp=dat, control=list(maxiter=20))summary(mod4a)#*** Model 5: 3PL model, add some prior Beta distributionguess.prior <- matrix( 0, nrow=I, ncol=2 )guess.prior[ est.guess > 0, 1] <- 5guess.prior[ est.guess > 0, 2] <- 17mod5 <- TAM::tam.mml.3pl(resp=dat, skillspace="normal", gammaslope.des="2PL", control=ctl.list, est.guess=est.guess, guess=guess, guess.prior=guess.prior)summary(mod5)#--- specification in tamaantammodel <- "LAVAAN MODEL: F1=~ I1__I40 F1 ~~ 1*F1 I3 + I7 ?=g1 I9 + I12 ?=g912 * g1MODEL PRIOR: g912 ~ Beta(5,17) I3_guess ~ Beta(5,17) I7_guess ~ Beta(5,17) "mod5a <- TAM::tamaan( tammodel, resp=dat, control=list(maxiter=20))#*** Model 6: 2PL model with design matrix for item slopesI <- 40 # number of itemsD <- 1 # dimensionsmaxK <- 2 # maximum number of categoriesNgam <- 13 # number of different slope parametersE <- array( 0, dim=c(I,maxK,D,Ngam) )# joint slope parameters for items 1 to 10, 11 to 20, 21 to 30E[ 1:10, 2, 1, 2 ] <- 1E[ 11:20, 2, 1, 1 ] <- 1E[ 21:30, 2, 1, 3 ] <- 1for (ii in 31:40){ E[ii,2,1,ii - 27 ] <- 1 }# estimate modelmod6 <- TAM::tam.mml.3pl(resp=dat, control=ctl.list, E=E, est.variance=FALSE )summary(mod6)#*** Model 6b: Truncated normal prior distribution for slope parametersgammaslope.prior <- matrix( 0, nrow=Ngam, ncol=4 )gammaslope.prior[,1] <- 2 # meangammaslope.prior[,2] <- 10 # standard deviationgammaslope.prior[,3] <- -Inf # lower boundgammaslope.prior[ 4:13,3] <- 1.2gammaslope.prior[,4] <- Inf # upper bound# estimate modelmod6b <- TAM::tam.mml.3pl(resp=dat, E=E, est.variance=FALSE, gammaslope.prior=gammaslope.prior, control=ctl.list )summary(mod6b)#*** Model 7: 2PL model with design matrix of slopes and slope constraintsNgam <- dim(E)[4] # number of gamma parameters# define two constraint equationsgammaslope.constr.V <- matrix( 0, nrow=Ngam, ncol=2 )gammaslope.constr.c <- rep(0,2)# set sum of first two xlambda entries to 1.8gammaslope.constr.V[1:2,1] <- 1gammaslope.constr.c[1] <- 1.8# set sum of entries 4, 5 and 6 to 3gammaslope.constr.V[4:6,2] <- 1gammaslope.constr.c[2] <- 3mod7 <- TAM::tam.mml.3pl(resp=dat, control=ctl.list, E=E, est.variance=FALSE, gammaslope.constr.V=gammaslope.constr.V, gammaslope.constr.c=gammaslope.constr.c)summary(mod7)#**** Model 8: Located latent class Rasch model with estimated three skill points# three classes of theta's are estimatedTP <- 3theta.k <- diag(TP)# because item difficulties are unrestricted, we define the sum of the estimated# theta points equal to zeroNgam <- TP # estimate three gamma loading parameters which are discrete theta pointsE <- array( 0, dim=c(I,2,TP,Ngam) )E[,2,1,1] <- E[,2,2,2] <- E[,2,3,3] <- 1gammaslope.constr.V <- matrix( 1, nrow=3, ncol=1 )gammaslope.constr.c <- c(0)# initial gamma valuesgammaslope <- c( -2, 0, 2 )# estimate modelmod8 <- TAM::tam.mml.3pl(resp=dat, control=ctl.list, E=E, skillspace="discrete", theta.k=theta.k, gammaslope=gammaslope, gammaslope.constr.V=gammaslope.constr.V, gammaslope.constr.c=gammaslope.constr.c )summary(mod8)#*** Model 9: Multidimensional multiple group modelN <- nrow(dat)I <- ncol(dat)group <- c( rep(1,N/4), rep(2,N/4), rep(3,N/2) )Q <- matrix(0,nrow=I,ncol=2)Q[ 1:(I/2), 1] <- Q[ seq(I/2+1,I), 2] <- 1# estimate modelmod9 <- TAM::tam.mml.3pl(resp=dat, skillspace="normal", est.some.slopes=FALSE, group=group, Q=Q)summary(mod9)############################################################################## EXAMPLE 2: Polytomous data#############################################################################data( data.mg, package="CDM")dat <- data.mg[1:1000, paste0("I",1:11)]#*******************************************************#*** Model 1: 1-dimensional 1PL estimation, normal skill distributionmod1 <- TAM::tam.mml.3pl(resp=dat, skillspace="normal", gammaslope.des="2PL", est.some.slopes=FALSE, est.variance=TRUE )summary(mod1)#*******************************************************#*** Model 2: 1-dimensional 2PL estimation, discrete skill distribution# define skill spacetheta.k <- matrix( seq(-5,5,len=21) )# allow skew skill distributiondelta.designmatrix <- cbind( 1, theta.k, theta.k^2, theta.k^3 )# fix 13th xsi item parameter to zeroxsi.fixed <- cbind( 13, 0 )# fix 10th slope paremeter to onegammaslope.fixed <- cbind( 10, 1 )# estimate modelmod2 <- TAM::tam.mml.3pl(resp=dat, skillspace="discrete", theta.k=theta.k, delta.designmatrix=delta.designmatrix, gammaslope.des="2PL", xsi.fixed=xsi.fixed, gammaslope.fixed=gammaslope.fixed)summary(mod2)#*******************************************************#*** Model 3: 2-dimensional 2PL estimation, normal skill distribution# define loading matrixQ <- matrix(0,11,2)Q[1:6,1] <- 1 # items 1 to 6 load on dimension 1Q[7:11,2] <- 1 # items 7 to 11 load on dimension 2# estimate modelmod3 <- TAM::tam.mml.3pl(resp=dat, gammaslope.des="2PL", Q=Q )summary(mod3)############################################################################## EXAMPLE 3: Dichotomous data with guessing##############################################################################*** simulate dataset.seed(9765)N <- 4000 # number of personsI <- 20 # number of itemsb <- seq( -1.5, 1.5, len=I )guess <- rep(0, I )guess.items <- c(6,11,16)guess[ guess.items ] <- .33library(sirt)dat <- sirt::sim.raschtype( stats::rnorm(N), b=b, fixed.c=guess )#*******************************************************#*** Model 1: Difficulty + guessing model, i.e. fix slopes to 1est.guess <- rep(0,I)est.guess[ guess.items ] <- seq(1, length(guess.items) )# define prior distributionguess.prior <- matrix( cbind( 5, 17 ), I, 2, byrow=TRUE )guess.prior[ ! est.guess, ] <- 0# estimate modelmod1 <- TAM::tam.mml.3pl(resp=dat, guess=guess, est.guess=est.guess, guess.prior=guess.prior, control=ctl.list,est.variance=TRUE, est.some.slopes=FALSE )summary(mod1)#*******************************************************#*** Model 2: estimate a joint guessing parameterest.guess <- rep(0,I)est.guess[ guess.items ] <- 1# estimate modelmod2 <- TAM::tam.mml.3pl(resp=dat, guess=guess, est.guess=est.guess, guess.prior=guess.prior, control=ctl.list,est.variance=TRUE, est.some.slopes=FALSE )summary(mod2)############################################################################## EXAMPLE 4: Latent class model with two classes# See slca Simulated Example 2 in the CDM package##############################################################################*******************************************************#*** simulate dataset.seed(9876)I <- 7 # number of items# simulate response probabilitiesa1 <- round( stats::runif(I,0, .4 ),4)a2 <- round( stats::runif(I, .6, 1 ),4)N <- 1000 # sample size# simulate data in two classes of proportions .3 and .7N1 <- round(.3*N)dat1 <- 1 * ( matrix(a1,N1,I,byrow=TRUE) > matrix( stats::runif( N1 * I), N1, I ) )N2 <- round(.7*N)dat2 <- 1 * ( matrix(a2,N2,I,byrow=TRUE) > matrix( stats::runif( N2 * I), N2, I ) )dat <- rbind( dat1, dat2 )colnames(dat) <- paste0("I", 1:I)#*******************************************************# estimation using tam.mml.3pl function# define design matricesTP <- 2 # two classestheta.k <- diag(TP) # there are theta dimensions -> two classes# The idea is that latent classes refer to two different "dimensions".# Items load on latent class indicators 1 and 2, see below.E <- array(0, dim=c(I,2,2,2*I) )items <- colnames(dat)dimnames(E)[[4]] <- c(paste0( colnames(dat), "Class", 1), paste0( colnames(dat), "Class", 2) )# items, categories, classes, parameters# probabilities for correct solutionfor (ii in 1:I){ E[ ii, 2, 1, ii ] <- 1 # probabilities class 1 E[ ii, 2, 2, ii+I ] <- 1 # probabilities class 2 }# estimation commandmod1 <- TAM::tam.mml.3pl(resp=dat, E=E, control=list(maxit=20), skillspace="discrete", theta.k=theta.k, notA=TRUE)summary(mod1)# compare simulated and estimated datacbind( mod1$rprobs[,2,1], a2 ) # Simulated class 2cbind( mod1$rprobs[,2,2], a1 ) # Simulated class 1#*******************************************************#** specification with tamaantammodel <- "ANALYSIS: TYPE=LCA; NCLASSES(2); # 2 classes NSTARTS(5,20); # 5 random starts with 20 iterationsLAVAAN MODEL: F=~ I1__I7 "mod1b <- TAM::tamaan( tammodel, resp=dat )summary(mod1b)# compare with mod1logLik(mod1)logLik(mod1b)############################################################################## EXAMPLE 5: Located latent class model, Rasch model# See slca Simulated Example 4 in the CDM package##############################################################################*** simulate dataset.seed(487)I <- 15 # I itemsb1 <- seq( -2, 2, len=I) # item difficultiesN <- 2000 # number of persons# simulate 4 theta classestheta0 <- c( -2.5, -1, 0.3, 1.3 ) # skill classesprobs0 <- c( .1, .4, .2, .3 ) # skill class probabilitiesTP <- length(theta0)theta <- theta0[ rep(1:TP, round(probs0*N) ) ]library(sirt)dat <- sirt::sim.raschtype( theta, b1 )colnames(dat) <- paste0("I",1:I)#*******************************************************#*** Model 1: Located latent class model with 4 classesmaxK <- 2Ngam <- TPE <- array( 0, dim=c(I, maxK, TP, Ngam ) )dimnames(E)[[1]] <- colnames(dat)dimnames(E)[[2]] <- paste0("Cat", 1:(maxK) )dimnames(E)[[3]] <- paste0("Class", 1:TP)dimnames(E)[[4]] <- paste0("theta", 1:TP)# theta designfor (tt in 1:TP){ E[1:I, 2, tt, tt] <- 1 }theta.k <- diag(TP)# set eighth item difficulty to zeroxsi.fixed <- cbind( 8, 0 )# initial gamma parametergammaslope <- seq( -1.5, 1.5, len=TP)# estimate modelmod1 <- TAM::tam.mml.3pl(resp=dat, E=E, xsi.fixed=xsi.fixed, control=list(maxiter=100), skillspace="discrete", theta.k=theta.k, gammaslope=gammaslope)summary(mod1)# compare estimated and simulated theta class locationscbind( mod1$gammaslope, theta0 )# compare estimated and simulated latent class proportionscbind( mod1$pi.k, probs0 )#----- specification using tamaantammodel <- "ANALYSIS: TYPE=LOCLCA; NCLASSES(4)LAVAAN MODEL: F=~ I1__I15 I8 | 0*t1 "mod1b <- TAM::tamaan( tammodel, resp=dat )summary(mod1b)############################################################################## EXAMPLE 6: DINA model with two skills# See slca Simulated Example 5 in the CDM package##############################################################################*** simulate dataset.seed(487)N <- 3000 # number of persons# define Q-matrixI <- 9 # 9 itemsNS <- 2 # 2 skillsTP <- 4 # number of skill classesQ <- scan(nlines=3, text= "1 0 1 0 1 0 0 1 0 1 0 1 1 1 1 1 1 1", )Q <- matrix(Q, I, ncol=NS, byrow=TRUE)# define skill distributionalpha0 <- matrix( c(0,0,1,0,0,1,1,1), nrow=4,ncol=2,byrow=TRUE)prob0 <- c( .2, .4, .1, .3 )alpha <- alpha0[ rep( 1:TP, prob0*N),]# define guessing and slipping parametersguess <- round( stats::runif(I, 0, .4 ), 2 )slip <- round( stats::runif(I, 0, .3 ), 2 )# simulate data according to the DINA modeldat <- CDM::sim.din( q.matrix=Q, alpha=alpha, slip=slip, guess=guess )$dat#*** Model 1: Estimate DINA model# define E matrix which contains the anti-slipping parametersmaxK <- 2Ngam <- IE <- array( 0, dim=c(I, maxK, TP, Ngam ) )dimnames(E)[[1]] <- colnames(dat)dimnames(E)[[2]] <- paste0("Cat", 1:(maxK) )dimnames(E)[[3]] <- c("S00","S10","S01","S11")dimnames(E)[[4]] <- paste0( "antislip", 1:I )# define anti-slipping parameters in Efor (ii in 1:I){ # define latent responses latresp <- 1*( alpha0 %*% Q[ii,]==sum(Q[ii,]) )[,1] # model slipping parameters E[ii, 2, latresp==1, ii ] <- 1 }# skill space definitiontheta.k <- diag(TP)gammaslope <- rep( qlogis( .8 ), I )# estimate modelmod1 <- TAM::tam.mml.3pl(resp=dat, E=E, control=list(maxiter=100), skillspace="discrete", theta.k=theta.k, gammaslope=gammaslope)summary(mod1)# compare estimated and simulated latent class proportionscbind( mod1$pi.k, probs0 )# compare estimated and simulated guessing parameterscbind( mod1$rprobs[,2,1], guess )# compare estimated and simulated slipping parameterscbind( 1 - mod1$rprobs[,2,4], slip )############################################################################## EXAMPLE 7: Mixed Rasch model with two classes# See slca Simulated Example 3 in the CDM package##############################################################################*** simulate dataset.seed(987)library(sirt)# simulate two latent classes of Rasch populationsI <- 15 # 6 itemsb1 <- seq( -1.5, 1.5, len=I) # difficulties latent class 1b2 <- b1 # difficulties latent class 2b2[ c(4,7, 9, 11, 12, 13) ] <- c(1, -.5, -.5, .33, .33, -.66 )b2 <- b2 - mean(b2)N <- 3000 # number of personswgt <- .25 # class probability for class 1# class 1dat1 <- sirt::sim.raschtype( stats::rnorm( wgt*N ), - b1 )# class 2dat2 <- sirt::sim.raschtype( stats::rnorm( (1-wgt)*N, mean=1, sd=1.7), - b2 )dat <- rbind( dat1, dat2 )# The idea is that each grid point class x theta is defined as new# dimension. If we approximate the trait distribution by 7 theta points# and are interested in estimating 2 latent classes, then we need# 7*2=14 dimensions.#*** Model 1: Rasch model# theta gridtheta.k1 <- seq( -5, 5, len=7 )TT <- length(theta.k1)#-- define theta design matrixtheta.k <- diag(TT)#-- delta designmatrixdelta.designmatrix <- matrix( 0, TT, ncol=3 )delta.designmatrix[, 1] <- 1delta.designmatrix[, 2:3] <- cbind( theta.k1, theta.k1^2 )#-- define loading matrix EE <- array( 0, dim=c(I,2,TT,I + 1) ) # last parameter is constant 1for (ii in 1:I){ E[ ii, 2, 1:TT, ii ] <- -1 # '-b' in '1*theta - b' E[ ii, 2, 1:TT, I+1] <- theta.k1 # '1*theta' in '1*theta - b' }# initial gammaslope parameterspar1 <- stats::qlogis( colMeans( dat ) )gammaslope <- c( par1, 1 )# sum constraint of zero on item difficultiesgammaslope.constr.V <- matrix( 0, I+1, 1 )gammaslope.constr.V[ 1:I, 1] <- 1 # Class 1gammaslope.constr.c <- c(0)# fixed gammaslope parametergammaslope.fixed <- cbind( I+1, 1 )# estimate modelmod1 <- TAM::tam.mml.3pl(resp=dat1, E=E, skillspace="discrete", theta.k=theta.k, delta.designmatrix=delta.designmatrix, gammaslope=gammaslope, gammaslope.constr.V=gammaslope.constr.V, gammaslope.constr.c=gammaslope.constr.c, gammaslope.fixed=gammaslope.fixed, notA=TRUE, est.variance=FALSE)summary(mod1)#*** Model 2: Mixed Rasch model with two latent classes# theta gridtheta.k1 <- seq( -4, 4, len=7 )TT <- length(theta.k1)#-- define theta design matrixtheta.k <- diag(2*TT) # 2*7=14 classes#-- delta designmatrixdelta.designmatrix <- matrix( 0, 2*TT, ncol=6 )# Class 1delta.designmatrix[1:TT, 1] <- 1delta.designmatrix[1:TT, 2:3] <- cbind( theta.k1, theta.k1^2 )# Class 2delta.designmatrix[TT+1:TT, 4] <- 1delta.designmatrix[TT+1:TT, 5:6] <- cbind( theta.k1, theta.k1^2 )#-- define loading matrix EE <- array( 0, dim=c(I,2,2*TT,2*I + 1) ) # last parameter is constant 1dimnames(E)[[1]] <- colnames(dat)dimnames(E)[[2]] <- c("Cat0","Cat1")dimnames(E)[[3]] <- c( paste0("Class1_theta", 1:TT), paste0("Class2_theta", 1:TT) )dimnames(E)[[4]] <- c( paste0("b_Class1_", colnames(dat)), paste0("b_Class2_", colnames(dat)), "One")for (ii in 1:I){ # Class 1 item parameters E[ ii, 2, 1:TT, ii ] <- -1 # '-b' in '1*theta - b' E[ ii, 2, 1:TT, 2*I+1] <- theta.k1 # '1*theta' in '1*theta - b' # Class 2 item parameters E[ ii, 2, TT + 1:TT, I + ii ] <- -1 E[ ii, 2, TT + 1:TT, 2*I+1] <- theta.k1 }# initial gammaslope parameterspar1 <- qlogis( colMeans( dat ) )gammaslope <- c( par1, par1 + stats::runif(I, -2,2 ), 1 )# sum constraint of zero on item difficulties within a classgammaslope.center.index <- c( rep( 1, I ), rep(2,I), 0 )gammaslope.center.value <- c(0,0)# estimate modelmod1 <- TAM::tam.mml.3pl(resp=dat, E=E, skillspace="discrete", theta.k=theta.k, delta.designmatrix=delta.designmatrix, gammaslope=gammaslope, gammaslope.center.index=gammaslope.center.index, gammaslope.center.value=gammaslope.center.value, gammaslope.fixed=gammaslope.fixed, notA=TRUE)summary(mod1)# latent class proportionsstats::aggregate( mod1$pi.k, list( rep(1:2, each=TT)), sum )# compare simulated and estimated item parameterscbind( b1, b2, - mod1$gammaslope[1:I], - mod1$gammaslope[I + 1:I ] )#--- specification in tamaantammodel <- "ANALYSIS: TYPE=MIXTURE; NCLASSES(2) NSTARTS(5,30)LAVAAN MODEL: F=~ I0001__I0015ITEM TYPE: ALL(Rasch); "mod1b <- TAM::tamaan( tammodel, resp=dat )summary(mod1b)############################################################################## EXAMPLE 8: 2PL mixture distribution model##############################################################################*** simulate dataset.seed(9187)library(sirt)# simulate two latent classes of Rasch populationsI <- 20b1 <- seq( -1.5, 1.5, len=I) # difficulties latent class 1b2 <- b1 # difficulties latent class 2b2[ c(4,7, 9, 11, 12, 13, 16, 18) ] <- c(1, -.5, -.5, .33, .33, -.66, -1, .3)# b2 <- scale( b2, scale=FALSE)b2 <- b2 - mean(b2)N <- 4000 # number of personswgt <- .75 # class probability for class 1# item slopesa1 <- rep( 1, I ) # first classa2 <- rep( c(.5,1.5), I/2 )# class 1dat1 <- sirt::sim.raschtype( stats::rnorm( wgt*N ), - b1, fixed.a=a1)# class 2dat2 <- sirt::sim.raschtype( stats::rnorm( (1-wgt)*N, mean=1, sd=1.4), - b2, fixed.a=a2)dat <- rbind( dat1, dat2 )#*** Model 1: Mixed 2PL model with two latent classestheta.k1 <- seq( -4, 4, len=7 )TT <- length(theta.k1)#-- define theta design matrixtheta.k <- diag(2*TT) # 2*7=14 classes#-- delta designmatrixdelta.designmatrix <- matrix( 0, 2*TT, ncol=6 )# Class 1delta.designmatrix[1:TT, 1] <- 1delta.designmatrix[1:TT, 2:3] <- cbind( theta.k1, theta.k1^2 )# Class 2delta.designmatrix[TT+1:TT, 4] <- 1delta.designmatrix[TT+1:TT, 5:6] <- cbind( theta.k1, theta.k1^2 )#-- define loading matrix EE <- array( 0, dim=c(I,2,2*TT,4*I ) )dimnames(E)[[1]] <- colnames(dat)dimnames(E)[[2]] <- c("Cat0","Cat1")dimnames(E)[[3]] <- c( paste0("Class1_theta", 1:TT), paste0("Class2_theta", 1:TT) )dimnames(E)[[4]] <- c( paste0("b_Class1_", colnames(dat)), paste0("a_Class1_", colnames(dat)), paste0("b_Class2_", colnames(dat)), paste0("a_Class2_", colnames(dat)) )for (ii in 1:I){ # Class 1 item parameters E[ ii, 2, 1:TT, ii ] <- -1 # '-b' in 'a*theta - b' E[ ii, 2, 1:TT, I + ii] <- theta.k1 # 'a*theta' in 'a*theta - b' # Class 2 item parameters E[ ii, 2, TT + 1:TT, 2*I + ii ] <- -1 E[ ii, 2, TT + 1:TT, 3*I + ii ] <- theta.k1}# initial gammaslope parameterspar1 <- scale( - stats::qlogis( colMeans( dat ) ), scale=FALSE )gammaslope <- c( par1, rep(1,I), scale( par1 + runif(I, - 1.4, 1.4 ), scale=FALSE), stats::runif( I,.6,1.4) )# constraint matrixgammaslope.constr.V <- matrix( 0, 4*I, 4 )# sum of item intercepts equals zerogammaslope.constr.V[ 1:I, 1] <- 1 # Class 1 (b)gammaslope.constr.V[ 2*I + 1:I, 2] <- 1 # Class 2 (b)# sum of item slopes equals number of items -> mean slope of 1gammaslope.constr.V[ I + 1:I, 3] <- 1 # Class 1 (a)gammaslope.constr.V[ 3*I + 1:I, 4] <- 1 # Class 2 (a)gammaslope.constr.c <- c(0,0,I,I)# estimate modelmod1 <- TAM::tam.mml.3pl(resp=dat, E=E, control=list(maxiter=80), skillspace="discrete", theta.k=theta.k, delta.designmatrix=delta.designmatrix, gammaslope=gammaslope, gammaslope.constr.V=gammaslope.constr.V, gammaslope.constr.c=gammaslope.constr.c, gammaslope.fixed=gammaslope.fixed, notA=TRUE)# estimated item parametersmod1$gammaslope# summarysummary(mod1)# latent class proportionsround( stats::aggregate( mod1$pi.k, list( rep(1:2, each=TT)), sum ), 3 )# compare simulated and estimated item interceptsint <- cbind( b1*a1, b2 * a2, - mod1$gammaslope[1:I], - mod1$gammaslope[2*I + 1:I ] )round( int, 3 )# simulated and estimated item slopesslo <- cbind( a1, a2, mod1$gammaslope[I+1:I], mod1$gammaslope[3*I + 1:I ] )round(slo,3)#--- specification in tamaantammodel <- "ANALYSIS: TYPE=MIXTURE; NCLASSES(2) NSTARTS(10,25)LAVAAN MODEL: F=~ I0001__I0020 "mod1t <- TAM::tamaan( tammodel, resp=dat )summary(mod1t)############################################################################## EXAMPLE 9: Toy example: Exact representation of an item by a factor#############################################################################data(data.gpcm)dat <- data.gpcm[,1,drop=FALSE ] # choose first item# some descriptives( t1 <- table(dat) )# The idea is that we define an IRT model with one latent variable# which extactly corresponds to the manifest item.I <- 1 # 1 itemK <- 4 # 4 categoriesTP <- 4 # 4 discrete theta points# define skill spacetheta.k <- diag(TP)# define loading matrix EE <- array( -99, dim=c(I,K,TP,1 ) )for (vv in 1:K){ E[ 1, vv, vv, 1 ] <- 9 }# estimate modelmod1 <- TAM::tam.mml.3pl(resp=dat, E=E, skillspace="discrete", theta.k=theta.k, notA=TRUE)summary(mod1)# -> the latent distribution corresponds to the manifest distribution, because ...round( mod1$pi.k, 3 )round( t1 / sum(t1), 3 )############################################################################## EXAMPLE 10: Some fixed item loadings#############################################################################data(data.Students,package="CDM")dat <- data.Students# select variablesvars <- scan( nlines=1, what="character") act1 act2 act3 act4 act5 sc1 sc2 sc3 sc4dat <- data.Students[, vars ]# define loading matrix: two-dimensional modelQ <- matrix( 0, nrow=9, ncol=2 )Q[1:5,1] <- 1Q[6:9,2] <- 1# define some fixed item loadingsQ.fixed <- NA*QQ.fixed[ c(1,4), 1] <- .5Q.fixed[ 6:7, 2 ] <- 1# estimate modelmod3 <- TAM::tam.mml.3pl( resp=dat, gammaslope.des="2PL", Q=Q, Q.fixed=Q.fixed, control=list( maxiter=10, nodes=seq(-4,4,len=10) ) )summary(mod3)############################################################################## EXAMPLE 11: Mixed response formats - Multiple choice and partial credit items#############################################################################data(data.timssAusTwn.scored)dat <- data.timssAusTwn.scored# select columns with item responsesdat <- dat[, grep("M0", colnames(dat) ) ]I <- ncol(dat) # number of items# The idea is to start with partial credit modelling# and then to include the guessing parameters#*** Model 0: Partial Credit Modelmod0 <- TAM::tam.mml(dat)summary(mod0)#*** Model 1 and Model 2: include guessing parameters# multiple choice itemsguess_items <- which( apply( dat, 2, max, na.rm=TRUE )==1 )# define guessing parametersguess0 <- rep(0,I)guess0[ guess_items ] <- .25 # set guessing probability to .25# define which guessing parameters should be estimatedest.guess1 <- rep(0,I) # all parameters are fixedest.guess2 <- 1 * ( guess0==.25 ) # joint guessing parameter# use design matrix from partial credit modelA0 <- mod0$A#--- Model 1: fixed guessing parameters of .25 and item slopes of 1mod1 <- TAM::tam.mml.3pl( dat, guess=guess0, est.guess=est.guess1, A=A0, est.some.slopes=FALSE, control=list(maxiter=50) )summary(mod1)#--- Model 2: estimate joint guessing parameters and item slopes of 1mod2 <- TAM::tam.mml.3pl( dat, guess=guess0, est.guess=est.guess2, A=A0, est.some.slopes=FALSE, control=list(maxiter=50) )summary(mod2)# model comparisonIRT.compareModels(mod0,mod1,mod2)## End(Not run)Model Fit Statistics inTAM
Description
The functiontam.modelfit computes several model fit statistics.It includes the Q3 statistic (Yen, 1984) and anadjusted variant of it (see Details). Effect sizes of model fit(MADaQ3,MADRESIDCOV,SRMR) are also available.
The functionIRT.modelfit is a wrapper totam.modelfit,but allows convenient model comparisons by using theCDM::IRT.compareModels function.
Thetam.modelfit function can also be used for fittedmodels outside theTAM package by applyingtam.modelfit.IRT ortam.modelfit.args.
The functiontam.Q3 computes theQ_3 statistic based onweighted likelihood estimates (seetam.wle).
Usage
tam.modelfit(tamobj, progress=TRUE)## S3 method for class 'tam.modelfit'summary(object,...)## S3 method for class 'tam.mml'IRT.modelfit(object, ...)## S3 method for class 'tam.mml.3pl'IRT.modelfit(object, ...)## S3 method for class 'tamaan'IRT.modelfit(object, ...)## S3 method for class 'IRT.modelfit.tam.mml'summary(object, ...)## S3 method for class 'IRT.modelfit.tam.mml.3pl'summary(object, ...)## S3 method for class 'IRT.modelfit.tamaan'summary(object, ...)tam.modelfit.IRT( object, progress=TRUE )tam.modelfit.args( resp, probs, theta, post, progress=TRUE )tam.Q3(tamobj, ... )## S3 method for class 'tam.Q3'summary(object,...)Arguments
tamobj | Object of class |
progress | An optional logical indicating whether progress shouldbe displayed |
object | Object of class |
resp | Dataset with item responses |
probs | Array with item response functions evaluated at |
theta | Matrix with used |
post | Individual posterior distribution |
... | Further arguments to be passed |
Details
For each itemi and each personn, residualse_{ni}=X_{ni}-E(X_{ni}) are computed. The expectedvalueE(X_{ni}) is obtained by integrating the individualposterior distribution.
The Q3 statistic of item pairsi andj is defined as thecorrelationQ3_{ij}=Cor( e_{ni}, e_{nj} ). The residuals intam.modelfit arecalculated by integrating values of the individual posterior distribution.Residuals intam.Q3 are calculated by using weighted likelihoodestimates (WLEs) fromtam.wle.
It is known that under local independence, the expected value ofQ_3is slightly smaller than zero. Therefore,an adjusted Q3 statistic (aQ3;aQ3_{ij})is computed by subtracting the average of all Q3 statistics fromQ3. To control for multiple testing,a p value adjustment by the method ofHolm (p.holm) is employed (see Chen, de la Torre & Zhang, 2013).
An effect size of model fit (MADaQ3) is defined asthe average of absolute values ofaQ3 statistics. An equivalentstatistic based on theQ_3 statistic is similar to thestandardized generalized dimensionality discrepancy measure (SGDDM; Levy,Xu, Yel & Svetina, 2015).
The SRMSR (standardized root mean square root of squared residuals,Maydeu-Olivaras, 2013) is based on comparing residual correlationsof item pairs
SRMSR=\sqrt{ \frac{1}{ J(J-1)/2 } \sum_{i < j} ( r_{ij} - \hat{r}_{ij} )^2 }
Additionally, the SRMR is computed as
SRMR=\frac{1}{ J(J-1)/2 } \sum_{i < j} | r_{ij} - \hat{r}_{ij} |
TheMADRESIDCOV statistic (McDonald & Mok, 1995) is based on comparingresidual covariances of item pairs
MADRESIDCOV=\frac{1}{ J(J-1)/2 } \sum_{i < j} | c_{ij} - \hat{c}_{ij} |
This statistic is just multiplied by 100 in the output of this function.
Value
A list with following entries
stat.MADaQ3 | Global fit statistic |
chi2.stat | Data frame with chi square tests of conditional independencefor every item pair (Chen & Thissen, 1997) |
fitstat | Model fit statistics |
modelfit.test | Test statistic of global fit based on multipletesting correction of |
stat.itempair | Q3 and adjusted Q3 statistic for all item pairs |
residuals | Residuals |
Q3.matr | Matrix of |
aQ3.matr | Matrix of adjusted |
Q3_summary | Summary of |
N_itempair | Sample size for each item pair |
References
Chen, J., de la Torre, J., & Zhang, Z. (2013).Relative and absolute fit evaluation in cognitive diagnosis modeling.Journal of Educational Measurement, 50, 123-140.doi:10.1111/j.1745-3984.2012.00185.x
Chen, W., & Thissen, D. (1997). Local dependence indexes for item pairsusing item response theory.Journal of Educational and Behavioral Statistics,22, 265-289.
Levy, R., Xu, Y., Yel, N., & Svetina, D. (2015). A standardizedgeneralized dimensionality discrepancy measure and a standardized model-basedcovariance for dimensionality assessment for multidimensional models.Journal of Educational Measurement, 52(2), 144–158.doi:10.1111/jedm.12070
Maydeu-Olivares, A. (2013). Goodness-of-fit assessment of item responsetheory models (with discussion).Measurement: Interdisciplinary Research and Perspectives,11, 71-137.doi:10.1080/15366367.2013.831680
McDonald, R. P., & Mok, M. M.-C. (1995). Goodness of fit in item response models.Multivariate Behavioral Research, 30, 23-40.doi:10.1207/s15327906mbr3001_2
Yen, W. M. (1984). Effects of local item dependence on the fit and equatingperformance of the three-parameter logistic model.Applied Psychological Measurement, 8, 125-145.doi:10.1177/014662168400800201
Examples
############################################################################## EXAMPLE 1: data.cqc01#############################################################################data(data.cqc01)dat <- data.cqc01#*****************************************************#*** Model 1: Rasch modelmod1 <- TAM::tam.mml( dat )# assess model fitres1 <- TAM::tam.modelfit( tamobj=mod1 )summary(res1)# display item pairs with five largest adjusted Q3 statisticsres1$stat.itempair[1:5,c("item1","item2","aQ3","p","p.holm")]## Not run: # IRT.modelfitfmod1 <- IRT.modelfit(mod1)summary(fmod1)#*****************************************************#*** Model 2: 2PL modelmod2 <- TAM::tam.mml.2pl( dat )# IRT.modelfitfmod2 <- IRT.modelfit(mod2)summary(fmod2)# model comparisonIRT.compareModels(fmod1, fmod2 )############################################################################## SIMULATED EXAMPLE 2: Rasch model#############################################################################set.seed(8766)N <- 1000 # number of personsI <- 20 # number of items# simulate responseslibrary(sirt)dat <- sirt::sim.raschtype( stats::rnorm(N), b=seq(-1.5,1.5,len=I) )#*** estimationmod1 <- TAM::tam.mml( dat )summary(dat)#*** model fitres1 <- TAM::tam.modelfit( tamobj=mod1)summary(res1)############################################################################## EXAMPLE 3: Model fit data.gpcm | Partial credit model#############################################################################data(data.gpcm)dat <- data.gpcm# estimate partial credit modelmod1 <- TAM::tam.mml( dat)summary(mod1)# assess model fittmod1 <- TAM::tam.modelfit( mod1 )summary(tmod1)############################################################################## EXAMPLE 4: data.read | Comparison Q3 statistic#############################################################################library(sirt)data(data.read, package="sirt")dat <- data.read#**** Model 1: 1PL modelmod1 <- TAM::tam.mml( dat )summary(mod1)#**** Model 2: 2PL modelmod2 <- TAM::tam.mml.2pl( dat )summary(mod2)#**** assess model fits# Q3 based on posteriorfmod1 <- TAM::tam.modelfit(mod1)fmod2 <- TAM::tam.modelfit(mod2)# Q3 based on WLEsq3_mod1 <- TAM::tam.Q3(mod1)q3_mod2 <- TAM::tam.Q3(mod2)summary(fmod1)summary(fmod2)summary(q3_mod1)summary(q3_mod2)## End(Not run)Unidimensional Non- and Semiparametric Item Response Model
Description
Conducts non- and semiparametric estimation of a unidimensional item response modelfor a single group allowing polytomous item responses (Rossi, Wang & Ramsay, 2002).
For dichotomous data, the function also allows group lasso penalty(penalty_type="lasso"; Breheny & Huang, 2015; Yang & Zhou, 2015) and a ridge penalty(penalty_type="ridge"; Rossi et al., 2002)which is applied to the nonlinear part of the basis expansion. This approachautomatically detects deviations from a 2PL or a 1PL model (see Examples 2 and 3).See Details for model specification.
Usage
tam.np( dat, probs_init=NULL, pweights=NULL, lambda=NULL, control=list(), model="2PL", n_basis=0, basis_type="hermite", penalty_type="lasso", pars_init=NULL, orthonormalize=TRUE)## S3 method for class 'tam.np'summary(object, file=NULL, ...)## S3 method for class 'tam.np'IRT.cv(object, kfold=10, ...)Arguments
dat | Matrix of integer item responses (starting from zero) |
probs_init | Array containing initial probabilities |
pweights | Optional vector of person weights |
lambda | Numeric or vector of regularization parameter |
control | List of control arguments, see |
model | Specified target model. Can be |
n_basis | Number of basis functions |
basis_type | Type of basis function: |
penalty_type | Lasso type penalty ( |
pars_init | Optional matrix of initial item parameters |
orthonormalize | Logical indicating whether basis functions shouldbe orthonormalized |
object | Object of class |
file | Optional file name for summary output |
kfold | Number of folds in |
... | Further arguments to be passed |
Details
The basis expansion approach is applied for the logit transformation of itemresponse functions for dichotomous data. In more detail, it this assumed that
P(X_i=1|\theta)=\psi( H_0(\theta) + H_1(\theta)
whereH_0 is the target function type andH_1 is the semiparametricpart which parameterizes model deviations. For the 2PL model (model="2PL")it isH_0(\theta)=d_i + a_i \theta and for the 1PL model(model="1PL") we setH_1(\theta)=d_i + 1 \cdot \theta.The model discrepancy is specified as a basis expansion approach
H_1 ( \theta )=\sum_{h=1}^p \beta_{ih} f_h( \theta)
wheref_h arebasis functions (possibly orthonormalized) and\beta_{ih} areitem parameters which should be estimated. Penalty functions are posed on the\beta_{ih} coefficients. For the group lasso penalty, we specify thepenaltyJ_{i,L1}=N \lambda \sqrt{p} \sqrt{ \sum_{h=1}^p \beta_{ih}^2 } while forthe ridge penalty it isJ_{i,L2}=N \lambda \sum_{h=1}^p \beta_{ih}^2(N denoting the sample size).
Value
List containing several entries
rprobs | Item response probabilities |
theta | Used nodes for approximation of |
n.ik | Expected counts |
like | Individual likelihood |
hwt | Individual posterior |
item | Summary item parameter table |
pars | Estimated parameters |
regularized | Logical indicating which items are regularized |
ic | List containing |
... | Further values |
References
Breheny, P., & Huang, J. (2015). Group descent algorithms for nonconvex penalized linearand logistic regression models with grouped predictors.Statistics and Computing, 25(2), 173-187.doi:10.1007/s11222-013-9424-2
Rossi, N., Wang, X., & Ramsay, J. O. (2002). Nonparametric item response functionestimates with the EM algorithm.Journal of Educational and Behavioral Statistics, 27(3), 291-317.doi:10.3102/10769986027003291
Yang, Y., & Zou, H. (2015). A fast unified algorithm for solving group-lasso penalizedlearning problems.Statistics and Computing, 25(6), 1129-1141.doi:10.1007/s11222-014-9498-5
See Also
Nonparametric item response models can also be estimated with themirt::itemGAM function in themirt package and theKernSmoothIRT::ksIRT in theKernSmoothIRT package.
Seetam.mml andtam.mml.2pl for parametric item responsemodels.
Examples
## Not run: ############################################################################## EXAMPLE 1: Nonparametric estimation polytomous data#############################################################################data(data.cqc02, package="TAM")dat <- data.cqc02#** nonparametric estimationmod <- TAM::tam.np(dat)#** extractor functions for objects of class 'tam.np'lmod <- IRT.likelihood(mod)pmod <- IRT.posterior(mod)rmod <- IRT.irfprob(mod)emod <- IRT.expectedCounts(mod)############################################################################## EXAMPLE 2: Semiparametric estimation and detection of item misfit##############################################################################- simulate data with two misfitting itemsset.seed(998)I <- 10N <- 1000a <- stats::rnorm(I, mean=1, sd=.3)b <- stats::rnorm(I, mean=0, sd=1)dat <- matrix(NA, nrow=N, ncol=I)colnames(dat) <- paste0("I",1:I)theta <- stats::rnorm(N)for (ii in 1:I){ dat[,ii] <- 1*(stats::runif(N) < stats::plogis( a[ii]*(theta-b[ii] ) ))}#* first misfitting item with lower and upper asymptoteii <- 1l <- .3u <- 1b[ii] <- 1.5dat[,ii] <- 1*(stats::runif(N) < l + (u-l)*stats::plogis( a[ii]*(theta-b[ii] ) ))#* second misfitting item with non-monotonic item response functionii <- 3dat[,ii] <- (stats::runif(N) < stats::plogis( theta-b[ii]+.6*theta^2))#- 2PL modelmod0 <- TAM::tam.mml.2pl(dat)#- lasso penalty with lambda of .05mod1 <- TAM::tam.np(dat, n_basis=4, lambda=.05)#- lambda value of .03 using starting value of previous modelmod2 <- TAM::tam.np(dat, n_basis=4, lambda=.03, pars_init=mod1$pars)cmod2 <- TAM::IRT.cv(mod2) # cross-validated deviance#- lambda=.015mod3 <- TAM::tam.np(dat, n_basis=4, lambda=.015, pars_init=mod2$pars)cmod3 <- TAM::IRT.cv(mod3)#- lambda=.007mod4 <- TAM::tam.np(dat, n_basis=4, lambda=.007, pars_init=mod3$pars)#- lambda=.001mod5 <- TAM::tam.np(dat, n_basis=4, lambda=.001, pars_init=mod4$pars)#- final estimation using solution of mod3eps <- .0001lambda_final <- eps+(1-eps)*mod3$regularized # lambda parameter for final estimatemod3b <- TAM::tam.np(dat, n_basis=4, lambda=lambda_final, pars_init=mod3$pars)summary(mod1)summary(mod2)summary(mod3)summary(mod3b)summary(mod4)# compare models with respect to information criteriaIRT.compareModels(mod0, mod1, mod2, mod3, mod3b, mod4, mod5)#-- compute item fit statistics RISE# regularized solutionTAM::IRT.RISE(mod_p=mod1, mod_np=mod3)# regularized solution, final estimationTAM::IRT.RISE(mod_p=mod1, mod_np=mod3b, use_probs=TRUE)TAM::IRT.RISE(mod_p=mod1, mod_np=mod3b, use_probs=FALSE)# use TAM::IRT.RISE() function for computing the RMSD statisticTAM::IRT.RISE(mod_p=mod1, mod_np=mod1, use_probs=FALSE)############################################################################## EXAMPLE 3: Mixed 1PL/2PL model##############################################################################* simulate data with 2 2PL items and 8 1PL itemsset.seed(9877)N <- 2000I <- 10b <- seq(-1,1,len=I)a <- rep(1,I)a[c(3,8)] <- c(.5, 2)theta <- stats::rnorm(N, sd=1)dat <- sirt::sim.raschtype(theta, b=b, fixed.a=a)#- 1PL modelmod1 <- TAM::tam.mml(dat)#- 2PL modelmod2 <- TAM::tam.mml.2pl(dat)#- 2PL model with penalty on slopesmod3 <- TAM::tam.np(dat, lambda=.04, model="1PL", n_basis=0)summary(mod3)#- final mixed 1PL/2PL modellambda <- 1*mod3$regularizedmod4 <- TAM::tam.np(dat, lambda=lambda, model="1PL", n_basis=0)summary(mod4)IRT.compareModels(mod1, mod2, mod3, mod4)## End(Not run)Person Outfit and Infit Statistics
Description
Computes person outfit and infit statistics.
Usage
tam.personfit(tamobj)Arguments
tamobj | Fitted object inTAM |
Value
Data frame containing person outfit and infit statistics
See Also
Seetam.fit andmsq.itemfit for item fitstatistics.
Examples
############################################################################## EXAMPLE 1: Person fit dichotomous data#############################################################################data(data.sim.rasch, package="TAM")resp <- data.sim.rasch#*** estimate Rasch modelmod1 <- TAM::tam.mml(resp=resp)summary(mod1)#*** compute person fit statisticsfmod1 <- TAM::tam.personfit(mod1)head(fmod1)Plausible Value Imputation
Description
Plausible value imputation for objects of the classestam andtam.mml(Adams & Wu, 2007). For converting generated plausible values intoa list of multiply imputed datasets seetampv2datalistand the Examples 2 and 3 of this function.
The functiontam.pv.mcmc employs fully Bayesian estimation for drawingplausible values and is recommended in cases when the latent regression modelis unreliably estimated (multidimensional model with stochastic nodes).The parameters of the latent regression (regression coefficients andresidual covariance matrices) are drawn by Bayesian bootstrap (Rubin, 1981).Either case probabilities (i.e., non-integer weights for cases in resampling;argumentsample_integers=FALSE) or ordinarybootstrap (i.e., sampling cases with replacement; argumentsample_integers=TRUE)can be used for the Bootstrap step by obtaining posterior draws of regression parameters.
Usage
tam.pv(tamobj, nplausible=10, ntheta=2000, normal.approx=FALSE, samp.regr=FALSE, theta.model=FALSE, np.adj=8, na.grid=5, verbose=TRUE)tam.pv.mcmc( tamobj, Y=NULL, group=NULL, beta_groups=TRUE, nplausible=10, level=.95, n.iter=1000, n.burnin=500, adj_MH=.5, adj_change_MH=.05, refresh_MH=50, accrate_bound_MH=c(.45, .55), sample_integers=FALSE, theta_init=NULL, print_iter=20, verbose=TRUE, calc_ic=TRUE)## S3 method for class 'tam.pv.mcmc'summary(object, file=NULL, ...)## S3 method for class 'tam.pv.mcmc'plot(x, ...)Arguments
tamobj | Object of class |
nplausible | Number of plausible values to be drawn |
ntheta | Number of ability nodes for plausible value imputation. Notethat in this function ability nodes are simulated for thewhole sample, not for every person (contrary to the software ConQuest). |
normal.approx | An optional logical indicating whether the individual posterior distributionsshould be approximated by a normal distribution?The default is |
samp.regr | An optional logical indicating whether regression coefficientsshould be fixed in the plausible value imputation oralso sampled from their posterior distribution?The default is |
theta.model | Logical indicating whether the theta grid from the |
np.adj | This parameter defines the "spread" of the random theta valuesfor drawing plausible values when |
na.grid | Range of the grid in normal approximation. Default is from-5 to 5. |
... | Further arguments to be passed |
Y | Optional matrix of regressors |
group | Optional vector of group identifiers |
beta_groups | Logical indicating whether group specific beta coefficientsshall be estimated. |
level | Confidence level |
n.iter | Number of iterations |
n.burnin | Number of burnin-iterations |
adj_MH | Adjustment factor for Metropolis-Hastings (MH) steps which controlsthe variance of the proposal distribution for |
adj_change_MH | Allowed change for MH adjustment factor after refreshing |
refresh_MH | Number of iterations after which the variance of the proposaldistribution should be updated |
accrate_bound_MH | Bounds for target acceptance rates of sampled |
sample_integers | Logical indicating whether weights for complete casesshould be sampled in bootstrap |
theta_init | Optional matrix with initial |
print_iter | Print iteration progress every |
verbose | Logical indicating whether iteration progress should be displayed. |
calc_ic | Logical indicating whether information criteria should be computed. |
object | Object of class |
x | Object of class |
file | A file name in which the summary output will be written |
Value
The value oftam.pv is a list with following entries:
pv | A data frame containing a person identifier ( |
hwt | Individual posterior distribution evaluated atthe ability grid |
hwt1 | Cumulated individual posterior distribution |
theta | Simulated ability nodes |
The value oftam.pv.mcmc is a list containing entries
pv | Data frame containing plausible values |
parameter_samples | Sampled regression parameters |
ic | Information criteria |
beta | Estimate of regression parameters |
variance | Estimate of residual variance matrix |
correlation | Estimate of residual correlation matrix corresponding to |
theta_acceptance_MH | Acceptance rates and acceptance MH factors for eachindividual |
theta_last | Last sampled |
... | Further values |
References
Adams, R. J., & Wu, M. L. (2007). The mixed-coefficients multinomial logit model.A generalized form of the Rasch model. In M. von Davier & C. H. Carstensen (Eds.):Multivariate and mixture distribution Rasch models: Extensions and applications(pp. 55-76). New York: Springer.doi:10.1007/978-0-387-49839-3_4
Rubin, D. B. (1981). The Bayesian bootstrap.The Annals of Statistics, 9(1),130-134.
See Also
Seetam.latreg for further examples offitting latent regression models and drawing plausible valuesfrom models which provides an individual likelihood as an input.
Examples
############################################################################## EXAMPLE 1: Dichotomous unidimensional data sim.rasch#############################################################################data(data.sim.rasch)resp <- data.sim.rasch[ 1:500, 1:15 ] # select subsample of students and items# estimate Rasch modelmod <- TAM::tam.mml(resp)# draw 5 plausible values without a normality# assumption of the posterior and 2000 ability nodespv1a <- TAM::tam.pv( mod, nplausible=5, ntheta=2000 )# draw 5 plausible values with a normality# assumption of the posterior and 500 ability nodespv1b <- TAM::tam.pv( mod, nplausible=5, ntheta=500, normal.approx=TRUE )# distribution of first plausible value from imputation pv1hist(pv1a$pv$PV1.Dim1 )# boxplot of all plausible values from imputation pv2boxplot(pv1b$pv[, 2:6 ] )## Not run: # draw plausible values with tam.pv.mcmc functionY <- matrix(1, nrow=500, ncol=1)pv2 <- TAM::tam.pv.mcmc( tamobj=mod, Y=Y, nplausible=5 )str(pv2)# summary outputsummary(pv2)# assessing convergence with traceplotsplot(pv2, ask=TRUE)# use starting values for theta and MH factors which fulfill acceptance rates# from previously fitted modelpv3 <- TAM::tam.pv.mcmc( tamobj=mod, Y=Y, nplausible=5, theta_init=pv2$theta_last, adj_MH=pv2$theta_acceptance_MH$adj_MH )############################################################################## EXAMPLE 2: Unidimensional plausible value imputation with# background variables; dataset data.pisaRead from sirt package#############################################################################data(data.pisaRead, package="sirt")dat <- data.pisaRead$data ## > colnames(dat) ## [1] "idstud" "idschool" "female" "hisei" "migra" "R432Q01" ## [7] "R432Q05" "R432Q06" "R456Q01" "R456Q02" "R456Q06" "R460Q01" ## [13] "R460Q05" "R460Q06" "R466Q02" "R466Q03" "R466Q06"## Note that reading items have variable names starting with R4# estimate 2PL model without covariatesitems <- grep("R4", colnames(dat) ) # select test items from datamod2a <- TAM::tam.mml.2pl( resp=dat[,items] )summary(mod2a)# fix item parameters for plausible value imputation # fix item intercepts by defining xsi.fixedxsi0 <- mod2a$xsi$xsixsi.fixed <- cbind( seq(1,length(xsi0)), xsi0 ) # fix item slopes using mod2$B# matrix of latent regressors female, hisei and migraY <- dat[, c("female", "hisei", "migra") ]mod2b <- TAM::tam.mml( resp=dat[,items], B=mod2a$B, xsi.fixed=xsi.fixed, Y=Y, pid=dat$idstud)# plausible value imputation with normality assumption# and ignoring uncertainty about regression coefficients# -> the default is samp.regr=FALSEpv2c <- TAM::tam.pv( mod2b, nplausible=10, ntheta=500, normal.approx=TRUE )# sampling of regression coefficientspv2d <- TAM::tam.pv( mod2b, nplausible=10, ntheta=500, samp.regr=TRUE)# sampling of regression coefficients, normal approximation using the# theta grid from the modelpv2e <- TAM::tam.pv( mod2b, samp.regr=TRUE, theta.model=TRUE, normal.approx=TRUE)#--- create list of multiply imputed datasets with plausible values# define dataset with covariates to be matchedY <- dat[, c("idstud", "idschool", "female", "hisei", "migra") ]# define plausible value namespvnames <- c("PVREAD")# create list of imputed datasetsdatlist1 <- TAM::tampv2datalist( pv2e, pvnames=pvnames, Y=Y, Y.pid="idstud")str(datlist1)# create a matrix of covariates with different set of students than in pv2eY1 <- Y[ seq( 1, 600, 2 ), ]# create list of multiply imputed datasetsdatlist2 <- TAM::tampv2datalist( pv2e, pvnames=c("PVREAD"), Y=Y1, Y.pid="idstud")#--- fit some models in lavaan and semToolslibrary(lavaan)library(semTools)#*** Model 1: Linear regressionlavmodel <- " PVREAD ~ migra + hisei PVREAD ~~ PVREAD "mod1 <- semTools::lavaan.mi( lavmodel, data=datlist1, m=0)summary(mod1, standardized=TRUE, rsquare=TRUE)# apply lavaan for third imputed datasetmod1a <- lavaan::lavaan( lavmodel, data=datlist1[[3]] )summary(mod1a, standardized=TRUE, rsquare=TRUE)# compare with mod1 by looping over all datasetsmod1b <- lapply( datlist1, FUN=function(dat0){ mod1a <- lavaan( lavmodel, data=dat0 ) coef( mod1a) } )mod1bmod1b <- matrix( unlist( mod1b ), ncol=length( coef(mod1)), byrow=TRUE )mod1bround( colMeans(mod1b), 3 )coef(mod1) # -> results coincide#*** Model 2: Path modellavmodel <- " PVREAD ~ migra + hisei hisei ~ migra PVREAD ~~ PVREAD hisei ~~ hisei "mod2 <- semTools::lavaan.mi( lavmodel, data=datlist1 )summary(mod2, standardized=TRUE, rsquare=TRUE)# fit statisticsinspect( mod2, what="fit")#--- using mitools packagelibrary(mitools)# convert datalist into an object of class imputationListdatlist1a <- mitools::imputationList( datlist1 )# fit linear regressionmod1c <- with( datlist1a, stats::lm( PVREAD ~ migra + hisei ) )summary( mitools::MIcombine(mod1c) )#--- using mice packagelibrary(mice)library(miceadds)# convert datalist into a mids objectmids1 <- miceadds::datalist2mids( datlist1 )# fit linear regressionmod1c <- with( mids1, stats::lm( PVREAD ~ migra + hisei ) )summary( mice::pool(mod1c) )############################################################################## EXAMPLE 3: Multidimensional plausible value imputation############################################################################## (1) simulate some dataset.seed(6778)library(mvtnorm)N <- 1000Y <- cbind( stats::rnorm(N), stats::rnorm(N) )theta <- mvtnorm::rmvnorm( N, mean=c(0,0), sigma=matrix( c(1,.5,.5,1), 2, 2 ))theta[,1] <- theta[,1] + .4 * Y[,1] + .2 * Y[,2] # latent regression modeltheta[,2] <- theta[,2] + .8 * Y[,1] + .5 * Y[,2] # latent regression modelI <- 20p1 <- stats::plogis( outer( theta[,1], seq( -2, 2, len=I ), "-" ) )resp1 <- 1 * ( p1 > matrix( stats::runif( N*I ), nrow=N, ncol=I ) )p1 <- stats::plogis( outer( theta[,2], seq( -2, 2, len=I ), "-" ) )resp2 <- 1 * ( p1 > matrix( stats::runif( N*I ), nrow=N, ncol=I ) )resp <- cbind(resp1,resp2)colnames(resp) <- paste("I", 1:(2*I), sep="")# (2) define loading MatrixQ <- array( 0, dim=c( 2*I, 2 ))Q[cbind(1:(2*I), c( rep(1,I), rep(2,I) ))] <- 1# (3) fit latent regression modelmod <- TAM::tam.mml( resp=resp, Y=Y, Q=Q )# (4) draw plausible valuespv1 <- TAM::tam.pv( mod, theta.model=TRUE )# (5) convert plausible values to list of imputed datasetsY1 <- data.frame(Y)colnames(Y1) <- paste0("Y",1:2)pvnames <- c("PVFA","PVFB")# create list of imputed datasetsdatlist1 <- TAM::tampv2datalist( pv1, pvnames=pvnames, Y=Y1 )str(datlist1)# (6) apply statistical modelslibrary(semTools)# define linear regressionlavmodel <- " PVFA ~ Y1 + Y2 PVFA ~~ PVFA "mod1 <- semTools::lavaan.mi( lavmodel, data=datlist1 )summary(mod1, standardized=TRUE, rsquare=TRUE)# (7) draw plausible values with tam.pv.mcmc functionY1 <- cbind( 1, Y )pv2 <- TAM::tam.pv.mcmc( tamobj=mod, Y=Y1, n.iter=1000, n.burnin=200 )# (8) group-specific plausible valuesset.seed(908)# create artificial grouping variablegroup <- sample( 1:3, N, replace=TRUE )pv3 <- TAM::tam.pv.mcmc( tamobj, Y=Y1, n.iter=1000, n.burnin=200, group=group )# (9) plausible values with no fitted object in TAM# fit IRT model without covariatesmod4a <- TAM::tam.mml( resp=resp, Q=Q )# define input for tam.pv.mcmctamobj1 <- list( AXsi=mod4a$AXsi, B=mod4a$B, resp=mod4a$resp )pmod4 <- TAM::tam.pv.mcmc( tamobj1, Y=Y1 )############################################################################## EXAMPLE 4: Plausible value imputation with measurement errors in covariates#############################################################################library(sirt)set.seed(7756)N <- 2000 # number of personsI <- 10 # number of items# simulate covariatesX <- mvrnorm( N, mu=c(0,0), Sigma=matrix( c(1,.5,.5,1),2,2 ) )colnames(X) <- paste0("X",1:2)# second covariate with measurement error with variance var.errvar.err <- .3X.err <- XX.err[,2] <-X[,2] + rnorm(N, sd=sqrt(var.err) )# simulate thetatheta <- .5*X[,1] + .4*X[,2] + rnorm( N, sd=.5 )# simulate item responsesitemdiff <- seq( -2, 2, length=I) # item difficultiesdat <- sirt::sim.raschtype( theta, b=itemdiff )#***********************#*** Model 0: Regression model with true variablesmod0 <- stats::lm( theta ~ X )summary(mod0)#***********************#*** Model 1: latent regression model with true covariates Xxsi.fixed <- cbind( 1:I, itemdiff )mod1 <- TAM::tam.mml( dat, xsi.fixed=xsi.fixed, Y=X)summary(mod1)# draw plausible valuesres1a <- TAM::tam.pv( mod1, normal.approx=TRUE, ntheta=200, samp.regr=TRUE)# create list of multiply imputed datasetslibrary(miceadds)datlist1a <- TAM::tampv2datalist( res1a, Y=X )imp1a <- miceadds::datalist2mids( datlist1a )# fit linear model# linear regression with measurement errors in Xlavmodel <- " PV.Dim1 ~ X1 + X2true X2true=~ 1*X2 X2 ~~ 0.3*X2 #=var.err PV.Dim1 ~~ PV.Dim1 X2true ~~ X2true "mod1a <- semTools::lavaan.mi( lavmodel, datlist1a)summary(mod1a, standardized=TRUE, rsquare=TRUE)#***********************#*** Model 2: latent regression model with error-prone covariates X.errmod2 <- TAM::tam.mml( dat, xsi.fixed=xsi.fixed, Y=X.err)summary(mod2)#***********************#*** Model 3: Adjustment of covariatescov.X.err <- cov( X.err )# matrix of variance of measurement errorsmeaserr <- diag( c(0,var.err) )# true covariance matrixcov.X <- cov.X.err - measerr# mean of X.errmu <- colMeans(X.err)muM <- matrix( mu, nrow=nrow(X.err), ncol=ncol(X.err), byrow=TRUE)# reliability matrixW <- solve( cov.X.err ) %*% cov.Xident <- diag(2)# adjusted scores of XX.adj <- ( X.err - muM ) %*% W + muM %*% ( ident - W )# fit latent regression modelmod3 <- TAM::tam.mml( dat, xsi.fixed=xsi.fixed, Y=X.adj)summary(mod3)# draw plausible valuesres3a <- TAM::tam.pv( mod3, normal.approx=TRUE, ntheta=200, samp.regr=TRUE)# create list of multiply imputed datasetslibrary(semTools)#*** PV dataset 1# datalist with error-prone covariatesdatlist3a <- TAM::tampv2datalist( res3a, Y=X.err )# datalist with adjusted covariatesdatlist3b <- TAM::tampv2datalist( res3a, Y=X.adj )# linear regression with measurement errors in Xlavmodel <- " PV.Dim1 ~ X1 + X2true X2true=~ 1*X2 X2 ~~ 0.3*X2 #=var.err PV.Dim1 ~~ PV.Dim1 X2true ~~ X2true "mod3a <- semTools::lavaan.mi( lavmodel, datlist3a)summary(mod3a, standardized=TRUE, rsquare=TRUE)lavmodel <- " PV.Dim1 ~ X1 + X2 PV.Dim1 ~~ PV.Dim1 "mod3b <- semTools::lavaan.mi( lavmodel, datlist3b)summary(mod3b, standardized=TRUE, rsquare=TRUE)#=> mod3b leads to the correct estimate.#*********************************************# plausible value imputation for abilities and error-prone# covariates using the mice packagelibrary(mice)library(miceadds)# creating the likelihood for plausible value for abilitiesmod11 <- TAM::tam.mml( dat, xsi.fixed=xsi.fixed )likePV <- IRT.likelihood(mod11)# creating the likelihood for error-prone covariate X2lavmodel <- " X2true=~ 1*X2 X2 ~~ 0.3*X2 "mod12 <- lavaan::cfa( lavmodel, data=as.data.frame(X.err) )summary(mod12)likeX2 <- TAM::IRTLikelihood.cfa( data=X.err, cfaobj=mod12)str(likeX2)#-- create data input for mice packagedata <- data.frame( "PVA"=NA, "X1"=X[,1], "X2"=NA )vars <- colnames(data)V <- length(vars)predictorMatrix <- 1 - diag(V)rownames(predictorMatrix) <- colnames(predictorMatrix) <- varsimputationMethod <- rep("norm", V )names(imputationMethod) <- varsimputationMethod[c("PVA","X2")] <- "plausible.values"#-- create argument lists for plausible value imputation# likelihood and theta grid of plausible value derived from IRT modellike <- list( "PVA"=likePV, "X2"=likeX2 )theta <- list( "PVA"=attr(likePV,"theta"), "X2"=attr(likeX2, "theta") )#-- initial imputationsdata.init <- datadata.init$PVA <- mod11$person$EAPdata.init$X2 <- X.err[,"X2"]#-- imputation using the mice and miceadds packageimp1 <- mice::mice( as.matrix(data), predictorMatrix=predictorMatrix, m=4, maxit=6, method=imputationMethod, allow.na=TRUE, theta=theta, like=like, data.init=data.init )summary(imp1)# compute linear regressionmod4a <- with( imp1, stats::lm( PVA ~ X1 + X2 ) )summary( mice::pool(mod4a) )## End(Not run)Standard Error Estimation
Description
Standard error computation for objects of the classestamandtam.mml.
Usage
tam.se(tamobj, item_pars=TRUE, ...)tam_mml_se_quick(tamobj, numdiff.parm=0.001, item_pars=TRUE )tam_latreg_se_quick(tamobj, numdiff.parm=0.001 )Arguments
tamobj | An object generated by |
item_pars | Logical indicating whether standard errors should alsobe computed for item parameters |
numdiff.parm | Step width parameter for numericaldifferentiation |
... | Further arguments to be passed |
Details
Covariances between parameters estimates are ignored in this standarderror calculation. The standard error is obtained by numericaldifferentiation.
Value
A list with following entries:
xsi | Data frame with |
beta | Data frame with |
B | Data frame with loading parameters and theircorresponding standard errors |
Note
Standard error estimation for variances and covariances is not yetimplemented.Standard error estimation for loading parameters in case ofirtmodel='GPCM.design' is highly experimental.
Examples
############################################################################## EXAMPLE 1: 1PL model, data.sim.rasch#############################################################################data(data.sim.rasch)# estimate Rasch modelmod1 <- TAM::tam.mml(resp=data.sim.rasch[1:500,1:10])# standard error estimationse1 <- TAM::tam.se( mod1 )# proportion of standard errors estimated by 'tam.se' and 'tam.mml'prop1 <- se1$xsi$se / mod1$xsi$se## > summary( prop1 )## Min. 1st Qu. Median Mean 3rd Qu. Max.## 1.030 1.034 1.035 1.036 1.039 1.042##=> standard errors estimated by tam.se are a bit larger## Not run: ############################################################################## EXAMPLE 2: Standard errors differential item functioning#############################################################################data(data.ex08)formulaA <- ~ item*femaleresp <- data.ex08[["resp"]]facets <- as.data.frame( data.ex08[["facets"]] )# investigate DIFmod <- TAM::tam.mml.mfr( resp=resp, facets=facets, formulaA=formulaA )summary(mod)# estimate standard errorssemod <- TAM::tam.se(mod)prop1 <- semod$xsi$se / mod$xsi$sesummary(prop1)# plot differences in standard errorsplot( mod$xsi$se, semod$xsi$se, pch=16, xlim=c(0,.15), ylim=c(0,.15), xlab="Standard error 'tam.mml'", ylab="Standard error 'tam.se'" )lines( c(-6,6), c(-6,6), col="gray")round( cbind( mod$xsi, semod$xsi[,-1] ), 3 ) ## xsi se.xsi N est se ## I0001 -1.956 0.092 500 -1.956 0.095 ## I0002 -1.669 0.085 500 -1.669 0.088 ## [...] ## I0010 2.515 0.108 500 2.515 0.110 ## female1 -0.091 0.025 500 -0.091 0.041 ## I0001:female1 -0.051 0.070 500 -0.051 0.071 ## I0002:female1 0.085 0.067 500 0.085 0.068 ## [...] ## I0009:female1 -0.019 0.068 500 -0.019 0.068 ###=> The largest discrepancy in standard errors is observed for the# main female effect (.041 in 'tam.se' instead of .025 in 'tam.mml')## End(Not run)Calculation of Thurstonian Thresholds
Description
This function estimates Thurstonian thresholds for item categoryparameters of (generalized) partial credit models (see Details).
Usage
tam.threshold(tamobj, prob.lvl=0.5)Arguments
tamobj | Object of class |
prob.lvl | A numeric specifying the probability level of the threshold.The default is |
Details
This function only works appropriately for unidimensional modelsor between item multidimensional models.
Value
A data frame with Thurstonian thresholds. Rows correspond to items andcolumns to item steps.
See Also
See theWrightMap package and Example 3 for creating Wright mapswith fitted models inTAM, seewrightMap.
Examples
############################################################################## EXAMPLE 1: ordered data - Partial credit model#############################################################################data( data.gpcm )# Model 1: partial credit modelmod1 <- TAM::tam.mml( resp=data.gpcm,control=list( maxiter=200) )summary(mod1) ## Item Parameters -A*Xsi ## item N M AXsi_.Cat1 AXsi_.Cat2 AXsi_.Cat3 B.Cat1.Dim1 B.Cat2.Dim1 B.Cat3.Dim1 ## 1 Comfort 392 0.880 -1.302 1.154 3.881 1 2 3 ## 2 Work 392 1.278 -1.706 -0.847 0.833 1 2 3 ## 3 Benefit 392 1.163 -1.233 -0.404 1.806 1 2 3# Calculation of Thurstonian thresholdsTAM::tam.threshold(mod1) ## Cat1 Cat2 Cat3 ## Comfort -1.325226 2.0717468 3.139801 ## Work -1.777679 0.6459045 1.971222 ## Benefit -1.343536 0.7491760 2.403168## Not run: ############################################################################## EXAMPLE 2: Multidimensional model data.math#############################################################################library(sirt)data(data.math, package="sirt")dat <- data.math$data# select itemsitems1 <- grep("M[A-D]", colnames(dat), value=TRUE)items2 <- grep("M[H-I]", colnames(dat), value=TRUE)# select datasetdat <- dat[ c(items1,items2)]# create Q-matrixQ <- matrix( 0, nrow=ncol(dat), ncol=2 )Q[ seq(1,length(items1) ), 1 ] <- 1Q[ length(items1) + seq(1,length(items2) ), 2 ] <- 1# fit two-dimensional modelmod1 <- TAM::tam.mml( dat, Q=Q )# compute thresholds (specify a probability level of .625)tmod1 <- TAM::tam.threshold( mod1, prob.lvl=.625 )############################################################################## EXAMPLE 3: Creating Wright maps with the WrightMap package#############################################################################library(WrightMap)# For conducting Wright maps in combination with TAM, see# http://wrightmap.org/post/100850738072/using-wrightmap-with-the-tam-packagedata(sim.rasch)dat <- sim.rasch# estimate Rasch model in TAMmod1 <- TAM::tam.mml(dat)summary(mod1)#--- A: creating a Wright map with WLEs# compute WLEwlemod1 <- TAM::tam.wle(mod1)$theta# extract thresholdstmod1 <- TAM::tam.threshold(mod1)# create Wright mapWrightMap::wrightMap( thetas=wlemod1, thresholds=tmod1, label.items.srt=-90)#--- B: creating a Wright Map with population distribution# extract ability distribution and replicate observationsuni.proficiency <- rep( mod1$theta[,1], round( mod1$pi.k * mod1$ic$n) )# draw WrightMapWrightMap::wrightMap( thetas=uni.proficiency, thresholds=tmod1, label.items.rows=3)## End(Not run)Weighted Likelihood Estimation and Maximum Likelihood Estimation ofPerson Parameters
Description
Compute the weighted likelihood estimator (Warm, 1989)for objects of classestam,tam.mml andtam.jml,respectively.
Usage
tam.wle(tamobj, ...)tam.mml.wle( tamobj, score.resp=NULL, WLE=TRUE, adj=.3, Msteps=20, convM=.0001, progress=TRUE, output.prob=FALSE )tam.mml.wle2(tamobj, score.resp=NULL, WLE=TRUE, adj=0.3, Msteps=20, convM=1e-04, progress=TRUE, output.prob=FALSE, pid=NULL, theta_init=NULL )tam_jml_wle(tamobj, resp, resp.ind, A, B, nstud, nitems, maxK, convM, PersonScores, theta, xsi, Msteps, WLE=FALSE, theta.fixed=NULL, progress=FALSE, output.prob=TRUE, damp=0, version=2, theta_proc=NULL)## S3 method for class 'tam.wle'summary(object, file=NULL, digits=3, ...)## S3 method for class 'tam.wle'print(x, digits=3, ...)Arguments
tamobj | An object generated by |
score.resp | An optional data frame for which WLEs or MLEsshould be calculated. In case of the default |
WLE | A logical indicating whether the weighted likelihood estimate(WLE, |
adj | Adjustment in MLE estimation for extreme scores (i.e. all or noneitems were correctly solved). This argument is not used if |
Msteps | Maximum number of iterations |
convM | Convergence criterion |
progress | Logical indicating whether progress should be displayed. |
output.prob | Logical indicating whether evaluated probabilities shouldbe included in the list of outputs. |
pid | Optional vector of person identifiers |
theta_init | Initial theta values |
resp | Data frame with item responses (only for |
resp.ind | Data frame with response indicators (only for |
A | Design matrix |
B | Design matrix |
nstud | Number of persons (applies only to |
nitems | Number of items (applies only to |
maxK | Maximum item score (applies only to |
PersonScores | A vector containing the sufficient statistics for theperson parameters (applies only to |
theta | Initial |
xsi | Parameter vector |
theta.fixed | Matrix for fixed person parameters |
damp | Numeric value between 0 and 1 indicating amount of dampeningincrements in |
version | Integer with possible values 2 or 3. In case of missing item responses, |
theta_proc | Function for processing |
... | Further arguments to be passed |
object | Object of class |
x | Object of class |
file | Optional file name in which the object summary should be written. |
digits | Number of digits for rounding |
Value
Fortam.wle.mml andtam.wle.mml2, it is a data frame with followingcolumns:
pid | Person identifier |
PersonScores | Score of each person |
PersonMax | Maximum score of each person |
theta | Weighted likelihood estimate (WLE) or MLE |
error | Standard error of the WLE or MLE |
WLE.rel | WLE reliability (same value for all persons) |
Fortam.jml.WLE, it is a list with following entries:
theta | Weighted likelihood estimate (WLE) or MLE |
errorWLE | Standard error of the WLE or MLE |
meanChangeWLE | Mean change between updated and previous abilityestimates from last iteration |
References
Penfield, R. D., & Bergeron, J. M. (2005). Applying a weighted maximumlikelihood latent trait estimator to the generalized partial credit model.Applied Psychological Measurement, 29, 218-233.
Warm, T. A. (1989). Weighted likelihood estimation of ability in itemresponse theory.Psychometrika, 54, 427-450.doi:10.1007/BF02294627
See Also
See thePP::PP_gpcm functionin thePP package for more personparameter estimators for the partial credit model (Penfield & Bergeron, 2005).
See the S3 methodIRT.factor.scores.tam.
Examples
############################################################################## EXAMPLE 1: 1PL model, data.sim.rasch#############################################################################data(data.sim.rasch)# estimate Rasch modelmod1 <- TAM::tam.mml(resp=data.sim.rasch)# WLE estimationwle1 <- TAM::tam.wle( mod1 ) ## WLE Reliability=0.894print(wle1)summary(wle1)# scoring for a different dataset containing same items (first 10 persons in sim.rasch)wle2 <- TAM::tam.wle( mod1, score.resp=data.sim.rasch[1:10,])#--- WLE estimation without using a TAM object#* create an input listinput <- list( resp=data.sim.rasch, AXsi=mod1$AXsi, B=mod1$B )#* estimationwle2b <- TAM::tam.mml.wle2( input )## Not run: ############################################################################## EXAMPLE 2: 3-dimensional Rasch model | data.read from sirt package#############################################################################data(data.read, package="sirt")# define Q-matrixQ <- matrix(0,12,3)Q[ cbind( 1:12, rep(1:3,each=4) ) ] <- 1# redefine data: create some missings for first three casesresp <- data.readresp[1:2, 5:12] <- NAresp[3,1:4] <- NA ## > head(resp) ## A1 A2 A3 A4 B1 B2 B3 B4 C1 C2 C3 C4 ## 2 1 1 1 1 NA NA NA NA NA NA NA NA ## 22 1 1 0 0 NA NA NA NA NA NA NA NA ## 23 NA NA NA NA 1 0 1 1 1 1 1 1 ## 41 1 1 1 1 1 1 1 1 1 1 1 1 ## 43 1 0 0 1 0 0 1 1 1 0 1 0 ## 63 1 1 0 0 1 0 1 1 1 1 1 1# estimate 3-dimensional Rasch modelmod <- TAM::tam.mml( resp=resp, Q=Q, control=list(snodes=1000,maxiter=50) )summary(mod)# WLE estimateswmod <- TAM::tam.wle(mod, Msteps=3)summary(wmod) ## head(round(wmod,2)) ## pid N.items PersonScores.Dim01 PersonScores.Dim02 PersonScores.Dim03 ## 2 1 4 3.7 0.3 0.3 ## 22 2 4 2.0 0.3 0.3 ## 23 3 8 0.3 3.0 3.7 ## 41 4 12 3.7 3.7 3.7 ## 43 5 12 2.0 2.0 2.0 ## 63 6 12 2.0 3.0 3.7 ## PersonMax.Dim01 PersonMax.Dim02 PersonMax.Dim03 theta.Dim01 theta.Dim02 ## 2 4.0 0.6 0.6 1.06 NA ## 22 4.0 0.6 0.6 -0.96 NA ## 23 0.6 4.0 4.0 NA -0.07 ## 41 4.0 4.0 4.0 1.06 0.82 ## 43 4.0 4.0 4.0 -0.96 -1.11 ## 63 4.0 4.0 4.0 -0.96 -0.07 ## theta.Dim03 error.Dim01 error.Dim02 error.Dim03 WLE.rel.Dim01 ## 2 NA 1.50 NA NA -0.1 ## 22 NA 1.11 NA NA -0.1 ## 23 0.25 NA 1.17 1.92 -0.1 ## 41 0.25 1.50 1.48 1.92 -0.1 ## 43 -1.93 1.11 1.10 1.14 -0.1# (1) Note that estimated WLE reliabilities are not trustworthy in this example.# (2) If cases do not possess any observations on dimensions, then WLEs# and their corresponding standard errors are set to NA.############################################################################## EXAMPLE 3: Partial credit model | Comparison WLEs with PP package#############################################################################library(PP)data(data.gpcm)dat <- data.gpcmI <- ncol(dat)#****************************************#*** Model 1: Partial Credit Model# estimation in TAMmod1 <- TAM::tam.mml( dat )summary(mod1)#-- WLE estimation in TAMtamw1 <- TAM::tam.wle( mod1 )#-- WLE estimation with PP package# convert AXsi parameters into thres parameters for PPAXsi0 <- - mod1$AXsi[,-1]b <- AXsi0K <- ncol(AXsi0)for (cc in 2:K){ b[,cc] <- AXsi0[,cc] - AXsi0[,cc-1]}# WLE estimation in PPppw1 <- PP::PP_gpcm( respm=as.matrix(dat), thres=t(b), slopes=rep(1,I) )#-- compare resultsdfr <- cbind( tamw1[, c("theta","error") ], ppw1$resPP)head( round(dfr,3)) ## theta error resPP.estimate resPP.SE nsteps ## 1 -1.006 0.973 -1.006 0.973 8 ## 2 -0.122 0.904 -0.122 0.904 8 ## 3 0.640 0.836 0.640 0.836 8 ## 4 0.640 0.836 0.640 0.836 8 ## 5 0.640 0.836 0.640 0.836 8 ## 6 -1.941 1.106 -1.941 1.106 8plot( dfr$resPP.estimate, dfr$theta, pch=16, xlab="PP", ylab="TAM")lines( c(-10,10), c(-10,10) )#****************************************#*** Model 2: Generalized partial Credit Model# estimation in TAMmod2 <- TAM::tam.mml.2pl( dat, irtmodel="GPCM" )summary(mod2)#-- WLE estimation in TAMtamw2 <- TAM::tam.wle( mod2 )#-- WLE estimation in PP# convert AXsi parameters into thres and slopes parameters for PPAXsi0 <- - mod2$AXsi[,-1]slopes <- mod2$B[,2,1]K <- ncol(AXsi0)slopesM <- matrix( slopes, I, ncol=K )AXsi0 <- AXsi0 / slopesMb <- AXsi0for (cc in 2:K){ b[,cc] <- AXsi0[,cc] - AXsi0[,cc-1]}# estimation in PPppw2 <- PP::PP_gpcm( respm=as.matrix(dat), thres=t(b), slopes=slopes )#-- compare resultsdfr <- cbind( tamw2[, c("theta","error") ], ppw2$resPP)head( round(dfr,3)) ## theta error resPP.estimate resPP.SE nsteps ## 1 -0.476 0.971 -0.476 0.971 13 ## 2 -0.090 0.973 -0.090 0.973 13 ## 3 0.311 0.960 0.311 0.960 13 ## 4 0.311 0.960 0.311 0.960 13 ## 5 1.749 0.813 1.749 0.813 13 ## 6 -1.513 1.032 -1.513 1.032 13## End(Not run)Missing Data Patterns
Description
Determines patterns of missing values or pattern of dichotomous itemresponses.
Usage
tam_NA_pattern(x)tam_01_pattern(x)Arguments
x | Matrix or data frame |
Value
List containing pattern identifiers and indices
Examples
############################################################################## EXAMPLE 1: Missing data patterns#############################################################################data(data.sim.rasch.missing, package="TAM")dat <- data.sim.rasch.missingres <- TAM::tam_NA_pattern(dat)str(res)## Not run: ############################################################################## EXAMPLE 2: Item response patterns#############################################################################data(data.read, package="sirt")dat <- data.readres <- TAM::tam_01_pattern(dat)str(res)## End(Not run)Downcoding an Item Response Dataset
Description
Recodes item categories in a data frame such that each item has values0,1,\ldots,K_i.
Usage
tam_downcode(dat)Arguments
dat | Data frame containing item responses |
Value
List with following entries
dat | Recoded dataset |
rec | Recoding table |
Examples
############################################################################## EXAMPLE 1: Downcoding in a toy example##############################################################################-- simulate some toy dataset.seed(989)# values to be sampledvals <- c(NA, 0:6)# number of persons and itemsN <- 10; I <- 5dat <- as.data.frame(matrix(NA, nrow=N, ncol=I))colnames(dat) <- paste0("I",1:I)for (ii in 1L:I){ dat[,ii] <- sample(vals, size=N, replace=TRUE)}#-- apply downcodingres <- TAM::tam_downcode(dat)dat <- res$dat # extract downcoded datasetrec <- res$rec # extract recoded tableItem Response Function for the 3PL Model
Description
Computes the item response function for the 3PL model in theTAMpackage.
Usage
tam_irf_3pl(theta, AXsi, B, guess=NULL, subtract_max=TRUE)Arguments
theta | Matrix or vector of |
AXsi | Matrix of item-category parameters |
B | Array containing item-category loadings |
guess | Optional parameter of guessing parameters |
subtract_max | Logical indicating whether numerical underflow inprobabilities should be explicitly avoided |
Value
Array containing item response probabilities arranged by the dimensionstheta points\times items\times categories
Examples
## Not run: ############################################################################## EXAMPLE 1: 2PL example#############################################################################library(sirt)data(data.read, package="sirt")dat <- data.read#* estimate 2PL modelmod <- TAM::tam.mml.2pl( resp=dat )#* define theta vectortheta <- seq(-3,3, len=41)#* compute item response probabilitiesprobs <- TAM::tam_irf_3pl( theta=theta, AXsi=mod$AXsi, B=mod$B )str(probs)## End(Not run)Wrapper Function forTAM Language
Description
This function is a convenience wrapper function forseveral item response models inTAM. Using thetamaanify framework, multidimensional item response models,latent class models, located and ordered latent class modelsand mixture item response models can be estimated.
Usage
tamaan(tammodel, resp, tam.method=NULL, control=list(), doparse=TRUE, ...)## S3 method for class 'tamaan'summary(object,file=NULL,...)## S3 method for class 'tamaan'print(x,...)Arguments
tammodel | String for specification inTAM, see also |
resp | Dataset with item responses |
tam.method | One of theTAM methods |
control | List with control arguments. See |
doparse | Optional logical indicating whether |
... | Further arguments to be passed to |
object | Object of class |
file | A file name in which the summary output will be written |
x | Object of class |
Value
Values generated bytam.mml,tam.mml.2plortam.mml.3pl. In addition, the list also contains the (optional) entries
tamaanify | Output produced by |
lcaprobs | Matrix with probabilities for latent class models |
locs | Matrix with cluster locations (for |
probs_MIXTURE | Class probabilities (for |
moments_MIXTURE | Distribution parameters (for |
itempartable_MIXTURE | Item parameters (for |
ind_classprobs | Individual posterior probabilities forlatent classes (for |
See Also
Seetamaanify for more details about model specificationusingtammodel.
Seetam.mml ortam.mml.3plfor more examples.
Examples
## Not run: ############################################################################## EXAMPLE 1: Examples dichotomous data data.read#############################################################################library(sirt)data(data.read,package="sirt")dat <- data.read#*********************************************************************#*** Model 1: Rasch modeltammodel <- "LAVAAN MODEL: F1=~ A1__C4 F1 ~~ F1ITEM TYPE: ALL(Rasch); "# estimate modelmod1 <- TAM::tamaan( tammodel, resp=dat)summary(mod1)#*********************************************************************#*** Model 2: 2PL model with some selected itemstammodel <- "LAVAAN MODEL: F1=~ A1__B1 + B3 + C1__C3 F1 ~~ F1 "mod2 <- TAM::tamaan( tammodel, resp=dat)summary(mod2)#*********************************************************************#*** Model 3: Multidimensional IRT modeltammodel <- "LAVAAN MODEL: G=~ A1__C4 F1=~ A1__B4 F2=~ C1__C4 F1 ~~ F2 # specify fixed entries in covariance matrix F1 ~~ 1*F1 F2 ~~ 1*F2 G ~~ 0*F1 G ~~ 0.3*F2 G ~~ 0.7*G "mod3 <- TAM::tamaan( tammodel, resp=dat, control=list(maxiter=30))summary(mod3)#*********************************************************************#*** Model 4: Some linear constraints for item slopes and interceptstammodel <- "LAVAAN MODEL: F=~ lam1__lam10*A1__C2 F=~ 0.78*C3 F ~~ F A1 | a1*t1 A2 | a2*t1 A3 | a3*t1 A4 | a4*t1 B1 | b1*t1 B2 | b2*t1 B3 | b3*t1 C1 | t1MODEL CONSTRAINT: # defined parameters # only linear combinations are permitted b2==1.3*b1 + (-0.6)*b3 a1==q1 a2==q2 + t a3==q1 + 2*t a4==q2 + 3*t # linear constraints for loadings lam2==1.1*lam1 lam3==0.9*lam1 + (-.1)*lam0 lam8==lam0 lam9==lam0 "mod4 <- TAM::tamaan( tammodel, resp=dat, control=list(maxiter=5) )summary(mod4)#*********************************************************************#*** Model 5: Latent class analysis with three classestammodel <- "ANALYSIS: TYPE=LCA; NCLASSES(3); # 3 classes NSTARTS(5,20); # 5 random starts with 20 iterationsLAVAAN MODEL: F=~ A1__C4 "mod5 <- TAM::tamaan( tammodel, resp=dat, control=list(maxiter=100) )summary(mod5)#*********************************************************************#*** Model 6: Ordered latent class analysis with three classestammodel <- "ANALYSIS: TYPE=OLCA; NCLASSES(3); # 3 classes NSTARTS(20,40); # 20 random starts with 40 iterationsLAVAAN MODEL: F=~ A1__C4 "mod6 <- TAM::tamaan( tammodel, dat )summary(mod6)#*********************************************************************#*** Model 7: Unidimensional located latent class model with three classestammodel <- "ANALYSIS: TYPE=LOCLCA; NCLASSES(3) NSTARTS(10,40)LAVAAN MODEL: F=~ A1__C4 B2 | 0*t1 "mod7 <- TAM::tamaan( tammodel, resp=dat)summary(mod7)#*********************************************************************#*** Model 8: Two-dimensional located latent class analysis with some# priors and equality constraints among thresholdstammodel <- "ANALYSIS: TYPE=LOCLCA; NCLASSES(4); NSTARTS(10,20);LAVAAN MODEL: AB=~ A1__B4 C=~ C1__C4 A1 | a1diff*t1 B2 | 0*t1 C2 | 0*t1 B1 | a1diff*t1MODEL PRIOR: # prior distributions for cluster locations DO2(1,4,1,1,2,1) Cl%1_Dim%2 ~ N(0,2); DOEND "# estimate modelmod8 <- TAM::tamaan( tammodel, resp=dat )summary(mod8)#*********************************************************************#*** Model 9: Two-dimensional model with constraints on parameterstammodel <- "LAVAAN MODEL: FA=~ A1+b*A2+A3+d*A4 FB=~ B1+b*B2+B3+d*B4 FA ~~ 1*FA FA ~~ FB FB ~~ 1*FB A1 | c*t1 B1 | c*t1 A2 | .7*t1 "# estimate modelmod9 <- TAM::tamaan( tammodel, resp=dat, control=list(maxiter=30) )summary(mod9)############################################################################## EXAMPLE 2: Examples polytomous data | data.Students#############################################################################library(CDM)data( data.Students, package="CDM")dat <- data.Students[,3:13] ## > colnames(dat) ## [1] "act1" "act2" "act3" "act4" "act5" "sc1" "sc2" "sc3" "sc4" "mj1" "mj2"#*********************************************************************#*** Model 1: Two-dimensional generalized partial credit modeltammodel <- "LAVAAN MODEL: FA=~ act1__act5 FS=~ sc1__sc4 FA ~~ 1*FA FS ~~ 1*FS FA ~~ FS "# estimate modelmod1 <- TAM::tamaan( tammodel, dat, control=list(maxiter=10) )summary(mod1)#*********************************************************************#*** Model 2: Two-dimensional model, some constraintstammodel <- "LAVAAN MODEL: FA=~ a1__a4*act1__act4 + 0.89*act5 FS=~ 1*sc1 + sc2__sc4 FA ~~ FA FS ~~ FS FA ~~ FS # some equality constraints act1 + act3 | a13_t1 * t1 act1 + act3 | a13_t2 * t2 "# only create design matrices with tamaanifymod2 <- TAM::tamaanify( tammodel, dat )mod2$lavpartable# estimate model (only few iterations as a test)mod2 <- TAM::tamaan( tammodel, dat, control=list(maxiter=10) )summary(mod2)#*********************************************************************#*** Model 3: Two-dimensional model, some more linear constraintstammodel <- "LAVAAN MODEL: FA=~ a1__a5*act1__act5 FS=~ b1__b4*sc1__sc4 FA ~~ 1*FA FA ~~ FS FS ~~ 1*FS act1 + act3 | a13_t1 * t1 act1 + act3 | a13_t2 * t2MODEL CONSTRAINT: a1==q0 a2==q0 a3==q0 + q1 a4==q2 a5==q2 + q1 "# estimatemod3 <- TAM::tamaan( tammodel, dat, control=list(maxiter=300 ) )summary(mod3)#*********************************************************************#*** Model 4: Latent class analysis with three latent classestammodel <- "ANALYSIS: TYPE=LCA; NCLASSES(3); # 3 classes NSTARTS(10,30); # 10 random starts with 30 iterationsLAVAAN MODEL: F=~ act1__act5 "# estimate modelmod4 <- TAM::tamaan( tammodel, resp=dat)summary(mod4)#*********************************************************************#*** Model 5: Partial credit model with "PCM2" parametrization# select datadat1 <- dat[, paste0("act",1:5) ]# specify tamaan modeltammodel <- " LAVAAN MODEL: F=~ act1__act5 F ~~ F # use DO statement as shortages DO(1,5,1) act% | b%_1 * t1 act% | b%_2 * t2 DOEND MODEL CONSTRAINT: DO(1,5,1) b%_1==delta% + tau%_1 b%_2==2*delta% DOEND ITEM TYPE: ALL(PCM) "# estimate modelmod5 <- TAM::tamaan( tammodel, dat1 )summary(mod5)# compare with PCM2 parametrization in tam.mmlmod5b <- TAM::tam.mml( dat1, irtmodel="PCM2" )summary(mod5b)#*********************************************************************#*** Model 6: Rating scale model# select datadat1 <- dat[, paste0("sc",1:4) ]psych::describe(dat1)# specify tamaan modeltammodel <- " LAVAAN MODEL: F=~ sc1__sc4 F ~~ F # use DO statement as shortages DO(1,4,1) sc% | b%_1 * t1 sc% | b%_2 * t2 sc% | b%_3 * t3 DOEND MODEL CONSTRAINT: DO(1,4,1) b%_1==delta% + step1 b%_2==2*delta% + step1 + step2 b%_3==3*delta% DOEND ITEM TYPE: ALL(PCM) "# estimate modelmod6 <- TAM::tamaan( tammodel, dat1 )summary(mod6)# compare with RSM in tam.mmlmod6b <- TAM::tam.mml( dat1, irtmodel="RSM" )summary(mod6b)#*********************************************************************#*** Model 7: Partial credit model with Fourier basis for# item intercepts (Thissen, Cai & Bock, 2010)# see ?tamaanify manual# define tamaan modeltammodel <- "LAVAAN MODEL: mj=~ mj1__mj4 mj ~~ 1*mjITEM TYPE: mj1(PCM,2) mj2(PCM,3) mj3(PCM) mj4(PCM,1) "# estimate modelmod7 <- TAM::tamaan( tammodel, dat )summary(mod7)# -> This function can also be applied for the generalized partial credit# model (GPCM).############################################################################## EXAMPLE 3: Rasch model and mixture Rasch model (Geiser & Eid, 2010)#############################################################################data(data.geiser, package="TAM")dat <- data.geiser#*********************************************************************#*** Model 1: Rasch modeltammodel <- "LAVAAN MODEL: F=~ mrt1__mrt6 F ~~ FITEM TYPE: ALL(Rasch); "mod1 <- TAM::tamaan( tammodel, resp=dat )summary(mod1)#*********************************************************************#*** Model 2: Mixed Rasch model with two classestammodel <- "ANALYSIS: TYPE=MIXTURE ; NCLASSES(2); NSTARTS(20,25);LAVAAN MODEL: F=~ mrt1__mrt6 F ~~ FITEM TYPE: ALL(Rasch); "mod2 <- TAM::tamaan( tammodel, resp=dat )summary(mod2)# plot item parametersipars <- mod2$itempartable_MIXTURE[ 1:6, ]plot( 1:6, ipars[,3], type="o", ylim=c(-3,2), pch=16, xlab="Item", ylab="Item difficulty")lines( 1:6, ipars[,4], type="l", col=2, lty=2)points( 1:6, ipars[,4], col=2, pch=2)# extract individual posterior distributionpost2 <- IRT.posterior(mod2)str(post2)# num [1:519, 1:30] 0.000105 0.000105 0.000105 0.000105 0.000105 ...# - attr(*, "theta")=num [1:30, 1:30] 1 0 0 0 0 0 0 0 0 0 ...# - attr(*, "prob.theta")=num [1:30, 1] 1.21e-05 2.20e-04 2.29e-03 1.37e-02 4.68e-02 ...# - attr(*, "G")=num 1# There are 2 classes and 15 theta grid points for each class# The loadings of the theta grid on items are as followsmod2$E[1,2,,"mrt1_F_load_Cl1"]mod2$E[1,2,,"mrt1_F_load_Cl2"]# compute individual posterior probability for class 1 (first 15 columns)round( rowSums( post2[, 1:15] ), 3 )# columns 16 to 30 refer to class 2## End(Not run)Function for ParsingTAM Input
Description
This function parses a so calledtammodel which is astring used for model estimation inTAM.The function is based on thelavaan syntax and operatesat the extensionlavaanify.IRT.
Usage
tamaanify(tammodel, resp, tam.method=NULL, doparse=TRUE )Arguments
tammodel | String for model definition following the rules described in Details andin Examples. |
resp | Item response dataset |
tam.method | One of theTAM methods |
doparse | Optional logical indicating whether |
Details
The model syntaxtammodel consists of several sections.Some of them are optional.
ANALYSIS:
Possible model types are unidimensional and multidimensionalitem response models (TYPE="TRAIT"), latent class models("LCA"), located latent class models ("LOCLCA";e.g. Formann, 1989; Bartolucci, 2007),ordered latent class models ("OLCA"; only works fordichotomous item responses; e.g. Hoijtink, 1997; Shojima, 2007) andmixture distribution models ("MIXTURE"; e.g. von Davier, 2007).
LAVAAN MODEL:
For specification of the syntax, seelavaanify.IRT.
MODEL CONSTRAINT:
Linear constraints can be specified by using conventionalspecification inR syntax. All terms must be combinedwith the+ operator. Equality constraints areset by using the== operator as inlavaan.
ITEM TYPE:
The following item types can be defined: Rasch model (Rasch),the 2PL model (2PL), partial credit model (PCM)and the generalized partial credit model (GPCM).
The item intercepts can also be smoothed for thePCMand theGPCM by using a Fourier basis proposed byThissen, Cai and Bock (2010). For an item with a maximumof score ofK, a smoothed partial credit modelis requested byPCM(kk) wherekk is aninteger between 1 andK. Withkk=1, only a linearfunction is used. The subsequent integers correspond toFourier functions with decreasing periods.See Example 2, Model 7 of thetamaanfunction.
PRIOR:
Possible prior distributions: Normal distributionN(mu,sd),truncated normal distributionTN(mu,sd,low,upp) andBeta distributionBeta(a,b).Parameter labels and prior specification must be separatedby~.
Value
A list with following (optional) entrieswhich are used as input in one of theTAM functionstam.mml,tam.mml.2pl ortam.mml.3pl:
tammodel | Model input forTAM |
tammodel.dfr | Processed |
ANALYSIS | Syntax specified in |
ANALYSIS.list | Parsed specifications in |
LAVAANMODEL | Syntax specified in |
lavpartable | Parameter table processed by thesyntax in |
items | Informations about items: Number of categories,specified item response function |
maxcat | Maximum number of categories |
ITEMTYPE | Syntax specified in |
MODELCONSTRAINT | Syntax specified in |
MODELCONSTRAINT.dfr | Processed syntax in |
modelconstraint.thresh | Processed data frame for model constraint of thresholds |
modelconstraint.loading | Processed data frame for loadings |
resp | Data set for usage |
method | UsedTAM function |
A | Design matrix A |
Q | Design matrix for loadings |
Q.fixed | Fixed values in |
B.fixed | Matrix with fixed item loadings(used for |
L | Processed design matrix for loadings when thereare model constraints for loadings |
variance.fixed | Matrix for specification of fixed valuesin covariance matrix |
est.variance | Logical indicating whether variance shouldbe estimated ( |
theta.k | Theta design matrix |
E | Design matrix E |
notA | Logical indicating whether |
gammaslope.fixed | Fixed |
gammaslope.prior | Prior distributions for |
xsi.fixed | Fixed |
xsi.prior | Prior distributions for |
References
Bartolucci, F. (2007). A class of multidimensional IRT models for testingunidimensionality and clustering items.Psychometrika, 72, 141-157.doi:10.1007/s11336-005-1376-9
Formann, A. K. (1989). Constrained latent class models: Some furtherapplications.British Journal of Mathematical and StatisticalPsychology, 42, 37-54.doi:10.1111/j.2044-8317.1989.tb01113.x
Hojtink, H., & Molenaar, I. W. (1997). A multidimensional item response model:Constrained latent class analysis using the Gibbs sampler and posteriorpredictive checks.Psychometrika, 62(2), 171-189.doi:10.1007/BF02295273
Thissen, D., Cai, L., & Bock, R. D. (2010).The nominal categories item response model.In M. L. Nering & Ostini, R. (Eds.).Handbook of Polytomous Item Response Models(pp. 43-75). New York: Routledge.
Shojima, K. (2007).Latent rank theory: Estimation of item referenceprofile by marginal maximum likelihood method with EM algorithm.DNC Research Note 07-12.
von Davier, M. (2007).Mixture distribution diagnostic models.ETS Research Report ETS RR-07-32. Princeton, ETS.doi:10.1002/j.2333-8504.2007.tb02074.x
See Also
Seetamaan for more examples. Other examplesare included intam.mml andtam.mml.3pl.
Examples
## Not run: ############################################################################## EXAMPLE 1: Examples dichotomous data data.read#############################################################################library(sirt)data(data.read,package="sirt")dat <- data.read#*********************************************************************#*** Model 1: 2PL estimation with some fixed parameters and# equality constraintstammodel <- "LAVAAN MODEL: F2=~ C1__C2 + 1.3*C3 + C4 F1=~ A1__B1 # fixed loading of 1.4 for item B2 F1=~ 1.4*B2 F1=~ B3 F1 ~~ F1 F2 ~~ F2 F1 ~~ F2 B1 | 1.23*t1 ; A3 | 0.679*t1 A2 | a*t1 ; C2 | a*t1 ; C4 | a*t1 C3 | x1*t1 ; C1 | x1*t1ITEM TYPE: A1__A3 (Rasch) ; A4 (2PL) ; B1__C4 (Rasch) ; "# process modelout <- TAM::tamaanify( tammodel, resp=dat)# inspect some outputout$method # used TAM functionout$lavpartable # lavaan parameter table#*********************************************************************#*** Model 2: Latent class analysis with three classestammodel <- "ANALYSIS: TYPE=LCA; NCLASSES(3); # 3 classes NSTARTS(5,20); # 5 random starts with 20 iterationsLAVAAN MODEL: F=~ A1__C4 "# process syntaxout <- TAM::tamaanify( tammodel, resp=dat)str(out$E) # E design matrix for estimation with tam.mml.3pl function#*********************************************************************#*** Model 3: Linear constraints for item intercepts and item loadingstammodel <- "LAVAAN MODEL: F=~ lam1__lam10*A1__C2 F ~~ F A1 | a1*t1 A2 | a2*t1 A3 | a3*t1 A4 | a4*t1 B1 | b1*t1 B2 | b2*t1 B3 | b3*t1 C1 | t1MODEL CONSTRAINT: # defined parameters # only linear combinations are permitted b2==1.3*b1 + (-0.6)*b3 a1==q1 a2==q2 + t a3==q1 + 2*t a4==q2 + 3*t # linear constraints for loadings lam2==1.1*lam1 lam3==0.9*lam1 + (-.1)*lam0 lam8==lam0 lam9==lam0 "# parse syntaxmod1 <- TAM::tamaanify( tammodel, resp=dat)mod1$A # design matrix A for interceptsmod1$L[,1,] # design matrix L for loadings## End(Not run)############################################################################## EXAMPLE 2: Examples polytomous data data.Students#############################################################################library(CDM)data( data.Students, package="CDM")dat <- data.Students[,3:13]#*********************************************************************#*** Model 1: Two-dimensional generalized partial credit modeltammodel <- "LAVAAN MODEL: FA=~ act1__act5 FS=~ sc1__sc4 FA ~~ 1*FA FS ~~ 1*FS FA ~~ FS act1__act3 | t1 sc2 | t2 "out <- TAM::tamaanify( tammodel, resp=dat)out$A # design matrix for item interceptsout$Q # loading matrix for items#*********************************************************************#*** Model 2: Linear constraints# In the following syntax, linear equations for multiple constraints# are arranged over multiple lines.tammodel <- " LAVAAN MODEL: F=~ a1__a5*act1__act5 F ~~ F MODEL CONSTRAINT: a1==delta + tau1 a2==delta a3==delta + z1 a4==1.1*delta + 2*tau1 + (-0.2)*z1 "# tamaanify modelres <- TAM::tamaanify( tammodel, dat )res$MODELCONSTRAINT.dfrres$modelconstraint.loadingConversion of Plausible Value Object into Datalist
Description
Converts atam.pv object and a matrix of covariatesinto a list of multiply imputed datasets. This list can be convenientlyanalyzed byR packages such assemTools,Zelig,miceorBIFIEsurvey.
Usage
tampv2datalist(tam.pv.object, pvnames=NULL, Y=NULL, Y.pid="pid", as_mids=FALSE, stringsAsFactors=FALSE)Arguments
tam.pv.object | Generated |
pvnames | Variable names of generated plausible values |
Y | Matrix with covariates |
Y.pid | Person identifier in |
as_mids | Logical indicating whether the datalistshould be converted into an object of class |
stringsAsFactors | Logical indicating whether strings in the data frameshould be converted into factors |
Value
List of multiply imputed datasets or anmids object
See Also
For examples seetam.pv.
Descriptive Statistics for Weighted Data
Description
Some descriptive statistics for weighted data: variance,standard deviation, means, skewness, excess kurtosis, quantiles andfrequency tables. Missing values are automatically removed fromthe data.
Usage
weighted_mean(x, w=rep(1, length(x)), select=NULL )weighted_var(x, w=rep(1, length(x)), method="unbiased", select=NULL )weighted_sd(x, w=rep(1, length(x)), method="unbiased", select=NULL )weighted_skewness( x, w=rep(1,length(x)), select=NULL )weighted_kurtosis( x, w=rep(1,length(x)), select=NULL )weighted_quantile( x, w=rep(1,length(x)), probs=seq(0,1,.25), type=NULL, select=NULL )weighted_table( x, w=NULL, props=FALSE )Arguments
x | A numeric vector. For |
w | Optional vector of sample weights |
select | Vector referring to selected cases |
method | Computation method (can be |
probs | Vector with probabilities |
type | Quantile type. For unweighted data, quantile types 6 and7 can be used (see |
props | Logical indicating whether relative or absolutefrequencies should be calculated. |
Value
Numeric value
See Also
Seestats::weighted.mean forcomputing a weighted mean.
Seestats::var for computingunweighted variances.
Seestats::quantile andHmisc::wtd.quantile) for quantiles.
Examples
############################################################################## EXAMPLE 1: Toy example for weighted_var function#############################################################################set.seed(9897)# simulate dataN <- 10x <- stats::rnorm(N)w <- stats::runif(N)#---- variance# use weighted_varweighted_var( x=x, w=w )# use cov.wtstats::cov.wt( data.frame(x=x), w=w )$cov[1,1]## Not run: # use wtd.var from Hmisc packageHmisc::wtd.var(x=x, weights=w, normwt=TRUE, method="unbiased")#---- standard deviationweighted_sd( x=x, w=w )#---- meanweighted_mean( x=x, w=w )stats::weighted.mean( x=x, w=w )#---- weighted quantiles for unweighted datapvec <- c(.23, .53, .78, .99 ) # choose probabilitiestype <- 7# quantiles for unweighted dataweighted_quantile( x, probs=pvec, type=type)quantile( x, probs=pvec, type=type)Hmisc::wtd.quantile(x,probs=pvec, type=type)# quantiles for weighted datapvec <- c(.23, .53, .78, .99 ) # probabilitiesweighted_quantile( x, w=w, probs=pvec)Hmisc::wtd.quantile(x, weights=w, probs=pvec)#--- weighted skewness and kurtosisweighted_skewness(x=x, w=w)weighted_kurtosis(x=x, w=w)############################################################################## EXAMPLE 2: Descriptive statistics normally distributed data############################################################################## simulate some normally distributed dataset.seed(7768)x <- stats::rnorm( 10000, mean=1.7, sd=1.2)# some statisticsweighted_mean(x=x)weighted_sd(x=x)weighted_skewness(x=x)weighted_kurtosis(x=x)############################################################################## EXAMPLE 3: Frequency tables##############################################################################*****# simulate data for weighted frequency tablesy <- scan() 1 0 1 1 1 2 1 3 1 4 2 0 2 1 2 2 2 3 2 4y <- matrix( y, ncol=2, byrow=TRUE)# define probabilitiesset.seed(976)pr <- stats::runif(10)pr <- pr / sum(pr)# sample dataN <- 300x <- y[ sample( 1:10, size=300, prob=pr, replace=TRUE ), ]w <- stats::runif( N, 0.5, 1.5 )# frequency table unweighted dataweighted_table(x[,2] )table( x[,2] )# weighted data and proportionsweighted_table(x[,2], w=w, props=TRUE)#*** contingency tabletable( x[,1], x[,2] )weighted_table( x )# table using weightsweighted_table( x, w=w )## End(Not run)