Skip to main content

Simulate Data under a Generalized Partial Credit Model

Description

rgpcm simulates IRT data under a generalized partial credit model.

Usage

rgpcm(theta, a, b, nullcats = FALSE, return_setting = TRUE)

Arguments

theta numeric vector of person parameters. Can also be a list, then a list of length length(theta) is returned, containing multiple simulated data sets.
a list of numerics of item discrimination parameters.
b list of numeric vectors of item threshold parameters.
nullcats logical. Should null categories be allowed?
return_setting logical. Should a list containing slots of "a", "b", and "theta", as well as the simulated data matrix "data" be returned (default) or only the simulated data matrix?

Value

rgpcm returns either a list of the following components:

a list of numerics of item discrimination parameters used,
b list of numeric vectors of item threshold parameters used,
theta numeric vector of person parameters used,
data numeric matrix containing the simulated data,

or (if return_setting = FALSE) only the numeric matrix containing the simulated data.

See Also

rpcm, rrsm, rpl, rrm

Examples

library("psychotools")

set.seed(1)
## item responses under a GPCM (generalized partial credit model) from
## 6 persons with three different person parameters
## 8 items with different combinations of two or three threshold parameters
## and corresponding discrimination parameters
ppar <- rep(-1:1, each = 2)
tpar <- rep(list(-2:0, -1:1, 0:1, 0:2), each = 2)
dpar <- rep(list(1, 2), each = 4)
sim <- rgpcm(theta = ppar, a = dpar, b = tpar)

## simulated item response data along with setting parameters
sim
$a
$a[[1]]
[1] 1

$a[[2]]
[1] 1

$a[[3]]
[1] 1

$a[[4]]
[1] 1

$a[[5]]
[1] 2

$a[[6]]
[1] 2

$a[[7]]
[1] 2

$a[[8]]
[1] 2


$b
$b[[1]]
[1] -2 -1  0

$b[[2]]
[1] -2 -1  0

$b[[3]]
[1] -1  0  1

$b[[4]]
[1] -1  0  1

$b[[5]]
[1] 0 1

$b[[6]]
[1] 0 1

$b[[7]]
[1] 0 1 2

$b[[8]]
[1] 0 1 2


$theta
[1] -1 -1  0  0  1  1

$data
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    0    1    2    1    0    0    0    1
[2,]    1    0    1    0    0    0    1    0
[3,]    2    2    0    1    1    1    1    1
[4,]    3    3    3    2    0    1    1    0
[5,]    3    3    3    2    1    2    2    3
[6,]    3    3    2    3    2    1    3    2
## print and plot corresponding item response object
iresp <- itemresp(sim$data)
iresp
[1] {0,1,2,1,0,0,0,1} {1,0,1,0,0,0,1,0} {2,2,0,1,1,1,1,1} {3,3,3,2,0,1,1,0}
[5] {3,3,3,2,1,2,2,3} {3,3,2,3,2,1,3,2}
plot(iresp)