fit.irtree_model: Fit an ItemResponseTrees model

Description Usage Arguments Value Methods Examples

View source: R/fit.R

Description

This function takes a data frame and an object of class irtree_model and runs the model in either mirt, Mplus, or TAM.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## S3 method for class 'irtree_model'
fit(
  object = NULL,
  data = NULL,
  engine = c("mirt", "mplus", "tam"),
  ...,
  link = c("logit", "probit"),
  verbose = interactive(),
  control = NULL,
  improper_okay = FALSE
)

Arguments

object

Object of class irtree_model. See irtree_model for more information.

data

Data frame containing containing one row per respondent and one column per variable. The variable names must correspond to those used in object.

engine

String specifying whether to use mirt, Mplus, or TAM for estimation.

...

Not currently used. Use control instead.

link

String specifying the link function. May be either logit, or (in case of Mplus), probit.

verbose

Logical indicating whether output should be printed to the console.

control

List. The allowed elements of this list depend on the engine. Use control_mirt(), control_mplus(), or control_tam() for convenience. Note that the fit() function does not use ..., but that you can use the control_*() functions to pass additional arguments.

improper_okay

Logical indicating whether the model should also be fit if it is not a proper IR-tree model. Set this only to TRUE if you really know what you are doing.

Value

Returns a list of class irtree_fit. The first list element is the return value of either mirt::mirt(), MplusAutomation::readModels(), or TAM::tam.mml(). Further information is provided in the element spec.

Methods

The methods coef(), summary(), and print() are implemented for objects of class irtree_fit, and those wrap the respective functions of mirt, MplusAutomation, or TAM. However, glance(), tidy(), and augment() may be more helpful.

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
# Running these examples may take a while

data("jackson")
df1 <- jackson[1:456, paste0("C", 1:5)]
df2 <- jackson[1:456, c(paste0("C", 1:5), paste0("E", 1:5))]

irtree_create_template(df1)

# Graded Response Model ---------------------------------------------------

m1 <- "
IRT:
t BY C1@1, C2@1, C3@1, C4@1, C5@1;

Class:
GRM
"

model1 <- irtree_model(m1)

fit1 <- fit(model1, data = df1)

glance(fit1)
tidy(fit1, par_type = "difficulty")
augment(fit1)

# IR-Tree Models ----------------------------------------------------------

##### IR-tree model for 1 target trait #####

m2 <- "
Equations:
1 = (1-m)*(1-t)*e
2 = (1-m)*(1-t)*(1-e)
3 = m
4 = (1-m)*t*(1-e)
5 = (1-m)*t*e

IRT:
t BY C1@1, C2@1, C3@1, C4@1, C5@1;
e BY C1@1, C2@1, C3@1, C4@1, C5@1;
m BY C1@1, C2@1, C3@1, C4@1, C5@1;

Class:
Tree
"

model2 <- irtree_model(m2)

# See ?mirt::mirt for details on method argument
fit2 <- fit(model2, data = df1, control = control_mirt(method = "MHRM"))

##### IR-tree model for 2 target traits #####

m3 <- "
Equations:
1 = (1-m)*(1-t)*e
2 = (1-m)*(1-t)*(1-e)
3 = m
4 = (1-m)*t*(1-e)
5 = (1-m)*t*e

IRT:
t1 BY C1@1, C2@1, C3@1, C4@1, C5@1;
t2 BY E1@1, E2@1, E3@1, E4@1, E5@1;
e  BY C1@1, C2@1, C3@1, C4@1, C5@1, E1@1, E2@1, E3@1, E4@1, E5@1;
m  BY C1@1, C2@1, C3@1, C4@1, C5@1, E1@1, E2@1, E3@1, E4@1, E5@1;

Class:
Tree

Constraints:
t = t1 | t2
"

model3 <- irtree_model(m3)

fit3 <- fit(model3, data = df2, control = control_mirt(method = "MHRM"))

##### IR-tree model constrained to Steps Model #####

m4 <- "
Equations:
1 = (1-a1)
2 = a1*(1-a2)
3 = a1*a2*(1-a3)
4 = a1*a2*a3*(1-a4)
5 = a1*a2*a3*a4

IRT:
a1 BY C1@1, C2@1, C3@1, C4@1, C5@1;
a2 BY C1@1, C2@1, C3@1, C4@1, C5@1;
a3 BY C1@1, C2@1, C3@1, C4@1, C5@1;
a4 BY C1@1, C2@1, C3@1, C4@1, C5@1;

Class:
Tree

Constraints:
a1 = a2
a1 = a3
a1 = a4
"

model4 <- irtree_model(m4)

fit4 <- fit(model4, data = df1)

# Partial Credit Model ----------------------------------------------------

##### Ordinary PCM #####

m5 <- "
IRT:
t BY C1@1, C2@1, C3@1, C4@1, C5@1;

Weights:
t = c(0, 1, 2, 3, 4)

Class:
PCM
"

model5 <- irtree_model(m5)

fit5 <- fit(model5, data = df1 - 1, engine = "tam")

##### Multidimensional PCM with constraints #####

m6 <- "
IRT:
t1 BY C1@1, C2@1, C3@1, C4@1, C5@1;
t2 BY E1@1, E2@1, E3@1, E4@1, E5@1;
e  BY C1@1, C2@1, C3@1, C4@1, C5@1, E1@1, E2@1, E3@1, E4@1, E5@1;
m  BY C1@1, C2@1, C3@1, C4@1, C5@1, E1@1, E2@1, E3@1, E4@1, E5@1;

Weights:
t = c(0, 1, 2, 3, 4)
e = c(1, 0, 0, 0, 1)
m = c(0, 0, 1, 0, 0)

Class:
PCM

Constraints:
t = t1 | t2
"

model6 <- irtree_model(m6)

fit6 <- fit(model6, data = df2 - 1, engine = "tam",
            control = control_tam(control = list(snodes = 1234)))

ItemResponseTrees documentation built on July 2, 2020, 2:25 a.m.