Drawing Responses – irtlib.drawing#

Drawing responses from the model, for simulation and parameter-recovery studies.

draw_responses() draws each response on its own: examinee \(j\) answers item \(i\) correctly when a number drawn uniformly from \([0, 1)\) falls below \(P_i(\theta_j)\), the probability of a correct response that irtlib.irt.icc() gives. Examinee \(j\)’s row takes the generator’s next n_items numbers after those of the examinees before it.

irtlib.drawing.draw_responses(theta: ArrayLike, items: NDArray[floating[Any]], rng: int | Generator | None = None) → NDArray[floating[Any]][source]#

Draw the responses of examinees of the given abilities to the given items, a response matrix.

Each response is correct with the probability irtlib.irt.icc() gives, independently of the others. The numbers are drawn row by row, so drawing one examinee at a time from one generator gives the same rows.

Parameters:
thetaarray_like

One ability per examinee, a one-dimensional array of finite numbers.

itemsnumpy.ndarray

A matrix of items, one row [a, b, c, d] per item, shape (n_items, 4). Only its shape and the finiteness of its parameters are checked; irtlib.ItemBank checks their ranges too.

rngint, numpy.random.Generator or None, optional

Where the responses are drawn from. None, the default, draws fresh randomness, so every call gives other responses. An int seeds a new generator, so the same seed gives the same responses. A generator is drawn from as is, and the call advances it.

Returns:
numpy.ndarray

A float matrix of shape (len(theta), n_items), one row per examinee and one column per item, holding 1.0 for a correct response and 0.0 for an incorrect one.

Raises:
TypeError

If theta or items holds values that are not real numbers.

ValueError

If theta is not one-dimensional or holds a value that is not finite, or items is not a matrix of four columns of finite numbers.

Examples

>>> import numpy
>>> items = numpy.array([[1.0, 0.0, 0.0, 1.0], [1.5, 1.0, 0.2, 1.0], [0.8, -1.0, 0.1, 0.95]])
>>> draw_responses(numpy.array([-1.0, 0.0, 2.5]), items, rng=3)
array([[1., 1., 0.],
       [0., 1., 1.],
       [1., 1., 1.]])