tamaan: Wrapper Function for 'TAM' Language

Description Usage Arguments Value See Also Examples

View source: R/tamaan.R

Description

This function is a convenience wrapper function for several item response models in TAM. Using the tamaanify framework, multidimensional item response models, latent class models, located and ordered latent class models and mixture item response models can be estimated.

Usage

1
2
3
4
5
6
7
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 in TAM, see also tamaanify.

resp

Dataset with item responses

tam.method

One of the TAM methods tam.mml, tam.mml.2pl or tam.mml.3pl.

control

List with control arguments. See tam.mml.

doparse

Optional logical indicating whether lavmodel should be parsed for DO statements, see doparse.

...

Further arguments to be passed to tam.mml, tam.mml.2pl or tam.mml.3pl.

object

Object of class tamaan

file

A file name in which the summary output will be written

x

Object of class tamaan

Value

Values generated by tam.mml, tam.mml.2pl or tam.mml.3pl. In addition, the list also contains the (optional) entries

tamaanify

Output produced by tamaanify

lcaprobs

Matrix with probabilities for latent class models

locs

Matrix with cluster locations (for TYPE="LOCLCA")

probs_MIXTURE

Class probabilities (for TYPE="MIXTURE")

moments_MIXTURE

Distribution parameters (for TYPE="MIXTURE")

itempartable_MIXTURE

Item parameters (for TYPE="MIXTURE")

ind_classprobs

Individual posterior probabilities for latent classes (for TYPE="MIXTURE")

See Also

See tamaanify for more details about model specification using tammodel.

See tam.mml or tam.mml.3pl for more examples.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#############################################################################
# EXAMPLE 1: Examples dichotomous data data.read
#############################################################################

library(sirt)
data(data.read,package="sirt")
dat <- data.read

#*********************************************************************
#*** Model 1: Rasch model

tammodel <- "
LAVAAN MODEL:
  F1=~ A1__C4
  F1 ~~ F1
ITEM TYPE:
  ALL(Rasch);
    "
# estimate model
mod1 <- TAM::tamaan( tammodel, resp=dat)
summary(mod1)

## Not run: 
#*********************************************************************
#*** Model 2: 2PL model with some selected items

tammodel <- "
LAVAAN MODEL:
  F1=~ A1__B1 + B3 + C1__C3
  F1 ~~ F1
    "
mod2 <- TAM::tamaan( tammodel, resp=dat)
summary(mod2)

#*********************************************************************
#*** Model 3: Multidimensional IRT model

tammodel <- "
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 intercepts

tammodel <- "
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 | t1
MODEL 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 classes

tammodel <- "
ANALYSIS:
  TYPE=LCA;
  NCLASSES(3);   # 3 classes
  NSTARTS(5,20); # 5 random starts with 20 iterations
LAVAAN MODEL:
  F=~ A1__C4
    "
mod5 <- TAM::tamaan( tammodel, resp=dat, control=list(maxiter=100)  )
summary(mod5)

#*********************************************************************
#*** Model 6: Ordered latent class analysis with three classes

tammodel <- "
ANALYSIS:
  TYPE=OLCA;
  NCLASSES(3);    # 3 classes
  NSTARTS(20,40); # 20 random starts with 40 iterations
LAVAAN MODEL:
  F=~ A1__C4
    "
mod6 <- TAM::tamaan( tammodel, dat )
summary(mod6)

#*********************************************************************
#*** Model 7: Unidimensional located latent class model with three classes

tammodel <- "
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 thresholds

tammodel <- "
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*t1
MODEL PRIOR:
  # prior distributions for cluster locations
  DO2(1,4,1,1,2,1)
    Cl%1_Dim%2 ~ N(0,2);
  DOEND
    "
# estimate model
mod8 <- TAM::tamaan( tammodel, resp=dat )
summary(mod8)

#*********************************************************************
#*** Model 9: Two-dimensional model with constraints on parameters

tammodel <- "
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 model
mod9 <- 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 model

tammodel <- "
LAVAAN MODEL:
  FA=~ act1__act5
  FS=~ sc1__sc4
  FA ~~ 1*FA
  FS ~~ 1*FS
  FA ~~ FS
    "
# estimate model
mod1 <- TAM::tamaan( tammodel, dat, control=list(maxiter=10)  )
summary(mod1)

#*********************************************************************
#*** Model 2: Two-dimensional model, some constraints

tammodel <- "
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 tamaanify
mod2 <- 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 constraints

tammodel <- "
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 * t2
MODEL CONSTRAINT:
  a1==q0
  a2==q0
  a3==q0    + q1
  a4==q2
  a5==q2 + q1
    "
# estimate
mod3 <- TAM::tamaan( tammodel, dat, control=list(maxiter=300 )  )
summary(mod3)

#*********************************************************************
#*** Model 4: Latent class analysis with three latent classes

tammodel <- "
ANALYSIS:
  TYPE=LCA;
  NCLASSES(3);    # 3 classes
  NSTARTS(10,30); # 10 random starts with 30 iterations
LAVAAN MODEL:
  F=~ act1__act5
    "
# estimate model
mod4 <- TAM::tamaan( tammodel, resp=dat)
summary(mod4)

#*********************************************************************
#*** Model 5: Partial credit model with "PCM2" parametrization

# select data
dat1 <- dat[, paste0("act",1:5) ]
# specify tamaan model
tammodel <- "
  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 model
mod5 <- TAM::tamaan( tammodel, dat1 )
summary(mod5)
# compare with PCM2 parametrization in tam.mml
mod5b <- TAM::tam.mml( dat1, irtmodel="PCM2" )
summary(mod5b)

#*********************************************************************
#*** Model 6: Rating scale model

# select data
dat1 <- dat[, paste0("sc",1:4) ]
psych::describe(dat1)

# specify tamaan model
tammodel <- "
  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 model
mod6 <- TAM::tamaan( tammodel, dat1 )
summary(mod6)
# compare with RSM in tam.mml
mod6b <- 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 model
tammodel <- "
LAVAAN MODEL:
   mj=~ mj1__mj4
   mj ~~ 1*mj
ITEM TYPE:
  mj1(PCM,2)
  mj2(PCM,3)
  mj3(PCM)
  mj4(PCM,1)
   "
# estimate model
mod7 <- 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 model
tammodel <- "
LAVAAN MODEL:
  F=~ mrt1__mrt6
  F ~~ F
ITEM TYPE:
  ALL(Rasch);
    "
mod1 <- TAM::tamaan( tammodel, resp=dat  )
summary(mod1)

#*********************************************************************
#*** Model 2: Mixed Rasch model with two classes
tammodel <- "
ANALYSIS:
  TYPE=MIXTURE ;
  NCLASSES(2);
  NSTARTS(20,25);
LAVAAN MODEL:
  F=~ mrt1__mrt6
  F ~~ F
ITEM TYPE:
  ALL(Rasch);
    "
mod2 <- TAM::tamaan( tammodel, resp=dat  )
summary(mod2)

# plot item parameters
ipars <- 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 distribution
post2 <- 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 follows
mod2$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)

TAM documentation built on June 25, 2021, 5:13 p.m.