# Quadrature and Ability Priors :API: {py:mod}`irtlib.quadrature` :Sources: {cite:t}`Bock1982`; {cite:t}`Bock1981`; {cite:t}`Choi2009`; {cite:t}`vanderLinden1998`; {cite:t}`vanderLinden1996` ## 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. {mod}`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 {cite:p}`vanderLinden1998{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 {cite:p}`Bock1982{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: $$ A_q = \frac{w_q\,\pi(X_q)}{\sum_{h=1}^{Q} w_h\,\pi(X_h)}. $$ 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}}$ {cite:p}`Bock1982{p. 433, Equation 3}`, and its posterior mass at the node is $$ \frac{L_j(X_q)\,A_q}{\sum_{h=1}^{Q} L_j(X_h)\,A_h}. $$ 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 {cite:p}`Bock1982{p. 432}`; {cite:p}`Bock1982{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 $$ \tilde{P}_{ij} = \sum_{q=1}^{Q} P_i(X_q)\,g_j(X_q), $$ and the expected posterior variance of item $i$ averages the two variances over that prediction {cite:p}`vanderLinden1998{p. 206, Equations 13 and 15}`; {cite:p}`Choi2009{Equation 4}`: $$ \tilde{P}_{ij}\,\mathrm{Var}_j(\theta \mid u_{ij} = 1) + (1 - \tilde{P}_{ij})\,\mathrm{Var}_j(\theta \mid u_{ij} = 0). $$ 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 {cite:p}`vanderLinden1998{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)$ {cite:p}`vanderLinden1996{p. 12, Equation 14}`, and names the predicted probabilities as a variant {cite:p}`vanderLinden1996{p. 13}`. With the predicted probabilities, the expected posterior variance depends on the posterior alone. ## Implementation **The grid.** The equal weights of {meth}`~irtlib.quadrature.QuadratureGrid.uniform` cancel, which leaves the prior density at the nodes, normalized: the masses {cite:t}`Bock1981{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 {cite:p}`Bock1982{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 ({doc}`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 {cite:p}`Bock1982{p. 432}`, so {func}`~irtlib.quadrature.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 {class}`~irtlib.quadrature.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.** {func}`~irtlib.quadrature.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 {func}`~irtlib.quadrature.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 {cite:p}`Bock1982{p. 433}`; neither {func}`~irtlib.quadrature.posterior_variance` nor {func}`~irtlib.quadrature.expected_posterior_variance` does. :::{dropdown} Comparison with mirt and catR - The range $[-6, 6]$ is mirt 1.48's default `theta_lim` {cite:p}`Chalmers2026{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 ({doc}`ADR-0003 `). - catR 3.17's `EPV` weights the two updated variances by the probabilities at the ability estimate it is given, as van der Linden's report does {cite:p}`Magis2022{p. 17}`, so its values differ from those of {func}`~irtlib.quadrature.expected_posterior_variance`. ::: ## Parameters ```{list-table} :header-rows: 1 :widths: 26 14 34 26 * - Parameter - Default - Description - Default from * - `mean`, `sd` of {func}`~irtlib.quadrature.normal_log_prior` - `0.0`, `1.0` - The normal prior's mean and standard deviation. - abilities $N(0, 1)$, mirt's default ({doc}`ADR-0008 `) * - `low`, `high` of {func}`~irtlib.quadrature.uniform_log_prior` - `-6.0`, `6.0` - The interval of the uniform prior. - the extended ability range, mirt's `theta_lim` {cite:p}`Chalmers2026{p. 129}` * - `n_nodes` of {meth}`~irtlib.quadrature.QuadratureGrid.uniform` - `121` - The number of equally spaced nodes. - a spacing of 0.1, after {cite:t}`Bock1982{p. 433}` * - `low`, `high` of {meth}`~irtlib.quadrature.QuadratureGrid.uniform` - `-6.0`, `6.0` - The first and last node. - the extended ability range, mirt's `theta_lim` {cite:p}`Chalmers2026{p. 129}` ``` ## Guarantees 1. 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. 2. An examinee who answered no item gets the prior's masses as its posterior. 3. The posterior of a long response pattern does not underflow to zero at every node. 4. An item whose probability of a correct response is the same at every node leaves the expected posterior variance at the posterior variance. 5. Identical items get identical expected posterior variances, bit for bit, so the items tied for the smallest are found by equality. ## References ```{bibliography} :filter: docname in docnames ``` ## API Reference ```{eval-rst} .. automodule:: irtlib.quadrature :members: ```