Item Response Functions#
- API:
- Sources:
Magis [2013]; Magis and Raîche [2012]; Barton and Lord [1981]; Baker [1987]; Veerkamp and Berger [1994]; Barrada et al. [2006]; Orlando and Thissen [2000]; Thissen et al. [1995]; Mislevy [1986]
Motivation#
Every method in irtlib rests on the same few quantities of the logistic models: the probability of a
correct response, its derivatives, the information an item gives about the ability, the
likelihood of a set of responses, and the probability of each number correct. irtlib.irt computes them once, for every model from the 1PL
to the 4PL, and the calibrators, the ability estimators and item fit call it, as catsim does. A
package that builds on irtlib can call it too.
Definition#
Under the four-parameter logistic model, an examinee of ability \(\theta\) answers item \(i\) correctly with probability
[Magis, 2013, p. 306, Equation 1], and incorrectly with probability \(Q_i = 1 - P_i\). The 3PL fixes \(d_i = 1\), and the 2PL also \(c_i = 0\) [Magis and Raîche, 2012, p. 3]. The derivatives of \(P_i\) with respect to the ability are
the derivatives of Barton and Lord [1981, p. A2] written with \(F_i\) and their scaling constant \(D\) set to 1; the first is also Magis [2013, p. 306, Equations 4 and 5].
The scaling constant. Some sources write the logistic models with a constant multiplying the
discrimination, the scaling constant \(D\), so that \(F_i(\theta) = 1 / (1 + e^{-D a_i(\theta - b_i)})\):
\(D\) is “taken as 1 by some writers for convenience and as 1.7 by others”, so that the logistic
models approximate the normal ogive models [Mislevy, 1986, p. 183, Equation 18]. The functions
above are those with \(D = 1\). \(D\) and \(a_i\) enter them only as the product \(D a_i\), so an item whose
discrimination is \(a_i\) under a constant \(D\) is the item whose discrimination is \(D a_i\) here, with
the same \(b_i\), \(c_i\) and \(d_i\). An ItemBank converts the parameters of a model
with a constant as it is built, read from a file or written to one, through its D
argument (ADR-0015).
Information. The information item \(i\) gives about the ability is \(I_i = P_i'^2 / (P_i Q_i)\) [Magis and Raîche, 2012, p. 4, Equation 4], for the 4PL
[Magis, 2013, p. 307, Equation 6], and the test information \(I(\theta)\) is the sum of the information of its items [Magis and Raîche, 2012, p. 5, Equation 8].
Standard error and confidence interval. The maximum likelihood estimate of the ability is
asymptotically normal, with variance the inverse of the test information
[Warm, 1989, p. 445] and standard error \(1 / \sqrt{I(\theta)}\)
[Magis and Raîche, 2012, p. 4, Equation 3]. confidence_interval() is the interval this
normal approximation gives, \(\hat\theta \pm z \cdot SE\), with \(z\) the standard normal’s quantile at
\((1 + \text{confidence}) / 2\).
Reliability. The reliability of the test at \(\theta\) is \(I(\theta) / (I(\theta) + 1 / \sigma^2)\), with the abilities’ variance \(\sigma^2 = 1\), as they are \(N(0, 1)\) (ADR-0008). For abilities \(N(0, 1)\), Bock and Mislevy [1982, p. 437, Equation 7] define a related reliability of the EAP estimate, one minus its posterior variance.
The ability of maximum information. An item is most informative at
with \(u_i = -3/4 + (c_i + d_i - 2 c_i d_i)/2\) and \(v_i = (c_i + d_i - 1)/4\), where \(x^*_i\) is the probability of a correct response at \(\theta^*_i\) [Magis, 2013, pp. 308-309, Equations 13, 18 and 19]. With \(d_i = 1\) it is \(\theta^*_i = b_i + \log[(1 + \sqrt{1 + 8 c_i}) / 2] / a_i\) (p. 310, Equation 23), and with \(c_i + d_i = 1\) it is \(b_i\) (pp. 309-310). The 3PL’s \(\theta^*_i\) is also Equation 2 of Barrada et al. [2006, p. 157], with their constant \(D = 1.7\).
The integral of the information. Since \(P_i' = a_i (P_i - c_i)(d_i - P_i) / (d_i - c_i)\) [Magis, 2013, p. 306, Equation 5], changing the variable of integration from \(\theta\) to \(P_i\) in the information and splitting the result into partial fractions integrates an item’s information in closed form:
which extends the 3PL closed form of Veerkamp and Berger [1994, p. 22, Equation 25], to which it reduces when \(d_i = 1\). Under the 2PL the integral over the whole scale is \(a_i\) (p. 22, Equation 28).
The log-likelihood. The log-likelihood of examinee \(j\)’s responses \(u_{ij}\) is
over the items \(i\) the examinee answered [Magis and Raîche, 2012, p. 4, Equation 2]; [Barton and Lord, 1981, p. A1].
The probability of each number correct. The probability \(S_k(\theta)\) that an examinee of ability \(\theta\) answers \(k\) of \(M\) items correctly, \(k = 0, \dots, M\), sums the probabilities of the response patterns with \(k\) correct [Thissen et al., 1995, p. 42, Equation 15]. Lord and Wingersky’s recursion builds it one item at a time, without enumerating the patterns [Thissen et al., 1995, p. 42]. With \(S^{(i)}_k\) the probability of \(k\) correct on the first \(i\) items, it starts from \(S^{(1)}_0 = Q_1\) and \(S^{(1)}_1 = P_1\), and adding item \(i\) gives
where a term whose number correct is below 0 or above \(i - 1\) is 0 [Orlando and Thissen, 2000, p. 53, Equations 6-10]; [Thissen et al., 1995, p. 42, Equation 16]. \(S_k(\theta)\) is \(S^{(M)}_k(\theta)\) [Orlando and Thissen, 2000, p. 53, Equation 11].
A reporting scale. theta_to_scale() takes abilities to scores on a reporting
scale along the line through \((\theta_{min}, \text{scale}_{min})\) and
\((\theta_{max}, \text{scale}_{max})\), and scale_to_theta() takes them back.
Implementation#
Items and shapes. The functions take one item as a row [a, b, c, d] of shape (4,), or
several as a matrix of such rows, shape (n, 4), with \(a > 0\) and \(0 \leq c < d \leq 1\), and a
response matrix with one row per examinee and one column per item, holding 1, 0 or NaN where the
examinee did not answer the item. The models have no scaling constant
(ADR-0001).
The derivatives calibration uses. Calibration solves for each item’s parameters, and reports their standard errors, from the derivatives of \(P_i\) with respect to those parameters, which every method that estimates items shares. It estimates them in four parameters (ADR-0007): the slope \(\lambda = a\) and the intercept \(\zeta = -ab\), so that \(a(\theta - b) = \lambda\theta + \zeta\), and the logits \(\gamma\) of \(c\) and \(\delta\) of \(d\). Every array of these derivatives has the four on its last axis, in that order. By the chain rule,
from the derivatives in \(a\), \(b\) and \(c\) of Barton and Lord [1981, p. A3] and the derivative of the logistic function. A parameter at its bound, \(c = 0\) or \(d = 1\), has derivative 0.
For an item answered by \(N_q\) examinees at ability \(X_q\), \(r_q\) of them correctly, the log-likelihood is \(\sum_q [r_q \log P(X_q) + (N_q - r_q)\log Q(X_q)]\), the grouped form of Baker [1987, p. 112, Equation 3]. Its derivative in a parameter \(\chi\) is \(\sum_q [r_q - N_q P(X_q)]\,(\partial P / \partial\chi) / (PQ)\), the form of Barton and Lord [1981, p. A2] summed within each group; with \(d = 1\) the derivative in \(\gamma\) is the equation for the logit of \(c\) of Mislevy [1986, p. 184, Equation 22]. The expected information of one response is \((\partial P / \partial\chi)(\partial P / \partial\phi) / (PQ)\), Barton and Lord’s second derivative (p. A2) without its terms in \(u - P\), whose expected value is 0. For the 2PL in these parameters the observed information equals the expected one [Baker, 1987, p. 116].
Precision far from the difficulty. Nothing is computed by subtracting from 1. \(F\) and \(1 - F\) both come from the logit; \(P = c + (d - c)F\) and \(Q = (1 - d) + (d - c)(1 - F)\); \(\log P\) and \(\log Q\) combine \(\log c\) or \(\log(1 - d)\) with \(\log(d - c)\) and \(\log F\) or \(\log(1 - F)\). The ratios \((d - c)F / P\), \((d - c)(1 - F) / Q\), \(c / P\) and \((1 - d) / Q\) each lie between 0 and 1. The first is 0 / 0 only where \(c = 0\) and \(F\) has underflowed to 0, the second only where \(d = 1\) and \(1 - F\) has, and both take their limit there, 1. With \(P - c = (d - c)F\) and \(d - P = (d - c)(1 - F)\) [Magis, 2013, p. 306, Equation 3], the item information is \(a^2 F (1 - F)\) times the first two ratios.
Departures from the sources. Magis assumes \(0 < c_i < 0.5\) and \(0.5 < d_i < 1\)
[Magis, 2013, p. 306]; max_info_theta() takes his Equation 19 for every item
with \(d_i < 1\), and his Equation 23 for every item with \(d_i = 1\). The closed form of the integral of
the information with \(d_i < 1\) has no published source; the
sources wanted
list both.
Comparison with mirt and catR
The reliability is mirt 1.48’s (
R/SingleGroup-methods.R:1474), the curve thatplot(type = "rxx")draws; the parity tests check it against mirt’s recorded values within a relative \(10^{-10}\).The closed-form integral of the information agrees with mirt 1.48’s
areainfo, which integrates numerically (R/areainfo.R:49-66), within the same tolerance.The parameters calibration solves in are mirt’s (ADR-0007).
The probabilities and the information agree with catR 3.17’s on the recorded abilities and items within a relative \(10^{-10}\), after the recorded values are checked against Magis’s equations written out (ADR-0003).
Parameters#
The functions take abilities and items; these have defaults:
Parameter |
Default |
Description |
Default from |
|---|---|---|---|
|
|
The interval’s confidence level, strictly between 0 and 1. |
catsim’s, from which the function moved (ADR-0004) |
|
|
The reporting scale’s scores at the two abilities below. |
catsim’s (ADR-0004) |
|
|
The abilities that map to |
catsim’s (ADR-0004) |
Guarantees#
Probabilities, information and log-likelihoods are finite at any finite ability, however far from an item’s difficulty.
Items without information, or no items at all, give a test information of 0.
A guessing parameter of 0 or an upper asymptote of 1 has derivative 0 in calibration’s parameters.
References#
Frank B. Baker. Methodology review: item parameter estimation under the one-, two-, and three-parameter logistic models. Applied Psychological Measurement, 11(2):111–141, 1987. Open copy: https://hdl.handle.net/11299/103398. doi:10.1177/014662168701100201.
Juan Ramón Barrada, Paloma Mazuela, and Julio Olea. Maximum information stratification method for controlling item exposure in computerized adaptive testing. Psicothema, 18(1):156–159, 2006. Open access. URL: https://www.psicothema.com/pdf/3191.pdf.
Mark A. Barton and Frederic M. Lord. An upper asymptote for the three-parameter logistic item-response model. Research Report RR-81-20, Educational Testing Service, Princeton, NJ, 1981. Open copy: https://files.eric.ed.gov/fulltext/ED207996.pdf. doi:10.1002/j.2333-8504.1981.tb01255.x.
R. Darrell Bock and Robert J. Mislevy. Adaptive EAP estimation of ability in a microcomputer environment. Applied Psychological Measurement, 6(4):431–444, 1982. Open copy: http://purl.umn.edu/93227. doi:10.1177/014662168200600405.
David Magis. A note on the item information function of the four-parameter logistic model. Applied Psychological Measurement, 37(4):304–315, 2013. Not openly available; Magis and Raîche (2012) describe the model and its information function. doi:10.1177/0146621613475471.
David Magis and Gilles Raîche. Random generation of response patterns under computerized adaptive testing with the R package catR. Journal of Statistical Software, 48(8):1–31, 2012. Open access. doi:10.18637/jss.v048.i08.
Robert J. Mislevy. Bayes modal estimation in item response models. Psychometrika, 51(2):177–195, 1986. Not openly available; Harwell and Baker (1991) describe the method. doi:10.1007/BF02293979.
Maria Orlando and David Thissen. Likelihood-based item-fit indices for dichotomous item response theory models. Applied Psychological Measurement, 24(1):50–64, 2000. Not openly available; Kang and Chen (2007) describe the method. doi:10.1177/01466216000241003.
David Thissen, Mary Pommerich, Kathleen Billeaud, and Valerie S. L. Williams. Item response theory for scores on tests including polytomous items with ordered responses. Applied Psychological Measurement, 19(1):39–49, 1995. Open copy: https://hdl.handle.net/11299/117418. doi:10.1177/014662169501900105.
Wim J. J. Veerkamp and Martijn P. F. Berger. Some new item selection criteria for adaptive testing. Research Report 94-6, University of Twente, 1994. Open access. URL: https://ris.utwente.nl/ws/files/5155670/RR_94-6.pdf.
Thomas A. Warm. Weighted likelihood estimation of ability in item response theory. Psychometrika, 54(3):427–450, 1989. Not openly available; Warm's (1985) dissertation, https://hdl.handle.net/11244/5356, derives the same results. doi:10.1007/BF02294627.
API Reference#
The item response functions of the 1PL to 4PL models, and the quantities derived from them.
The functions take one item as a row [a, b, c, d] of shape (4,), or several as a matrix of such rows, shape
(n, 4), with a > 0 and 0 <= c < d <= 1, and a response matrix with one row per examinee and one column per
item, holding 1, 0 or NaN where the examinee did not answer the item.
- irtlib.irt.THETA_MAX_EXTENDED = 6.0#
The upper end of the extended ability range, which the default quadrature grid spans.
- irtlib.irt.THETA_MAX_TYPICAL = 4.0#
The upper end of the typical ability range, the default
theta_maxoftheta_to_scale().
- irtlib.irt.THETA_MIN_EXTENDED = -6.0#
The lower end of the extended ability range, which the default quadrature grid spans.
- irtlib.irt.THETA_MIN_TYPICAL = -4.0#
The lower end of the typical ability range, the default
theta_minoftheta_to_scale().
- irtlib.irt.confidence_interval(theta: float, items: NDArray[floating[Any]], confidence: float = 0.95) tuple[float, float][source]#
Return the confidence interval of an ability estimate, centred on it, from its standard error
see().- Parameters:
- thetafloat
The estimated ability.
- itemsnumpy.ndarray
The administered items, a matrix of shape
(n, 4).- confidencefloat, optional
The confidence level, strictly between 0 and 1. Default is 0.95.
- Returns:
- tuple[float, float]
The lower and the upper bound of the interval, infinite when the items give no information at
theta.
- Raises:
- ValueError
If
confidenceis not strictly between 0 and 1.
Examples
>>> import numpy >>> lower, upper = confidence_interval(0.5, numpy.array([[2.0, 0.5, 0.0, 1.0]] * 4)) >>> round(lower, 4), round(upper, 4) (-0.48, 1.48)
- irtlib.irt.icc(theta: float | NDArray[floating[Any]], items: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the probability of a correct response to each item, its item characteristic curve.
The probability rises with
thetafrom the guessing parametercto the upper asymptoted, and equals(c + d) / 2at the difficultyb.- Parameters:
- thetafloat or numpy.ndarray
An ability, or an array of abilities.
- itemsnumpy.ndarray
One item
[a, b, c, d], shape(4,), or a matrix of items, shape(n, 4).
- Returns:
- numpy.ndarray or numpy.float64
Every ability against every item, of shape
numpy.shape(theta) + items.shape[:-1]: a floatthetagives(n,)fornitems andkabilities give(k, n). A floatthetawith a single item of shape(4,)gives a NumPy scalar, anumpy.float64.
Examples
>>> import numpy >>> items = numpy.array([[1.0, 0.0, 0.0, 1.0], [1.5, 1.0, 0.2, 1.0]]) >>> icc(0.0, items).round(4) array([0.5 , 0.3459]) >>> icc(numpy.array([-1.0, 0.0, 1.0]), items).shape (3, 2)
- irtlib.irt.icc_derivatives(theta: float | NDArray[floating[Any]], items: NDArray[floating[Any]]) tuple[NDArray[floating[Any]], NDArray[floating[Any]]][source]#
Return the first and second derivatives of each item’s characteristic curve with respect to the ability.
Both are finite at any finite ability, and tend to 0 far from the difficulty.
- Parameters:
- thetafloat or numpy.ndarray
An ability, or an array of abilities.
- itemsnumpy.ndarray
One item
[a, b, c, d], shape(4,), or a matrix of items, shape(n, 4).
- Returns:
- tuple[numpy.ndarray, numpy.ndarray]
The first and the second derivative of
icc(), every ability against every item, each of shapenumpy.shape(theta) + items.shape[:-1].
Examples
>>> import numpy >>> first, second = icc_derivatives(0.0, numpy.array([[2.0, 0.0, 0.0, 1.0], [1.0, 1.0, 0.2, 0.9]])) >>> first.round(4), second.round(4) (array([0.5 , 0.1376]), array([0. , 0.0636]))
- irtlib.irt.info_integral(lower: float, upper: float, items: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the integral of each item’s
information()between two abilities.- Parameters:
- lowerfloat
Lower integration bound, possibly
-inf.- upperfloat
Upper integration bound, possibly
inf.- itemsnumpy.ndarray
One item
[a, b, c, d], shape(4,), or a matrix of items, shape(n, 4).
- Returns:
- numpy.ndarray
The integrals over
[lower, upper], of shapeitems.shape[:-1]; negated whenloweris aboveupper.
Examples
>>> import numpy >>> info_integral(-numpy.inf, numpy.inf, numpy.array([[0.7, -1.0, 0.0, 1.0], [1.3, 0.0, 0.0, 1.0]])) array([0.7, 1.3])
- irtlib.irt.information(theta: float | NDArray[floating[Any]], items: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the Fisher information each item gives about the ability.
An item is most informative near its difficulty, at
max_info_theta(). Far from the difficulty the information tends to 0 and stays finite.- Parameters:
- thetafloat or numpy.ndarray
An ability, or an array of abilities.
- itemsnumpy.ndarray
One item
[a, b, c, d], shape(4,), or a matrix of items, shape(n, 4).
- Returns:
- numpy.ndarray
Every ability against every item, of shape
numpy.shape(theta) + items.shape[:-1]: a floatthetagives(n,)fornitems andkabilities give(k, n).
Examples
>>> import numpy >>> information(0.0, numpy.array([[1.0, 0.0, 0.0, 1.0], [2.0, 0.0, 0.0, 1.0]])) array([0.25, 1. ])
- irtlib.irt.log_likelihood(theta: float | NDArray[floating[Any]], responses: ArrayLike, items: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the log-likelihood of each examinee’s responses at each ability.
Each examinee’s log-likelihood sums the log-probabilities of
log_response_probabilities()over the items the examinee answered, and an examinee who answered no item has log-likelihood 0.log_likelihood_function()computes the same values for many abilities, one call at a time.- Parameters:
- thetafloat or numpy.ndarray
An ability, or an array of abilities, each with a finite logit
a (theta - b)for every item.- responsesarray_like
The response matrix, one row per examinee and one column per item: 1 or True for a correct response, 0 or False for an incorrect one, and NaN for a missing one.
- itemsnumpy.ndarray
The items, a matrix of shape
(n, 4), one row per column ofresponses.
- Returns:
- numpy.ndarray
Every examinee at every ability, of shape
(n_examinees,) + numpy.shape(theta).
- Raises:
- TypeError
If the responses are neither Booleans, integers nor floats.
- ValueError
If
itemsis not an(n, 4)matrix of finite numbers,responsesis not a matrix with one column per item, or a response is not 0, 1 or NaN.
Examples
>>> import numpy >>> items = numpy.array([[1.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 1.0]]) >>> log_likelihood(0.0, numpy.array([[1.0, 0.0], [1.0, numpy.nan]]), items).round(4) array([-1.3863, -0.6931])
- irtlib.irt.log_likelihood_function(responses: ArrayLike, items: NDArray[floating[Any]]) Callable[[float | NDArray[floating[Any]]], NDArray[floating[Any]]][source]#
Return the log-likelihood of each examinee’s responses as a function of the ability.
The returned function gives, for any
theta, the value oflog_likelihood(). The responses and items are checked here, once, and the terms that do not depend on the ability are computed here too. Changingresponsesoritemsafterwards does not change the function.- Parameters:
- responsesarray_like
The response matrix, one row per examinee and one column per item: 1 or True for a correct response, 0 or False for an incorrect one, and NaN for a missing one.
- itemsnumpy.ndarray
The items, a matrix of shape
(n, 4), one row per column ofresponses.
- Returns:
- Callable[[float | numpy.ndarray], numpy.ndarray]
The log-likelihood of every examinee at every ability
thetawhose logitsa (theta - b)are finite, of shape(n_examinees,) + numpy.shape(theta).
- Raises:
- TypeError
If the responses are neither Booleans, integers nor floats.
- ValueError
If
itemsis not an(n, 4)matrix of finite numbers,responsesis not a matrix with one column per item, or a response is not 0, 1 or NaN.
Examples
>>> import numpy >>> items = numpy.array([[1.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 1.0]]) >>> log_lik = log_likelihood_function(numpy.array([[True, False]]), items) >>> log_lik(0.0).round(4), log_lik(numpy.array([0.0, 1.0])).round(4) (array([-1.3863]), array([[-1.3863, -1.6265]]))
- irtlib.irt.log_likelihood_gradient(theta: NDArray[floating[Any]], items: NDArray[floating[Any]], correct: NDArray[floating[Any]], total: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the gradient of each item’s log-likelihood from response counts at given abilities.
- Parameters:
- thetanumpy.ndarray
The abilities, shape
(k,), such as the nodes of a quadrature grid.- itemsnumpy.ndarray
A matrix of items
[a, b, c, d], shape(n, 4), with \(0 \leq c < d \leq 1\).- correctnumpy.ndarray
The number of correct responses to each item at each ability, shape
(k, n). Counts need not be integers, such as the expected counts of an E-step.- totalnumpy.ndarray
The number of responses to each item at each ability, shape
(k, n).
- Returns:
- numpy.ndarray
The gradient of each item’s log-likelihood, shape
(n, 4), with respect to the slope, the intercept, the logit ofcand the logit ofd.
Examples
>>> import numpy >>> items = numpy.array([[1.0, 0.0, 0.0, 1.0]]) >>> log_likelihood_gradient(numpy.array([0.0]), items, numpy.array([[3.0]]), numpy.array([[4.0]])) array([[0., 1., 0., 0.]])
- irtlib.irt.log_response_probabilities(theta: float | NDArray[floating[Any]], items: NDArray[floating[Any]]) tuple[NDArray[floating[Any]], NDArray[floating[Any]]][source]#
Return the log-probabilities of a correct and of an incorrect response to each item.
They stay finite at any finite distance from the difficulty. Far below the difficulty the first tends to
log(c), far above it the second tolog(1 - d), and without guessing or slipping they keep falling linearly intheta.- Parameters:
- thetafloat or numpy.ndarray
An ability, or an array of abilities.
- itemsnumpy.ndarray
One item
[a, b, c, d], shape(4,), or a matrix of items, shape(n, 4).
- Returns:
- tuple[numpy.ndarray, numpy.ndarray]
The logarithms of
icc()and of its complement, every ability against every item, each of shapenumpy.shape(theta) + items.shape[:-1].
Examples
>>> import numpy >>> log_p, log_q = log_response_probabilities(0.0, numpy.array([[1.0, 0.0, 0.2, 1.0]])) >>> numpy.exp(log_p).round(4), numpy.exp(log_q).round(4) (array([0.6]), array([0.4]))
- irtlib.irt.max_info_theta(items: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the ability at which each item gives the most information.
- Parameters:
- itemsnumpy.ndarray
One item
[a, b, c, d], shape(4,), or a matrix of items, shape(n, 4).
- Returns:
- numpy.ndarray
A new array of shape
items.shape[:-1], one ability per item.
Examples
>>> import numpy >>> max_info_theta(numpy.array([[1.0, 0.5, 0.0, 1.0], [1.0, 0.0, 0.2, 1.0]])).round(4) array([0.5 , 0.2671])
- irtlib.irt.number_correct_probabilities(theta: float | NDArray[floating[Any]], items: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the probability of each number correct on a set of items, from 0 to all of them, at each ability.
The probabilities at an ability sum to 1.
- Parameters:
- thetafloat or numpy.ndarray
An ability, or an array of abilities.
- itemsnumpy.ndarray
The items, a matrix of shape
(n, 4). No items, shape(0, 4), give a number correct of 0 with probability 1.
- Returns:
- numpy.ndarray
Every ability against every number correct from 0 to
n, of shapenumpy.shape(theta) + (n + 1,).
- Raises:
- ValueError
If
itemsis not an(n, 4)matrix of finite numbers.
Examples
>>> import numpy >>> items = numpy.array([[1.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 1.0]]) >>> number_correct_probabilities(0.0, items).round(4) array([0.25, 0.5 , 0.25]) >>> number_correct_probabilities(numpy.array([-1.0, 0.0, 1.0]), items).shape (3, 3)
- irtlib.irt.parameter_information(theta: NDArray[floating[Any]], items: NDArray[floating[Any]], total: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return each item’s expected information matrix from the number of responses at given abilities.
- Parameters:
- thetanumpy.ndarray
The abilities, shape
(k,), such as the nodes of a quadrature grid.- itemsnumpy.ndarray
A matrix of items
[a, b, c, d], shape(n, 4), with \(0 \leq c < d \leq 1\).- totalnumpy.ndarray
The number of responses to each item at each ability, shape
(k, n). Counts need not be integers.
- Returns:
- numpy.ndarray
One symmetric matrix per item, shape
(n, 4, 4), over the slope, the intercept, the logit ofcand the logit ofd. A parameter at its bound,c = 0ord = 1, has a zero row and column.
Examples
>>> import numpy >>> items = numpy.array([[1.0, 0.0, 0.0, 1.0]]) >>> parameter_information(numpy.array([0.0]), items, numpy.array([[4.0]]))[0] array([[0., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]])
- irtlib.irt.probability_gradient(theta: float | NDArray[floating[Any]], items: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the derivatives of the probability of a correct response in each item’s parameters.
- Parameters:
- thetafloat or numpy.ndarray
An ability, or an array of abilities.
- itemsnumpy.ndarray
One item
[a, b, c, d], shape(4,), or a matrix of items, shape(n, 4), with \(0 \leq c < d \leq 1\).
- Returns:
- numpy.ndarray
Every ability against every item, of shape
numpy.shape(theta) + items.shape[:-1] + (4,): the derivatives with respect to the slope, the intercept, the logit ofcand the logit ofd.
Examples
>>> import numpy >>> probability_gradient(0.0, numpy.array([1.0, 0.0, 0.0, 1.0])) array([0. , 0.25, 0. , 0. ])
- irtlib.irt.reliability(theta: float, items: NDArray[floating[Any]]) float[source]#
Return the reliability of the test at
theta, from itstotal_information(), for abilities N(0, 1).Values close to 1 mean a precise test.
- Parameters:
- thetafloat
An ability.
- itemsnumpy.ndarray
The administered items, a matrix of shape
(n, 4).
- Returns:
- float
The reliability, between 0 and 1; 0 when the items give no information at
theta.
Examples
>>> import numpy >>> reliability(0.0, numpy.array([[2.0, 0.0, 0.0, 1.0]] * 4)) 0.8
- irtlib.irt.scale_to_theta(score: float | NDArray[floating[Any]], scale_min: float = 0, scale_max: float = 100, theta_min: float = -4.0, theta_max: float = 4.0) float | NDArray[floating[Any]][source]#
Convert scores on a reporting scale back to abilities, the inverse of
theta_to_scale().With the same four bounds, a score converted to an ability and back is the same score.
- Parameters:
- scorefloat or numpy.ndarray
A score, or an array of scores.
- scale_minfloat, optional
Score of
theta_min. Default is 0.- scale_maxfloat, optional
Score of
theta_max. Default is 100.- theta_minfloat, optional
Ability mapped to
scale_min. Default isTHETA_MIN_TYPICAL, -4.- theta_maxfloat, optional
Ability mapped to
scale_max. Default isTHETA_MAX_TYPICAL, 4.
- Returns:
- float or numpy.ndarray
The abilities, a float for a float
scoreand an array of its shape otherwise.
- Raises:
- ValueError
If
theta_maxis not greater thantheta_min, orscale_maxis not greater thanscale_min.
Examples
>>> scale_to_theta(75.0) 2.0 >>> scale_to_theta(500.0, scale_min=200, scale_max=800) 0.0
- irtlib.irt.see(theta: float, items: NDArray[floating[Any]]) float[source]#
Return the standard error of estimation at
theta, the square root of thevar().It is in the units of the ability scale.
- Parameters:
- thetafloat
An ability.
- itemsnumpy.ndarray
The administered items, a matrix of shape
(n, 4).
- Returns:
- float
The standard error, infinite when the items give no information at
theta.
Examples
>>> import numpy >>> see(0.0, numpy.array([[1.0, 0.0, 0.0, 1.0]])) 2.0
- irtlib.irt.theta_to_scale(theta: float | NDArray[floating[Any]], scale_min: float = 0, scale_max: float = 100, theta_min: float = -4.0, theta_max: float = 4.0) float | NDArray[floating[Any]][source]#
Convert abilities to scores on a reporting scale, such as 0 to 100 or 200 to 800.
theta_minbecomesscale_minandtheta_maxbecomesscale_max, and abilities between or beyond them follow the same line.scale_to_theta()is its inverse.- Parameters:
- thetafloat or numpy.ndarray
An ability, or an array of abilities.
- scale_minfloat, optional
Score of
theta_min. Default is 0.- scale_maxfloat, optional
Score of
theta_max. Default is 100.- theta_minfloat, optional
Ability mapped to
scale_min. Default isTHETA_MIN_TYPICAL, -4.- theta_maxfloat, optional
Ability mapped to
scale_max. Default isTHETA_MAX_TYPICAL, 4.
- Returns:
- float or numpy.ndarray
The scores, a float for a float
thetaand an array of its shape otherwise.
- Raises:
- ValueError
If
theta_maxis not greater thantheta_min, orscale_maxis not greater thanscale_min.
Examples
>>> theta_to_scale(2.0) 75.0 >>> theta_to_scale(0.0, scale_min=200, scale_max=800) 500.0
- irtlib.irt.total_information(theta: float, items: NDArray[floating[Any]]) float[source]#
- irtlib.irt.total_information(theta: NDArray[floating[Any]], items: NDArray[floating[Any]]) NDArray[floating[Any]]
Return the test information of a set of items, the sum of their
information().Items without information, or no items at all, give 0.
- Parameters:
- thetafloat or numpy.ndarray
An ability, or an array of abilities.
- itemsnumpy.ndarray
One item
[a, b, c, d], shape(4,), or a matrix of items, shape(n, 4).
- Returns:
- float or numpy.ndarray
One value per ability: a float for a float
theta, otherwise an array of the shape oftheta.
Examples
>>> import numpy >>> total_information(0.0, numpy.array([[1.0, 0.0, 0.0, 1.0], [2.0, 0.0, 0.0, 1.0]])) 1.25
- irtlib.irt.var(theta: float, items: NDArray[floating[Any]]) float[source]#
Return the variance of the ability estimate at
theta, the inverse of thetotal_information().- Parameters:
- thetafloat
An ability.
- itemsnumpy.ndarray
The administered items, a matrix of shape
(n, 4).
- Returns:
- float
The variance, infinite when the items give no information at
theta.
Examples
>>> import numpy >>> var(0.0, numpy.array([[1.0, 0.0, 0.0, 1.0], [2.0, 0.0, 0.0, 1.0]])) 0.8