Markov Chain Monte Carlo#

API:

irtlib.mcmc.MCMCCalibrator; irtlib.mcmc.MCMCCalibration; irtlib.mcmc.Proposals; irtlib.mcmc.potential_scale_reduction()

Sources:

Patz and Junker [1999]; Patz and Junker [1999]; Gelman and Rubin [1992]; Brooks and Gelman [1998]; Kim and Bolt [2007]

Motivation#

Markov chain Monte Carlo (MCMC) draws the abilities and the item parameters from their joint posterior given the responses, treating “item and subject parameters at the same time” [Patz and Junker, 1999, p. 146]. Rather than an estimate and a standard error at a mode, it gives the whole posterior of each item, from which the posterior mean serves as the estimate and the posterior standard deviation as its standard error [Kim and Bolt, 2007, pp. 40, 46]. The draws of the items alone, with the abilities left aside, integrate the abilities out, and have the asymptotics of marginal maximum likelihood [Patz and Junker, 1999, pp. 151-152].

Its estimates agree closely with BILOG’s marginal maximum likelihood estimates [Patz and Junker, 1999, p. 163, Table 2], under the same priors in Kim and Bolt [2007, p. 46], at a far higher cost, so its value is the posterior itself: for highly discriminating items of the normal-ogive model, the posterior standard deviations were 20% to 60% larger than the standard errors of the EM algorithm, a sign that the normal approximation at the mode “may be a poor approximation” [Albert, 1992, p. 262]. irtlib calibrates the 1PL to the 3PL this way, and keeps the item draws but not the abilities’ (ADR-0012); Marginal Maximum Likelihood is the faster route to the estimates alone.

Definition#

The posterior of the abilities \(\theta\) and the item parameters \(\beta\), \(\beta_i\) those of item \(i\), given the responses \(u\) is proportional to the likelihood times the priors, which are independent across examinees and items [Patz and Junker, 1999, p. 156]:

\[p(\theta, \beta \mid u) \propto p(u \mid \theta, \beta) \prod_j \pi(\theta_j) \prod_i p(\beta_i),\]

with \(\pi\) the prior density of ability, here the standard normal. Each iteration \(t\) of a chain draws every ability and then every item from its distribution given the rest, by a Metropolis-Hastings step where that distribution has no standard form: from the current value a step proposes a new one, which the chain accepts with probability \(\min(1, R)\) and otherwise keeps the current value [Patz and Junker, 1999, pp. 160-161]. For examinee \(j\), a normal step gives \(\theta_j^*\) and, with \(L_j\) the likelihood of the examinee’s responses,

\[R_\theta = \frac{L_j(\theta_j^*) \, \pi(\theta_j^*)}{L_j(\theta_j^{t-1}) \, \pi(\theta_j^{t-1})}\]

[Patz and Junker, 1999, p. 160]. For item \(i\), a proposal density \(q(\beta, \beta^*)\) of drawing \(\beta^*\) from \(\beta\) gives \(\beta_i^*\), and, with \(u_i\) the responses to item \(i\), \(u_{ij}\) over the examinees \(j\),

\[R_\beta = \frac{p(u_i \mid \theta^t, \beta_i^*) \, p(\beta_i^*) \, q(\beta_i^*, \beta_i^{t-1})} {p(u_i \mid \theta^t, \beta_i^{t-1}) \, p(\beta_i^{t-1}) \, q(\beta_i^{t-1}, \beta_i^*)}\]

[Patz and Junker, 1999, p. 156, Equation 8]. The proposal densities cancel when the step is symmetric. The intercept takes a normal step, and the slope \(a_i\) a lognormal one, a normal step of \(\log a_i\) [Patz and Junker, 1999, p. 349, Equation 12], whose densities leave the factor \(a_i^* / a_i^{t-1}\) in \(R_\beta\).

Several chains run from dispersed starting values [Patz and Junker, 1999, p. 159]. For each parameter, let \(m\) chains keep \(n\) draws each, chain \(l\) with mean \(\bar x_l\) and variance \(s_l^2\), and \(\bar x\) the mean of all the draws. The variance between the chains’ means and the mean variance within them are

\[\frac{B}{n} = \frac{1}{m - 1} \sum_{l=1}^m (\bar x_l - \bar x)^2, \qquad W = \frac{1}{m} \sum_{l=1}^m s_l^2\]

[Gelman and Rubin, 1992, p. 460]. The pooled estimate of the posterior variance is \(\hat\sigma^2 = \frac{n - 1}{n} W + \frac{1}{n} B\) (p. 461, Equation 3), and the draws are approximated by a Student’s \(t\) of scale \(\sqrt{\hat V}\), \(\hat V = \hat\sigma^2 + B/(mn)\), with \(df = 2 \hat V^2 / \widehat{\operatorname{var}}(\hat V)\) degrees of freedom, where

\[\widehat{\operatorname{var}}(\hat V) = \left(\frac{n - 1}{n}\right)^2 \frac{1}{m} \widehat{\operatorname{var}}(s_l^2) + \left(\frac{m + 1}{mn}\right)^2 \frac{2}{m - 1} B^2 + 2 \frac{(m + 1)(n - 1)}{mn^2} \cdot \frac{n}{m} \left[\widehat{\operatorname{cov}}(s_l^2, \bar x_l^2) - 2 \bar x \, \widehat{\operatorname{cov}}(s_l^2, \bar x_l)\right]\]

(p. 461, Equation 4). The potential scale reduction, the factor by which the spread of the draws might shrink if the chains ran on, is

\[\sqrt{\hat R} = \sqrt{\frac{\hat V}{W} \cdot \frac{df + 3}{df + 1}},\]

with Brooks and Gelman’s correction for the degrees of freedom [Brooks and Gelman, 1998, p. 438]. It declines to 1 as \(n\) grows [Gelman and Rubin, 1992, p. 461], and the correction is minor near convergence, “because at convergence \(d\) tends to be large” [Brooks and Gelman, 1998, p. 438]. Gelman and Rubin multiply by \(df / (df - 2)\) instead (p. 461), a factor that Brooks and Gelman call incorrect: it “can be infinite or even negative in the cases where convergence is so slow that \(d < 2\)” (pp. 437-438). Brooks and Gelman print the degrees of freedom as \(2\hat V / \widehat{\operatorname{var}}(\hat V)\) (p. 437), which, unlike a number of degrees of freedom, changes with the scale of the draws; irtlib keeps Gelman and Rubin’s \(2\hat V^2 / \widehat{\operatorname{var}}(\hat V)\), which does not.

Implementation#

The parameters and the priors. The steps move each item’s slope \(a_i\), intercept \(\zeta_i = -a_i b_i\) and the logit of its guessing parameter \(c_i\), the parameters of Marginal Maximum Likelihood, under its priors (ADR-0008): lognormal on the slope, normal on the intercept and on the logit of \(c\). A prior is needed on every parameter drawn [Kim and Bolt, 2007, p. 40], and the posterior must be proper [Patz and Junker, 1999, p. 345], so the calibrator refuses a parameter drawn without one. The abilities are standard normal, as in Patz and Junker [1999, p. 353] and Marginal Maximum Likelihood.

The steps. Each iteration draws every ability, each by its own step, then every item, each item’s parameters proposed independently and accepted together [Patz and Junker, 1999, p. 161]; [Patz and Junker, 1999, p. 349]. Patz and Junker [1999, p. 161] print \(R_\beta\) with the two proposal densities the other way round from their Equation 8, which leaves the factor \(a_i^{t-1} / a_i^*\) instead; irtlib follows Equation 8, under which the factor cancels the \(1/a\) of the lognormal prior’s density. The 3PL’s guessing parameter takes a normal step on its logit, where the priors are; Patz and Junker draw \(c\) itself uniformly within \(\delta\) of its current value under a beta prior [Patz and Junker, 1999, p. 349, Equations 11-12]. A slope fixed for every item drops the slope’s step, as for their Rasch model [Patz and Junker, 1999, p. 159]. The 1PL’s slope, which every item shares (ADR-0008), takes a lognormal step of its own between the abilities’ and the items’, its ratio over every item’s responses and its prior counted once; the sources give no step for it.

The proposals. The steps’ standard deviations default to Patz and Junker’s for 3,000 examinees: 0.8 for the abilities, and 0.09 for the 2PL’s or 0.12 for the 3PL’s slopes, on the log scale, and intercepts [Patz and Junker, 1999, p. 353]. The 1PL takes the 2PL’s. For the logit of \(c\), 0.15 is the standard deviation of their uniform step of \(c\) within \(\delta = 0.05\), \(0.05/\sqrt 3\), at their prior mean \(c = 1/4\), where the logit’s derivative is \(1/(c(1 - c))\). Gelman, Roberts and Gilks (1996) recommend acceptance rates of about 50% for one parameter, decreasing toward 25% for a block of several, as Patz and Junker [1999, p. 159] describe them, and Patz and Junker tuned their steps to these rates in preliminary runs [Patz and Junker, 1999, p. 163]; [Patz and Junker, 1999, p. 353]. A calibration reports how often each step was accepted after the burn-in, so that its steps can be tuned. With the defaults, on 20 items and 1,000 examinees of the 2PL, 49% of the steps of the abilities and of the items were accepted (measured 2026-11-28). On 8 items and 300 examinees of the 2PL, 1,000 iterations of five chains left a largest potential scale reduction of 1.10 to 1.32 over five data sets, against 1.07 to 1.19 with steps of 0.2 for the slopes and intercepts (measured 2026-12-02).

Starting values. Each chain starts from its own random values, dispersed as the potential scale reduction needs [Gelman and Rubin, 1992, p. 460], as Culpepper [2016, Section 3.1] starts five: abilities and intercepts standard normal, and slopes uniform on \((0, 3)\). Culpepper’s are the parameters of the normal-ogive model, and he draws the guessing and slipping parameters of the 4PL jointly, uniform where their sum is below 1; the 3PL has no slipping parameter, and irtlib draws its guessing parameter uniform on \((0, 1)\).

Chains, iterations and burn-in. Five chains of 10,000 iterations by default, as Kim and Bolt [2007, p. 45] ran. The first half of each chain is discarded as burn-in, as Gelman and Rubin [1992, p. 460] discard the first \(n\) of \(2n\) iterations and Culpepper [2016, Section 3.1] the first 50,000 of 100,000; it “has been common to dismiss the first 500 or so states” [Kim and Bolt, 2007, p. 42]. Each chain draws from its own stream, spawned from the generator the call is given (ADR-0005).

Convergence. The potential scale reduction is computed for each item’s \(a\), \(b\) and \(c\) over the draws kept. Gelman and Rubin monitor until it is “near 1” for every quantity of interest, with no number [Gelman and Rubin, 1992, p. 461]; a calibration converges when every one is below 1.1, and warns otherwise. Brooks and Gelman call 1.1 “the more stringent standard”, against 1.2, “sometimes used as a guideline for ‘approximate convergence’” [Brooks and Gelman, 1998, p. 444]. The variances and covariances of Equation 4 are taken over the \(m\) chains with divisor \(m - 1\), which neither source states (sources wanted). The potential scale reduction is infinite where \(W = 0\), no chain moving; an estimate of \(\operatorname{var}(\hat V)\) that is not positive gives no correction.

The estimates. The estimates are the posterior means of \(a\), \(b\) and \(c\) over the draws kept of every chain, and the standard errors their posterior standard deviations [Kim and Bolt, 2007, p. 46], the square roots of the variances of each item’s posterior covariance over the same draws; the result keeps those draws, and not the abilities’ (ADR-0012). The log-likelihood reported is the marginal one at the estimates, over the grid of Marginal Maximum Likelihood, so that Item and Person Fit and Model Comparison take the calibration; the one recorded after each iteration is at the mean of the items the chains drew in it. A posterior mode can be estimated “from a kernel density estimate or normal approximation” of the draws [Patz and Junker, 1999, p. 156], and the normal approximation’s mode is the mean. On 10 items and 1,000 simulated examinees with 5% of responses missing, the posterior means of the slopes exceeded Marginal Maximum Likelihood’s Bayes modal estimates under the same priors by up to 0.19 posterior standard deviations, and those of the difficulties differed by up to 0.07, in a run of 50,000 draws (measured 2026-11-28).

Missing responses. A missing response is left out of the likelihood. Patz and Junker draw the missing responses as one more step of each iteration, under missingness that does not depend on the parameters or the responses [Patz and Junker, 1999, p. 351], and note that this is slow, so that “analytically averaging over the missing data” remains important (p. 352); leaving a response out of the likelihood averages over it exactly.

Run time. On 20 items and 1,000 simulated examinees, a calibration with the default settings took 46 seconds for the 2PL, 64 for the 3PL and 66 for the 1PL, whose shared slope adds a step to each iteration, against at most 0.2 seconds for Marginal Maximum Likelihood (measured 2026-11-28). Of these, recording the marginal log-likelihood after each iteration took 4.5, 7.0 and 7.0 seconds, 10% to 11% of each run, measured against the same runs without it. Patz and Junker’s chains of 7,400 iterations took about 5.7 hours each in S-Plus [Patz and Junker, 1999, p. 170], and Kim and Bolt’s of 10,000 about 3 hours in WinBUGS [Kim and Bolt, 2007, p. 46]. The 3PL mixes slowly: its draws had significant autocorrelations up to lag 350, where the 2PL’s had none at lag 100 [Patz and Junker, 1999, p. 353].

Parameters#

Parameter

Default

Description

Default from

model

"2PL"

"1PL" (one slope shared by every item), "2PL" or "3PL".

MMLCalibrator’s default

priors

none: required

A Priors with a prior on each parameter the model draws: the slope, the intercept and, for the 3PL, the logit of \(c\).

Kim and Bolt [2007, p. 40]; no default prior (ADR-0008)

fixed_slope

None

A slope every item keeps instead of drawing it.

no fixed slope (ADR-0008)

chains

5

The number of chains, at least 2.

Kim and Bolt [2007, p. 45]

iterations

10_000

The iterations of each chain, burn-in included.

Kim and Bolt [2007, p. 45]

burn_in

half of iterations

The iterations of each chain before the first draw kept.

Gelman and Rubin [1992, p. 460]

proposals

0.8; 0.09, or 0.12 for the 3PL; 0.15

A Proposals: the standard deviations of the steps of the abilities, of the log slopes and the intercepts, and of the logits of \(c\).

Patz and Junker [1999, p. 353]; for the 1PL and the logit of \(c\), no source yet (sources wanted)

max_scale_reduction

1.1

The convergence check: every potential scale reduction below it.

Brooks and Gelman [1998, p. 444]

rng of calibrate

None

The generator each chain’s stream is spawned from; an integer fixes it.

ADR-0005

Guarantees#

  1. The same rng, responses and settings give the same draws.

  2. Every estimate comes with its potential scale reduction; a calibration whose chains do not all fall below max_scale_reduction says so in its result and warns with a ConvergenceWarning.

  3. The result keeps every chain’s draws of every item after the burn-in, of which the estimates and covariances are the means and covariances; the burn-in is not kept.

  4. Responses may be missing, and an examinee who answered no item changes no item’s posterior.

  5. A model drawn without a prior on one of its parameters is refused.

References#

[Alb92]

James H. Albert. Bayesian estimation of normal ogive item response curves using Gibbs sampling. Journal of Educational Statistics, 17(3):251–269, 1992. Not openly available; Sheng (2008) describes the method. doi:10.3102/10769986017003251.

[BG98] (1,2,3,4,5)

Stephen P. Brooks and Andrew Gelman. General methods for monitoring convergence of iterative simulations. Journal of Computational and Graphical Statistics, 7(4):434–455, 1998. Open copy: https://sites.stat.columbia.edu/gelman/research/published/brooksgelman2.pdf. doi:10.1080/10618600.1998.10474787.

[Cul16] (1,2)

Steven Andrew Culpepper. Revisiting the 4-parameter item response model: Bayesian estimation and application. Psychometrika, 81(4):1142–1163, 2016. Not openly available; Zhang, Lu, Du and Zhang (2020) describe the method. doi:10.1007/s11336-015-9477-6.

[GR92] (1,2,3,4,5,6,7)

Andrew Gelman and Donald B. Rubin. Inference from iterative simulation using multiple sequences. Statistical Science, 7(4):457–472, 1992. Open copy: https://sites.stat.columbia.edu/gelman/research/published/itsim.pdf. doi:10.1214/ss/1177011136.

[KB07] (1,2,3,4,5,6,7,8,9,10,11)

Jee-Seon Kim and Daniel M. Bolt. Estimating item response theory models using Markov chain Monte Carlo methods. Educational Measurement: Issues and Practice, 26(4):38–51, 2007. Open copy: https://www.ncme.org/wp-content/uploads/2025/10/Module-27-Markov-chain-Monte-Carlo-Estimation-Kim-1.pdf. doi:10.1111/j.1745-3992.2007.00107.x.

[PJ99a] (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)

Richard J. Patz and Brian W. Junker. A straightforward approach to Markov chain Monte Carlo methods for item response models. Journal of Educational and Behavioral Statistics, 24(2):146–178, 1999. Not openly available; Kim and Bolt (2007) describe the method. doi:10.3102/10769986024002146.

[PJ99b] (1,2,3,4,5,6,7,8,9,10,11)

Richard J. Patz and Brian W. Junker. Applications and extensions of MCMC in IRT: multiple item types, missing data, and rated responses. Journal of Educational and Behavioral Statistics, 24(4):342–366, 1999. Not openly available; Kim and Bolt (2007) describe the sampling it extends, citing this paper as their 1999a. doi:10.3102/10769986024004342.

API Reference#

Calibration of the 1PL to 3PL by Markov chain Monte Carlo, from several chains, with their potential scale reduction.

A calibration draws every examinee’s ability and every item’s parameters, in turn, from their posterior given the responses, under a prior on every item parameter (irtlib.mml.Priors) and abilities normal with mean 0 and variance 1. Several chains start from random values and run side by side; potential_scale_reduction() compares them. The draws are kept in the parameters of an item bank, [a, b, c, d].

class irtlib.mcmc.MCMCCalibration(estimates: NDArray[floating[Any]], items: ItemBank | None, covariances: NDArray[floating[Any]] | None, log_likelihood: float, log_likelihoods: NDArray[floating[Any]], likelihood: Likelihood, n_parameters: int, item_parameters: NDArray[integer[Any]], converged: bool, change: float, grid: QuadratureGrid | None, abilities: AbilityEstimates | None, draws: NDArray[floating[Any]], burn_in: int, potential_scale_reduction: NDArray[floating[Any]], ability_acceptance: NDArray[floating[Any]], item_acceptance: NDArray[floating[Any]], slope_acceptance: NDArray[floating[Any]] | None)[source]#

The result of a calibration by Markov chain Monte Carlo: its summaries, and every chain’s draws.

It is a Calibration, whose fields summarize the draws kept, so item fit and model comparison take it, and it prints as one does, with its burn-in.

Parameters:
estimates, covariancesnumpy.ndarray

The posterior means of each item’s [a, b, c, d] over the draws of every chain, and the posterior covariance of each item’s draws, whose variances give the standard errors; a parameter the model does not draw keeps its value, with NaN in its row and column.

log_likelihood, log_likelihoods, likelihood, gridfloat, numpy.ndarray, Likelihood, QuadratureGrid

The marginal log-likelihood at the estimates, and after each iteration at the mean of the items the chains drew in it, so that cycles is the iterations of each chain, burn-in included; abilities are integrated over the default grid, which item fit reuses.

converged, changebool, float

Whether every potential scale reduction is below the calibrator’s limit, with a ConvergenceWarning if not, and the largest of them.

items, n_parameters, item_parameters, abilitiesItemBank or None, int, numpy.ndarray, None

As in every Calibration; abilities is None.

drawsnumpy.ndarray

Every chain’s draws [a, b, c, d] of every item after the burn-in, of shape (chains, iterations - burn_in, n_items, 4): draws[k, t, i] is item i after iteration burn_in + t + 1 of chain k. A parameter not estimated keeps its value in every draw. The burn-in is not kept.

burn_inint

The iterations of each chain before the first draw kept.

potential_scale_reductionnumpy.ndarray

The potential scale reduction of each estimate over the chains, in the shape of estimates, NaN for a parameter not estimated.

ability_acceptancenumpy.ndarray

For each chain, the share of the steps of the abilities accepted after the burn-in, over every examinee.

item_acceptancenumpy.ndarray

For each chain and item, the share of the steps of the item’s parameters accepted after the burn-in, of shape (chains, n_items); for the 1PL with an estimated slope, of the item’s intercept.

slope_acceptancenumpy.ndarray or None

For each chain, the share of the steps of the 1PL’s shared slope accepted after the burn-in; None unless the 1PL estimates its slope.

class irtlib.mcmc.MCMCCalibrator(model: IrtModel | str = IrtModel.PL2, *, priors: Priors, fixed_slope: float | None = None, chains: int = 5, iterations: int = 10000, burn_in: int | None = None, proposals: Proposals | None = None, max_scale_reduction: float = 1.1)[source]#

Calibrate the 1PL to 3PL by Markov chain Monte Carlo, from several chains, with priors on every item parameter.

Each call to calibrate() draws from the posterior of the items of one response matrix, which may have missing responses, with abilities normal with mean 0 and variance 1. Every chain starts from random values, keeps its draws after the burn-in, and the chains are compared by their potential scale reduction.

The Markov Chain Monte Carlo page gives the method, its sources and the origin of each default.

Parameters:
modelirtlib.IrtModel or str, optional

"2PL", the default, draws a slope per item; "1PL" one slope shared by every item; "3PL" also a guessing parameter per item.

priorsirtlib.mml.Priors

Priors on the slope, the intercept and the logit of the guessing parameter of every item: one on each parameter the model draws.

fixed_slopefloat, optional

A slope every item keeps instead of drawing it, with any model.

chainsint, optional

The number of chains. Default is 5.

iterationsint, optional

The iterations of each chain, burn-in included; each draws every ability and then every item. Default is 10,000.

burn_inint, optional

The iterations of each chain before the first draw kept. Default is half of iterations.

proposalsProposals, optional

The spreads of the random-walk steps. Default is Proposals’ defaults.

max_scale_reductionfloat, optional

The convergence check: the calibration converges when every potential scale reduction is below this. Default is 1.1.

Raises:
ValueError

If the model is the 4PL; a prior is missing on a parameter the model draws, or given on one it does not draw; fixed_slope is not finite and positive; chains is less than 2; burn_in is negative or leaves fewer than two draws per chain; or max_scale_reduction is not above 1.

Examples

>>> import numpy
>>> from irtlib.drawing import draw_responses
>>> items = numpy.array([[1.0, -1.0, 0.0, 1.0], [1.0, 0.0, 0.0, 1.0], [1.0, 1.0, 0.0, 1.0]])
>>> responses = draw_responses(numpy.random.default_rng(0).normal(size=200), items, rng=1)
>>> calibrator = MCMCCalibrator(
...   fixed_slope=1.0, priors=Priors(intercept=(0.0, 2.0)), iterations=1000, proposals=Proposals(intercept=0.3)
... )
>>> calibration = calibrator.calibrate(responses, rng=2)
>>> calibration.draws.shape, calibration.converged
((5, 500, 3, 4), True)
calibrate(responses: NDArray[floating[Any]], rng: int | Generator | None = None) → MCMCCalibration[source]#

Draw from the posterior of the items of a response matrix.

Parameters:
responsesnumpy.ndarray

The response matrix: one row per examinee, one column per item, holding 1, 0 or NaN for a missing response.

rngint or numpy.random.Generator or None, optional

The source of the draws; each chain draws from a stream spawned from it. None draws fresh entropy.

Returns:
MCMCCalibration

The posterior means, their posterior standard deviations and the marginal log-likelihood at them, with every chain’s draws after the burn-in, their potential scale reduction and how often each step was accepted. If a potential scale reduction is not below max_scale_reduction, the result says so and a ConvergenceWarning is issued; if an item’s estimates are not valid in an item bank, the result’s bank leaves the item out and a RuntimeWarning names it.

Raises:
TypeError

If the responses are neither Booleans, integers nor floats.

ValueError

If the responses fail irtlib.calibration.validate_responses().

class irtlib.mcmc.Proposals(ability: float = 0.8, slope: float | None = None, intercept: float | None = None, guessing: float = 0.15)[source]#

The spreads of the random-walk steps of a Markov chain Monte Carlo calibration.

Each is the standard deviation of a normal step: of an ability, of the log of a slope, of an intercept, or of the logit of a guessing parameter. Larger steps are accepted less often; the calibration reports how often each was.

Parameters:
abilityfloat, optional

The step of every ability. Default is 0.8.

slopefloat or None, optional

The step of the log of every slope, the 1PL’s shared slope included. Default is 0.12 for the 3PL and 0.09 otherwise.

interceptfloat or None, optional

The step of every intercept, -a * b. Default is 0.12 for the 3PL and 0.09 otherwise.

guessingfloat, optional

The step of the logit of every guessing parameter, for the 3PL. Default is 0.15.

Raises:
ValueError

If a spread is not finite and positive.

Examples

>>> Proposals(ability=1.1).ability
1.1
irtlib.mcmc.potential_scale_reduction(draws: ArrayLike) → NDArray[floating[Any]][source]#

Return the potential scale reduction of each quantity drawn by several chains.

It is the factor by which the spread of the draws could still shrink if the chains ran on: near 1 once the chains agree, and large while each still covers only part of the distribution. The Markov Chain Monte Carlo page gives its formula.

Parameters:
drawsarray_like

The draws kept from each chain, of shape (chains, n, ...): n draws per chain of a scalar, or of an array of quantities.

Returns:
numpy.ndarray

The potential scale reduction of each quantity, of shape draws.shape[2:]; inf where no chain varies.

Raises:
ValueError

If there are fewer than two chains or fewer than two draws per chain.

Examples

>>> import numpy
>>> draws = numpy.random.default_rng(0).normal(size=(4, 1000))
>>> float(potential_scale_reduction(draws).round(2))
1.0
>>> draws[3] += 1  # one chain away from the others
>>> float(potential_scale_reduction(draws).round(2))
1.19