Quadrature and Ability Priors#
- API:
- Sources:
Bock and Mislevy [1982]; Bock and Aitkin [1981]; Choi and Swartz [2009]; van der Linden [1998]; van der Linden [1996]
Motivation#
Marginal maximum likelihood integrates over the abilities of a population, and the expected a
posteriori estimate integrates over one examinee’s posterior. Neither integral has a closed form, so
both become sums over the nodes of a grid of abilities. irtlib.quadrature holds that grid, the
ability priors it is weighted by, and each examinee’s posterior over it, shared by calibration and
ability estimation.
An adaptive test asks one more question of the posterior: how much would one more item narrow it? The expected posterior variance answers it for each item before the item is given, and the item that narrows the posterior most is a choice for the next item [van der Linden, 1998, p. 206].
Definition#
Calibration and ability estimation both replace the integral over ability by a sum over the nodes \(X_q\), \(q = 1, \dots, Q\), of a grid. Each node carries a mass \(A_q\), the probability of a discrete prior distribution at that node, and the masses sum to 1 [Bock and Mislevy, 1982, p. 433, Equation 6]. A grid holds the nodes and a weight \(w_q\) for each, and a prior is a log-density \(\log \pi\). A node’s mass is its weight times the prior density there, normalized:
Examinee \(j\)’s likelihood at a node, \(L_j(X_q)\), is the product over the items \(i\) it answered of \(P_i(X_q)^{u_{ij}} [1 - P_i(X_q)]^{1 - u_{ij}}\) [Bock and Mislevy, 1982, p. 433, Equation 3], and its posterior mass at the node is
The mean of the posterior over the nodes is the EAP estimate of the examinee’s ability, and its variance serves as the estimate’s error variance: the square of the posterior standard deviation [Bock and Mislevy, 1982, p. 432]; [Bock and Mislevy, 1982, p. 433, Equations 4 and 5].
Write \(g_j(X_q)\) for examinee \(j\)’s posterior mass at node \(X_q\), and \(u\) for a response to item \(i\) that the examinee has not given yet, 1 if correct and 0 if not. That response would multiply each mass by \(P_i(X_q)^{u}\,Q_i(X_q)^{1 - u}\), and the masses, normalized again, would be the examinee’s posterior after it, of variance \(\mathrm{Var}_j(\theta \mid u_{ij} = u)\). The posterior predicts a correct response with probability
and the expected posterior variance of item \(i\) averages the two variances over that prediction [van der Linden, 1998, p. 206, Equations 13 and 15]; [Choi and Swartz, 2009, Equation 4]:
Selecting the item with the smallest expected posterior variance minimizes the preposterior risk under a quadratic loss, a criterion that Owen mentioned as an alternative item selection rule [van der Linden, 1998, p. 203]. The research report that preceded van der Linden’s article weights the two variances by the probabilities at the current ability estimate instead, \(P_i(\hat{\theta}_j)\) and \(Q_i(\hat{\theta}_j)\) [van der Linden, 1996, p. 12, Equation 14], and names the predicted probabilities as a variant [van der Linden, 1996, p. 13]. With the predicted probabilities, the expected posterior variance depends on the posterior alone.
Implementation#
The grid. The equal weights of uniform() cancel, which
leaves the prior density at the nodes, normalized: the masses Bock and Aitkin [1981, p. 449] take for a
normal prior, and for any other. Those nodes are evenly spaced, as Bock and Mislevy’s are:
Gauss-Hermite quadrature, they note, has less advantage for the likelihoods of adaptive testing
[Bock and Mislevy, 1982, p. 433]. The default grid has 121 nodes on the extended ability range \([-6, 6]\),
a spacing of 0.1: about the spacing of the 80 points between \(\pm 4\) standard deviations that Bock
and Mislevy (p. 433) suggest to keep precision down to a posterior standard deviation of 0.2.
Calibration uses its own grid, 61 nodes on the same range
(ADR-0007).
The posterior. An examinee who answered no item has \(L_j = 1\) at every node, and its posterior
is the masses. The log-likelihoods accumulate as sums over the items
[Bock and Mislevy, 1982, p. 432], so posterior() takes each examinee’s
log-likelihood at the nodes, whatever the response function that gave it. It adds the log of each
node’s weight and prior density, and shifts each examinee’s row by its maximum before
exponentiating, so that the likelihood of a long response pattern does not underflow. A
GridPrior evaluates and checks a prior on a grid’s nodes once, for a
caller that computes many posteriors with the same grid and prior.
The expected posterior variance. expected_posterior_variance() takes the
posteriors and each item’s probability of a correct response at the nodes, whatever the response
function that gave them, and returns one value per examinee and item. It computes each updated
posterior’s variance on the same nodes, as posterior_variance() computes the
posterior’s. A response that the posterior predicts with probability 0, where the item’s probability
is 0 or 1 at every node with mass, adds nothing to the average.
Departures from the sources. Bock and Mislevy apply Sheppard’s correction to the posterior
variance [Bock and Mislevy, 1982, p. 433]; neither posterior_variance() nor
expected_posterior_variance() does.
Comparison with mirt and catR
The range \([-6, 6]\) is mirt 1.48’s default
theta_lim[Chalmers, 2026, p. 129].The EAP estimates that catR 3.17 records are checked to be the posterior mean and standard deviation written out, on the same nodes and weights, within a relative \(10^{-10}\), before irtlib is compared with them (ADR-0003).
catR 3.17’s
EPVweights the two updated variances by the probabilities at the ability estimate it is given, as van der Linden’s report does [Magis et al., 2022, p. 17], so its values differ from those ofexpected_posterior_variance().
Parameters#
Parameter |
Default |
Description |
Default from |
|---|---|---|---|
|
|
The normal prior’s mean and standard deviation. |
abilities \(N(0, 1)\), mirt’s default (ADR-0008) |
|
|
The interval of the uniform prior. |
the extended ability range, mirt’s |
|
|
The number of equally spaced nodes. |
a spacing of 0.1, after Bock and Mislevy [1982, p. 433] |
|
|
The first and last node. |
the extended ability range, mirt’s |
Guarantees#
The masses of a grid under a prior are non-negative and sum to 1; a node outside a uniform prior’s interval gets mass 0.
An examinee who answered no item gets the prior’s masses as its posterior.
The posterior of a long response pattern does not underflow to zero at every node.
An item whose probability of a correct response is the same at every node leaves the expected posterior variance at the posterior variance.
Identical items get identical expected posterior variances, bit for bit, so the items tied for the smallest are found by equality.
References#
R. Darrell Bock and Murray Aitkin. Marginal maximum likelihood estimation of item parameters: application of an EM algorithm. Psychometrika, 46(4):443–459, 1981. Not openly available; Baker (1987) describes the method. doi:10.1007/BF02293801.
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.
R. Philip Chalmers. mirt: Multidimensional Item Response Theory. 2026. R package version 1.48, reference manual dated 2026-10-06. Open access. URL: https://cran.r-project.org/package=mirt.
Seung W. Choi and Richard J. Swartz. Comparison of CAT item selection criteria for polytomous items. Applied Psychological Measurement, 33(6):419–440, 2009. Open copy: https://pmc.ncbi.nlm.nih.gov/articles/PMC2791416/ (author manuscript, without the journal's page numbers). doi:10.1177/0146621608327801.
David Magis, Gilles Raîche, and Juan Ramón Barrada. catR: Generation of IRT Response Patterns under Computerized Adaptive Testing. 2022. R package version 3.17, reference manual, published on CRAN 2022-06-24. Open access. URL: https://cran.r-project.org/package=catR.
Wim J. van der Linden. Bayesian item selection criteria for adaptive testing. Research Report 96-01, University of Twente, Faculty of Educational Science and Technology, Enschede, 1996. Open copy: https://files.eric.ed.gov/fulltext/ED424235.pdf.
Wim J. van der Linden. Bayesian item selection criteria for adaptive testing. Psychometrika, 63(2):201–216, 1998. Not openly available; Choi and Swartz (2009) describe the criterion with the same weights. doi:10.1007/BF02294775.
API Reference#
The quadrature grid, the ability priors, and each examinee’s posterior over the grid.
- class irtlib.quadrature.GridPrior(grid: QuadratureGrid, log_prior: LogPrior)[source]#
A prior over the nodes of a grid, evaluated and checked once, for posteriors computed many times on them.
It keeps copies of the grid’s nodes and of each node’s log weight plus log prior density, so changing the grid’s arrays afterwards does not change it.
posterior()returns whatposterior()returns for the same grid and prior, without evaluating the prior again.- Parameters:
- gridQuadratureGrid
The nodes and their weights.
- log_priorLogPrior
Vectorized log-density of the prior.
- Raises:
- ValueError
If the log-prior is NaN or +inf at a node, or -inf at every node.
Examples
>>> import numpy >>> prior = GridPrior(QuadratureGrid.uniform(3, -1.0, 1.0), uniform_log_prior(-1.0, 1.0)) >>> prior.posterior(numpy.log(numpy.array([[0.2, 0.5, 0.8]]))).round(4) array([[0.1333, 0.3333, 0.5333]])
- posterior(log_likelihood: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return each examinee’s posterior over the nodes, from its log-likelihood at them.
- Parameters:
- log_likelihoodnumpy.ndarray
Each examinee’s log-likelihood at each node, shape
(examinees, nodes); -inf where the likelihood is 0.
- Returns:
- numpy.ndarray
The posterior probabilities, shape
(examinees, nodes), each row summing to 1.
- Raises:
- ValueError
If
log_likelihoodis not of shape(examinees, nodes), if the log-likelihood is NaN or +inf at a node, or if an examinee’s posterior has no mass at any node.
- type irtlib.quadrature.LogPrior = Callable[[NDArray[floating[Any]]], NDArray[floating[Any]]]#
A log prior density: maps an array of abilities to their log-densities, elementwise, without writing to the array.
- class irtlib.quadrature.QuadratureGrid(nodes: NDArray[floating[Any]], weights: NDArray[floating[Any]])[source]#
The nodes abilities are integrated over, each with a weight.
A node’s mass is proportional to its weight times the prior density there, so the weights take part in the posterior itself; equal weights, as
uniform()builds, cancel in the normalization. Two grids are equal only if they are the same object, and a grid can be a set member or a dictionary key.- Parameters:
- nodesnumpy.ndarray
One-dimensional array of finite abilities.
- weightsnumpy.ndarray
One-dimensional array of finite, positive weights, one per node.
- Raises:
- ValueError
If the arrays are not one-dimensional, differ in length, have fewer than two entries, or hold nodes that are not finite or weights that are not finite and positive.
- classmethod uniform(n_nodes: int = 121, low: float = -6.0, high: float = 6.0) Self[source]#
Return a grid of equally spaced nodes from
lowtohigh, each weighing the spacing.- Parameters:
- n_nodesint, optional
Number of nodes, both bounds included. Default is 121, a spacing of 0.1 on the default bounds.
- lowfloat, optional
First node. Default is
irtlib.irt.THETA_MIN_EXTENDED.- highfloat, optional
Last node. Default is
irtlib.irt.THETA_MAX_EXTENDED.
- Returns:
- QuadratureGrid
The grid, with every weight equal to the spacing of the nodes.
- Raises:
- ValueError
If
n_nodes < 2orhigh <= low.
Examples
>>> grid = QuadratureGrid.uniform() >>> grid.nodes.size, float(grid.nodes[0]), float(grid.nodes[-1]), float(grid.weights[0]) (121, -6.0, 6.0, 0.1)
- irtlib.quadrature.expected_posterior_variance(post: NDArray[floating[Any]], nodes: NDArray[floating[Any]], probabilities: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the variance each examinee’s posterior is expected to have after one more response to each item.
For each examinee and item, the posterior is updated with a correct and with an incorrect response to the item, and the variances of the two updated posteriors are averaged, each weighted by the probability the examinee’s posterior predicts for its response. A response that the posterior predicts with probability 0 adds nothing. Identical columns of
probabilitiesgive identical values, bit for bit. The Quadrature and Ability Priors page gives the definition and its sources.- Parameters:
- postnumpy.ndarray
Posterior probabilities, shape
(examinees, nodes), asposterior()returns.- nodesnumpy.ndarray
The nodes the probabilities refer to, shape
(nodes,).- probabilitiesnumpy.ndarray
Each item’s probability of a correct response at each node, shape
(nodes, items), asirtlib.irt.icc()returns for the nodes.
- Returns:
- numpy.ndarray
The expected posterior variances, shape
(examinees, items).
- Raises:
- ValueError
If
nodesis not one-dimensional,postis not of shape(examinees, nodes)orprobabilitiesis not of shape(nodes, items).
Examples
>>> import numpy >>> post = numpy.array([[0.2, 0.8], [0.5, 0.5]]) >>> expected_posterior_variance(post, numpy.array([-1.0, 1.0]), numpy.array([[0.2], [0.8]])).round(4) array([[0.4706], [0.64 ]])
- irtlib.quadrature.normal_log_prior(mean: float = 0.0, sd: float = 1.0) LogPrior[source]#
Return the log-density of a normal prior with the given mean and standard deviation.
The prior pickles, equals any prior this function returns for the same arguments, and its repr is the call that builds it.
- Parameters:
- meanfloat, optional
Mean of the prior. Default is 0.
- sdfloat, optional
Standard deviation of the prior. Default is 1.
- Returns:
- LogPrior
A vectorized callable mapping abilities to their log-densities under the prior.
- Raises:
- ValueError
If
meanis not finite, orsdis not finite and positive.
Examples
>>> normal_log_prior(mean=0.5, sd=2.0) normal_log_prior(mean=0.5, sd=2.0)
- irtlib.quadrature.posterior(log_likelihood: NDArray[floating[Any]], grid: QuadratureGrid, log_prior: LogPrior) NDArray[floating[Any]][source]#
Return each examinee’s posterior over the nodes of a grid, from its log-likelihood at the nodes.
An examinee’s posterior mass at a node is proportional to the node’s weight times the prior density and the likelihood there. A row of zeros, the log-likelihood of an examinee who answered no item, gives the prior’s masses.
- Parameters:
- log_likelihoodnumpy.ndarray
Each examinee’s log-likelihood at each node, shape
(examinees, nodes); -inf where the likelihood is 0.- gridQuadratureGrid
The nodes and their weights.
- log_priorLogPrior
Vectorized log-density of the prior.
- Returns:
- numpy.ndarray
The posterior probabilities, shape
(examinees, nodes), each row summing to 1.
- Raises:
- ValueError
If
log_likelihoodis not of shape(examinees, nodes), if the log-prior or the log-likelihood is NaN or +inf at a node, or if an examinee’s posterior has no mass at any node.
Examples
>>> import numpy >>> grid = QuadratureGrid.uniform(3, -1.0, 1.0) >>> likelihood = numpy.array([[0.2, 0.5, 0.8], [1.0, 1.0, 1.0]]) >>> posterior(numpy.log(likelihood), grid, uniform_log_prior(-1.0, 1.0)).round(4) array([[0.1333, 0.3333, 0.5333], [0.3333, 0.3333, 0.3333]])
- irtlib.quadrature.posterior_mean(post: NDArray[floating[Any]], nodes: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the mean of each examinee’s posterior over the nodes.
- Parameters:
- postnumpy.ndarray
Posterior probabilities, shape
(examinees, nodes), asposterior()returns.- nodesnumpy.ndarray
The nodes the probabilities refer to.
- Returns:
- numpy.ndarray
The probability-weighted mean of the nodes, one per examinee.
Examples
>>> import numpy >>> posterior_mean(numpy.array([[0.25, 0.5, 0.25], [0.0, 0.5, 0.5]]), numpy.array([-1.0, 0.0, 1.0])) array([0. , 0.5])
- irtlib.quadrature.posterior_variance(post: NDArray[floating[Any]], nodes: NDArray[floating[Any]]) NDArray[floating[Any]][source]#
Return the variance of each examinee’s posterior over the nodes.
- Parameters:
- postnumpy.ndarray
Posterior probabilities, shape
(examinees, nodes), asposterior()returns.- nodesnumpy.ndarray
The nodes the probabilities refer to.
- Returns:
- numpy.ndarray
The probability-weighted mean of the squared distances between the nodes and the examinee’s
posterior_mean(), one per examinee.
Examples
>>> import numpy >>> posterior_variance(numpy.array([[0.25, 0.5, 0.25], [0.0, 0.5, 0.5]]), numpy.array([-1.0, 0.0, 1.0])) array([0.5 , 0.25])
- irtlib.quadrature.prior_masses(grid: QuadratureGrid, log_prior: LogPrior) NDArray[floating[Any]][source]#
Return the prior’s mass at each node of a grid: the node’s weight times the prior density there, normalized.
The masses are the posterior of an examinee who answered no item.
- Parameters:
- gridQuadratureGrid
The nodes and their weights.
- log_priorLogPrior
Vectorized log-density of the prior.
- Returns:
- numpy.ndarray
One mass per node, summing to 1.
- Raises:
- ValueError
If the log-prior is NaN or +inf at a node, or -inf at every node.
Examples
>>> prior_masses(QuadratureGrid.uniform(4, -1.0, 2.0), uniform_log_prior(-1.0, 2.0)) array([0.25, 0.25, 0.25, 0.25])
- irtlib.quadrature.uniform_log_prior(low: float = -6.0, high: float = 6.0) LogPrior[source]#
Return the log-density of a uniform prior on
[low, high].The log-density is minus the log of the width inside the bounds, the bounds included, and -inf outside them. The prior pickles, equals any prior this function returns for the same arguments, and its repr is the call that builds it.
- Parameters:
- lowfloat, optional
Lower bound of the prior’s support. Default is
irtlib.irt.THETA_MIN_EXTENDED.- highfloat, optional
Upper bound of the prior’s support. Default is
irtlib.irt.THETA_MAX_EXTENDED.
- Returns:
- LogPrior
A vectorized callable mapping abilities to their log-densities under the prior.
- Raises:
- ValueError
If either bound is not finite or
high <= low.
Examples
>>> uniform_log_prior() uniform_log_prior(low=-6.0, high=6.0)