brRasch: Fitting fixed-effects IRT models using bias-reducing adjusted...

Description Usage Arguments Details Value Examples

View source: R/brRasch.R

Description

'brRasch' is used to fit fixed-effects IRT models by inputting the data in a matrix format and specifying the constraints.

Usage

1
2
3
4
5
brRasch(data, weights, itemsName = "item", subjectsName = "subject",
  dim = 1, br = FALSE, startmaxit = 5, startadjustment = 0.1,
  startmethod = "BFGS", fsmaxit = 1000, fstol = 1e-04, fsridge = 0.001,
  fsinitstepfactor = 1, trace = FALSE, start = NULL, constraints,
  fix = FALSE, penalty = c("none", "L2", "L2discr"), tuning = 0)

Arguments

data

a matrix of counts or an object of class compressed. If a matrix of counts is inputted then the rows must correspond to subjects and the columns to items.

weights

a matrix of weights. If left unspecfied then it is assummed to be a matrix of 1 of the same dimension as data. If data is an object of class compressed then the value of weights will be ignored

itemsName

character string specifying the prefix to be used on the column index of data. It is used to specify meanigful names for the model parameters and applied only when colnames(data) is NULL

subjectsName

character string specifying the prefix to be used on the row index of data. It is used to specify meanigful names for the model parameters and applied only when rownames(data) is NULL

dim

non-negative integer. It specifies the dimension of the Rasch model. See Details for more information

br

logical scalar. Specified whether fitting whould be done using bias reduction (TRUE) or maximum likelihood (FALSE)

startmaxit

a positive integer. The maximum number of iterations for the calculation of starting values.

startadjustment

a positive scalar. The data is adjusted as startadjustment + data*(1 - 2*startadjustment) prior to the calculation of starting values. If data is of class compressed then data$data*data$weights is adjusted instead

startmethod

the method to be used in the optim call when calculated starting values. See optim for details

fsmaxit

non-negative interger. Maximum allowed number of (quasi-) Fisher scoring iterations

fstol

a positive scalar. If the absolute value of the step-size for all parameters is less than fstol, then the (quasi-) Fisher scoring iteration stops and the maximum likelihood or reduced-bias estimates are deeemed found

fsridge

a positive scalar by which the diagonal elements of the expected information matrix are inflated prior to inversion

fsinitstepfactor

positive integer. the step-size in the (quasi-) Fisher scoring iterations is initially scaled by 2^(-fsinitstepfactor) and then depending on whether there is an increase in step the scaling factor is sequentially reduced to 2^(-fsinitstepfactor - 1), 2^(-fsinitstepfactor - 2), and so on. See Details for more information on the fitting procedure

trace

either a logical scalar or a positive integer. If TRUE then trace information is being printed at each iteration of the (quasi-) Fisher scoring algorithm. If positive integer then information is printed only for the iterations that satisfy iter %% trace == 0

start

a vector of starting values for the model parameters. It should be of length I + dim*(S + I) where S is nrow(data) and I is ncol(data)

constraints

a setConstraints object. If left unspecified then brRasch will prompt the user in setting the constraints using relimp::pickFrom

penalty

character string specifying the type of reguralization penalty to be used in estimation. See Details for more information

tuning

a numeric vector specifying the value for the tuning parameters

Details

If dim = 0 then an 1PL model is fit. Any input in constraints is ignored and the constraints are set internally for a 2PL model by fixing the 'first' easiness parameter to 0 and all discrimination parameters to 1.

Value

coefficients

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
data(LSAT)

## Use the weighted Bernoulli representation to get the
## coefficients quickly
LSATCompressed <- compress(LSAT)

## Fit a 2PL model to an adjusted version of LSAT data using ML the
## adjustment is p/(2n) which is bias-reducing in logistic regression
## and ensures finiteness of the estimates (see Cordeiro & McCullagh,
## 1991 for details)
adj <- (nrow(LSAT) + 2*ncol(LSAT))/(2*nrow(LSAT)*ncol(LSAT))
lsatCompressed <- within.list(LSATCompressed, data <- adj + data*(1 - 2*adj))


## Set the contrasts so that the first easiness and first
## discrimination parameters are 0 and 1, respectively
constrc <- setConstraintsRasch(data = lsatCompressed$data,
                               dim = 1,
                               which = c(1, 6),
                               values = c(0, 1))

## Fit the 2PL model under those constraints
fitML <- brRasch(lsatCompressed, constraints = constrc, br = FALSE)

## Not run: 
    ## Plot the IRF from the adjusted data
    irf(fitML)

## End(Not run)

## In order to fit a Rasch model to the same data set the constrints so
## that all discrimination parameters are 1
constrc0 <- setConstraintsRasch(data = lsatCompressed$data,
                                dim = 1,
                                which = c(1, 6, 7, 8, 9, 10),
                                values = c(0, 1, 1, 1, 1, 1))

## Fit the 2PL model under those constraints.
fitML0 <- brRasch(lsatCompressed, constraints = constrc0, br = FALSE)

## Crosscheck that the fit is right by comparing with glm
lsatLong <- reshape(lsatCompressed$data, direction = "long",
                    varying = names(lsatCompressed$data),
                    v.names = "y", timevar = "item", idvar = "subject")
lsatLong$w <- reshape(lsatCompressed$weights, direction = "long",
                      varying = names(lsatCompressed$data),
                      v.names = "w", timevar = "item", idvar = "subject")$w
lsatLong <- within(lsatLong, {
    item <- factor(item)
    subject <- factor(subject) })
fitML0glm <- glm(y ~ -1 + subject + item, weights = w, family = binomial, data = lsatLong)

## The coefficients are numerically the same
coef(fitML0)
coef(fitML0glm)

## Not run: 
    ## The IRFs for fitML0 have the same slope
    irf(fitML0)

## End(Not run)

## Now get an intermediate fit between Rasch and 2PL by using L2
## penalization on the difference of betas to 1 with tuning = 0.1
fitMLL2 <- brRasch(lsatCompressed, constraints = constrc, br = FALSE,
                   penalty = "L2discr", tuning = 0.1)


## Not run: 
    ## The IRFs for the L2 penalized fit vary between those of fitML to
    ## those of fitML0 as tuning grows. Notice the grouping of the
    ## abilities the closer one moves to fitML0
    for (lambda in c(0, 0.1, 1, 10, 100, 1000, 10000)) {
        IRF <- irf(update(fitMLL2, tuning = lambda))
        print(IRF + ggplot2::labs(title = bquote(lambda == .(lambda))))
    }

## End(Not run)

## Not run: 
    ## Now use fitML to get starting values for a reduced-bias fit of the
    ## original data under the same constraints
    ## the decompress method will extract the coeeficients
    startBR <- decompress(fitML)
    ## and also rebuild the dataset respecting the order of the abilities in startBR
    LSATdecompressed <- decompress(LSATCompressed)
    constr <- setConstraintsRasch(data = LSATdecompressed,
                                  dim = 1,
                                  which = c(1, 6),
                                  values = c(0, 1))

    ## Requires several slow iterations
    fitBR1 <- brRasch(LSATdecompressed, constraints = constr, br = TRUE, dim = 1,
                      start = startBR, trace = 10, fstol = 1e-06)


    ## Plot the IRFs
    irf(fitBR1)

## End(Not run)

## Not run: 
    ## Can also use own built-in starting value procedure
    fitBR2 <- brRasch(LSAT, constraints = constr, br = TRUE,
                      trace = 1)

## End(Not run)

## Not run: 
    ## Score test 2PL vs 1PL
    fitBR0 <- brRasch(LSATdecompressed, dim = 0, br = TRUE,
                      start = coef(fitBR2), trace = 10, fstol = 1e-06)

    constr_score <- setConstraintsRasch(data = LSATdecompressed,
                                        dim = 1,
                                        which = c(1, 6, 7, 8, 9, 10),
                                        values = c(0, 2, 2, 2, 2, 2),
                                        restricted = c(7, 8, 9, 10))
    fitBR0_restr <- brRasch(LSATdecompressed, constraints = constr_score, br = TRUE,
                            trace = 10, dim = 1, fstol = 1e-06)
    ## p-value for test that all betas are 1 is large
    wh <- names(coef(fitBR0_restr))[c(7, 8, 9, 10)]
    1 - pchisq(with(fitBR0_restr, drop(scores[wh] %*% vcov[wh, wh] %*% scores[wh])), 4)
    ## which is compatible with the comparable value that the discrimination parameters have
    coef(fitBR1, what = "discr")

## End(Not run)

## Not run: 

    ## Fit two dimensional model
    constr2 <- setConstraintsRasch(data = LSATdecompressed,
                                   dim = 2,
                                   which = c(6, 7, 8, 9, 16, 17),
                                   values = c(1, 1, 1, 1, -0.1, 0.1))
    fitBR2dim <- brRasch(LSATdecompressed, constraints = constr2, br = TRUE, trace = 10,
                         dim = 2, fsinitstepfactor = 1)
    adj <- 0.01
    lsatCompressed <- within.list(LSATCompressed, data <- adj + data*(1 - 2*adj))
    lsatDecompressed <- decompress(lsatCompressed)
    fitBR2dimAdj <- brRasch(lsatDecompressed, constraints = constr2, br = FALSE, trace = 10,
                            dim = 2, fsinitstepfactor = 5, fsridge = 1e-03, startmaxit = 100)
    ## Check this out - it does not converge

## End(Not run)

ikosmidis/brRasch documentation built on July 25, 2018, 10:28 a.m.