Mean Squares#

API:

irtlib.fit.mean_squares(); irtlib.fit.person_mean_squares(); irtlib.fit.MeanSquares

Sources:

Wright and Masters [1982]; Wright and Stone [1979]; Meijer and Sijtsma [2001]; Karabatsos [2003]

Motivation#

The weighted and unweighted mean squares compare each response with its expectation at the examinee’s estimated ability [Wright and Masters, 1982, pp. 97-99], summed item by item: the infit and the outfit of the Rasch model. Wright and Masters define them for the models of their book, all built from the Rasch model (p. 10; p. 100, Table 5.4a), whose model for dichotomous responses (p. 38, Equation 3.1.1) is the 1PL, every item with the same slope \(a\), with person parameters \(a\theta_j\) and item parameters \(ab_i\). irtlib computes them for every model, 1PL to 4PL, at each item’s probabilities. The Implementation gives the sources, and measures them against S-X², which detected a misfitting item that the item mean squares missed under the 2PL to 4PL.

Summed examinee by examinee instead, over the items each examinee answered, the same residuals give each examinee’s mean squares: person fit, which flags the examinees whose response patterns the model does not explain [Wright and Masters, 1982, p. 108]. Item fit serves the construction and calibration of a test, and person fit the validity of the measures a calibrated test makes (p. 109).

Definition#

For examinee \(j\) and item \(i\), with \(P_{ij}\) the probability of a correct response at the examinee’s ability and \(Q_{ij} = 1 - P_{ij}\), the score residual \(y_{ij} = u_{ij} - P_{ij}\) [Wright and Masters, 1982, p. 98, Equation 5.4.2] has variance \(W_{ij}\) and kurtosis \(C_{ij}\) (p. 98, Equations 5.4.3 and 5.4.4), which for the two categories of a dichotomous item are

\[W_{ij} = P_{ij} Q_{ij}, \quad C_{ij} = P_{ij} Q_{ij} (P_{ij}^3 + Q_{ij}^3),\]

and the standardized residual is \(z_{ij} = y_{ij} / W_{ij}^{1/2}\) (p. 99, Equation 5.4.5). Over the \(N\) examinees, the unweighted and the weighted mean squares, which Wright and Masters write \(u_i\) and \(v_i\), are

\[U_i = \frac{1}{N} \sum_j z_{ij}^2, \quad V_i = \frac{\sum_j W_{ij} z_{ij}^2}{\sum_j W_{ij}} = \frac{\sum_j y_{ij}^2}{\sum_j W_{ij}}\]

(p. 99, Equations 5.4.6 and 5.4.7). irtlib calls \(U_i\) the outfit and \(V_i\) the infit. \(U_i\) is sensitive to unexpected responses of examinees for whom the item is far too easy or far too hard, and the weights \(W_{ij}\), smallest for those examinees, lessen their influence on \(V_i\) (pp. 99, 101). When the data fit the model both have expectation 1, \(U_i\) with variance \(\sum_j (C_{ij} / W_{ij}^2) / N^2 - 1 / N\) (p. 100, Table 5.4a) and \(V_i\) with variance

\[q_i^2 = \frac{\sum_j (C_{ij} - W_{ij}^2)}{\left(\sum_j W_{ij}\right)^2}\]

(p. 101, Equation 5.4.8). The weighted mean square is standardized to

\[t_i = (V_i^{1/3} - 1)(3 / q_i) + q_i / 3,\]

which has a mean near 0 and a standard deviation near 1 when the data fit (p. 101; p. 100, Table 5.4a). Wright and Masters estimate the person and item parameters from the same data as the residuals, which lowers the expected mean square by the factor \((M - 1)(N - 1) / (MN)\) for \(M\) items (p. 101). Karabatsos [2003, p. 296] standardizes an examinee’s mean squares by the same transformation, “where MS can either refer to U or W”, the unweighted or the weighted. irtlib standardizes the unweighted mean square of an examinee so, and of an item likewise, since the examinees’ mean squares parallel the items’ [Wright and Masters, 1982, p. 109], with the standard deviation from Table 5.4a in place of \(q_i\).

Person fit. The examinees’ mean squares “parallel the corresponding item fit statistics exactly”, the squared residuals summed over the items for one examinee rather than over the examinees for one item [Wright and Masters, 1982, p. 109]. Over the \(M_j\) items examinee \(j\) answered, the weighted mean square, its variance and its standardized value are

\[V_j = \frac{\sum_i y_{ij}^2}{\sum_i W_{ij}}, \quad q_j^2 = \frac{\sum_i (C_{ij} - W_{ij}^2)}{\left(\sum_i W_{ij}\right)^2}, \quad t_j = (V_j^{1/3} - 1)(3 / q_j) + q_j / 3\]

(pp. 108-109, Equations 5.7.6-5.7.8), and the unweighted mean square \(U_j = \sum_i z_{ij}^2 / M_j\) has the variance \(\sum_i (C_{ij} / W_{ij}^2) / M_j^2 - 1 / M_j\) of Table 5.4a (p. 100), with the items in place of the examinees. Wright and Stone [1979, p. 77, Equations 4.4.1-4.4.2] divide an examinee’s sum of squared standardized residuals by \(M - 1\) instead, one less than the number of items, and standardize it by a logarithm; irtlib follows Wright and Masters.

Implementation#

The abilities. The item mean squares take the abilities the caller passes, estimated at the calibration’s items by any of the Ability Estimation, or by default EAP estimates of irtlib.ability.expected_a_posteriori() on the calibration’s grid, abilities normal with mean 0 and variance 1 (ADR-0006). A calibration with no grid, such as one by Conditional Maximum Likelihood, needs the caller’s abilities, such as maximum likelihood estimates. An examinee whose ability is infinite or NaN, as the maximum likelihood estimate of a zero or perfect score is, is left out of every item’s sums, as Wright and Stone edit the zero and perfect scores out of the data before calibrating, since they “tell us in which direction to look for an estimate” of ability but not how far [Wright and Stone, 1979, p. 32]. The examinees’ mean squares take the abilities from the caller, estimated by any of the Ability Estimation. Under the 1PL, the Conditional Mean Squares need no abilities, and their expectation is not lowered by them.

The models. The mean squares of the items and of the examinees take items of any model, 1PL to 4PL, at each item’s probabilities. Wright and Masters write \(W_{ij}\) and \(C_{ij}\) in terms of the model’s probabilities (p. 108, Equations 5.7.1-5.7.3). Meijer and Sijtsma [2001, p. 115, Equations 20-21] write an examinee’s unweighted and weighted mean squares at \(P_g(\theta)\), “the item response function” of any model (p. 114). They note that the unweighted one, “developed for the Rasch model, also can be used for other IRT models” (p. 108), and report the examinees’ mean squares in use under the 2PL and the 3PL (pp. 124-125), where a study under the 3PL found the standardized unweighted one “poorly standardized” (p. 125). No source on the shelf applies the examinees’ mean squares to the 4PL, or the items’ to any model but the Rasch model. irtlib takes both at the probabilities of every model, since the examinees’ mean squares “parallel the corresponding item fit statistics exactly” [Wright and Masters, 1982, p. 109].

Measured on 2026-12-02 for each model, with slopes from 0.7 to 2 (1 under the 1PL), difficulties from −2 to 2, guessing parameters from .10 to .25 and upper asymptotes from .85 to .97 where the model has them, and abilities normal with mean 0 and variance 1:

  • at the generating items and abilities, over 200 data sets of 1,000 examinees and 20 or 40 items, every model’s item mean squares averaged 0.99 to 1.00, and their standardized values had means within 0.05 of 0 and standard deviations of 0.94 to 0.99, the 4PL’s as near as the 1PL’s;

  • over 30 data sets of 2,000 examinees and 20 or 40 items, calibrated by Marginal Maximum Likelihood and evaluated at the default EAP abilities, in which one item’s probability of a correct response rose and then fell with ability, which no model fits, and 5% of the examinees answered every item at random:

    • no other item of any model had a standardized value above 1.96; 34% to 87% had a standardized outfit below −1.96, and 24% to 70% a standardized infit, the 4PL’s no more often than the 1PL’s;

    • the misfitting item had a standardized outfit above 1.96 in half the data sets of 20 items and in all those of 40 under the 1PL, and in at most 3% under the 2PL to 4PL, whose estimates of the item absorb its misfit, while S-X² rejected it at the 5% level in each of 15 data sets of 20 items without the random responders, under every model;

    • 32% to 94% of the examinees who answered at random had a standardized infit above 1.96, by model and test length, the 4PL’s within 0.06 of the 3PL’s, and at most 1% of the others;

    • the 4 of these 240 calibrations that stopped short of convergence are included, and the 5 of the 4PL that failed with a singular information matrix were drawn again.

Missing responses. Wright and Masters’ sums run over every examinee and every item, with no rule for a missing response. The item mean squares need complete responses (ADR-0006). The examinees’ mean squares sum over the items each examinee answered, \(M_j\) of them, with no source on the shelf for that rule; an examinee who answered no item, or whose ability is infinite or NaN, has none of the four values.

Two choices no source on the shelf covers:

  • a variance \(W_{ij}\) whose square is below \(10^{-5}\) is raised to \(10^{-5/2}\), leaving \(C_{ij}\) and \(y_{ij}\) as they are, so that a mean square’s variance can fall below 0, and its \(t\) is then NaN;

  • the standard deviation of either mean square is capped at 1.4142 before standardizing.

The sources wanted list these two, the item mean squares beyond the Rasch model and the examinees’ of the 4PL, and the examinees’ sums over the answered items.

Comparison with mirt
  • mirt 1.48 calls \(U\) and \(V\) outfit and infit too (R/itemfit.R:584, 588), and takes EAP estimates by default (R/itemfit.R:268, 535-538), on the grid of its fscores, or the abilities of its Theta argument (R/itemfit.R:84-87, 536).

  • irtlib’s standardized outfit and its two choices above are mirt’s: the standardized outfit (R/itemfit.R:585, 587), the floor on \(W_{ij}\) (R/personfit.R:189-200) and the cap on the standard deviation (R/itemfit.R:586, 591; R/personfit.R:205, 209).

  • mirt computes the mean squares of any model from its probabilities (R/personfit.R:181-194), and with missing responses sums over the examinees who answered each item, with \(N\) their number (R/itemfit.R:577-584), and over the items each examinee answered, with \(M_j\) their number (R/personfit.R:195, 202-210).

  • Three departures. mirt replaces an infinite ability by the largest finite one plus 0.1, or the smallest less 0.1, in the item mean squares (R/itemfit.R:542-549) and in the examinees’ (R/personfit.R:146-151); irtlib leaves that examinee out of the items’ sums, and gives the examinee NaN. In the examinees’ mean squares with missing responses, mirt divides the first term of the outfit’s variance by the square of the number of all items, \(M^2\), where irtlib divides it by \(M_j^2\) (R/personfit.R:204). Where the floor on \(W_{ij}\) leaves that variance negative, mirt takes its absolute value (R/personfit.R:204), and irtlib gives NaN.

  • At mirt’s estimates and abilities the parity tests find the item mean squares and their standardized values within a relative \(10^{-10}\); on irtlib’s own calibration, the mean squares within a relative \(10^{-4}\) and the standardized values within \(10^{-3}\) (ADR-0003). At the same abilities, on 2PL, 3PL and 4PL items, they find mirt’s mean squares of the items, with complete responses, and of the examinees, with responses complete and missing, within a relative \(10^{-10}\), and their standardized values too, except the examinees’ standardized outfit with missing responses.

Parameters#

mean_squares() takes the calibration and the responses it was calibrated on, and optionally each examinee’s ability, theta, by default the EAP estimates on the calibration’s grid. person_mean_squares() takes the responses, the items and each examinee’s ability. Neither has other settings.

Guarantees#

  1. Each item, or each examinee, gets its outfit and infit, and their standardized values; a standardized value is NaN where its mean square’s variance is not positive.

  2. For the item mean squares, a missing response, or, without abilities passed in, a calibration whose likelihood is not marginal raises an error.

  3. The item mean squares leave out an examinee whose ability is infinite or NaN, without a warning; an item with no examinee left has NaN for all four values.

  4. The mean squares of an examinee leave out the examinee’s missing responses, and are NaN when the examinee answered no item or the ability is infinite or NaN, without a warning.

References#

[Kar03] (1,2)

George Karabatsos. Comparing the aberrant response detection performance of thirty-six person-fit statistics. Applied Measurement in Education, 16(4):277–298, 2003. Not openly available; Wright and Masters (1982) describe the mean squares, and the cube-root standardization of the weighted one. doi:10.1207/S15324818AME1604_2.

[MS01] (1,2)

Rob R. Meijer and Klaas Sijtsma. Methodology review: evaluating person fit. Applied Psychological Measurement, 25(2):107–135, 2001. Not openly available; Wright and Masters (1982) describe the mean squares, for the Rasch model. doi:10.1177/01466210122031957.

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

Benjamin D. Wright and Geoffrey N. Masters. Rating Scale Analysis. MESA Press, Chicago, 1982. Open copy: https://www.rasch.org/BTD_RSA/pdf/Rating%20Scale%20Analysis.pdf.

[WS79] (1,2,3)

Benjamin D. Wright and Mark H. Stone. Best Test Design. MESA Press, Chicago, 1979. Open copy: https://www.rasch.org/BTD_RSA/pdf/Best%20Test%20Design.pdf.

API Reference#

irtlib.fit.mean_squares(calibration: Calibration, responses: NDArray[floating[Any]], *, theta: ArrayLike | None = None) → MeanSquares[source]#

Return the outfit and infit mean squares of every item of a calibration, from its responses.

Each response is compared with its probability under the item’s model, 1PL to 4PL, at the examinee’s ability: the ability passed as theta, or else the EAP estimate on the calibration’s grid, with abilities normal with mean 0 and variance 1. An examinee whose ability is infinite or NaN, such as the maximum likelihood estimate of responses all correct or all incorrect, is left out of every item’s sums, without a warning.

The Mean Squares page gives the method, its sources and the origin of each default.

Parameters:
calibrationCalibration

A calibration of any model, 1PL to 4PL. Without theta, it must be of the marginal likelihood, on whose grid the abilities are estimated.

responsesnumpy.ndarray

The complete response matrix the calibration estimated its items from: one row per examinee, one column per item, 1 or 0.

thetaarray_like or None, optional

Each examinee’s ability, one per row of responses, such as the theta of an AbilityEstimates at the calibration’s estimates. Default is None, the EAP estimates on the calibration’s grid.

Returns:
MeanSquares

Each item’s outfit and infit, and their standardized values; NaN for an item whose examinees all lack a finite ability.

Raises:
TypeError

If the responses are neither Booleans, integers nor floats, or theta holds values other than numbers.

ValueError

If, without theta, the calibration’s likelihood is not marginal, so that it has no grid; the responses fail irtlib.calibration.validate_responses(), have a missing response, or do not have one column per item of the calibration; or theta does not hold one ability per row of responses.

Examples

>>> import numpy
>>> from irtlib.drawing import draw_responses
>>> from irtlib.mml import MMLCalibrator
>>> items = numpy.column_stack([numpy.ones(4), [-1.0, -0.3, 0.3, 1.0], numpy.zeros(4), numpy.ones(4)])
>>> responses = draw_responses(numpy.random.default_rng(1).normal(size=500), items, rng=2)
>>> fit = mean_squares(MMLCalibrator("1PL").calibrate(responses), responses)
>>> fit.outfit.round(3), fit.infit.round(3)
(array([0.751, 0.772, 0.741, 0.723]), array([0.821, 0.807, 0.777, 0.791]))

A conditional calibration has no grid, so its mean squares take abilities, here the maximum likelihood estimates at its items:

>>> from irtlib.ability import maximum_likelihood
>>> from irtlib.cml import CMLCalibrator
>>> calibration = CMLCalibrator().calibrate(responses)
>>> theta = maximum_likelihood(responses, calibration.estimates).theta
>>> fit = mean_squares(calibration, responses, theta=theta)
>>> fit.outfit.round(3), fit.infit.round(3)
(array([0.903, 1.012, 0.907, 0.825]), array([0.933, 1.009, 0.929, 0.881]))
irtlib.fit.person_mean_squares(responses: ArrayLike, items: ArrayLike, theta: ArrayLike) → MeanSquares[source]#

Return the outfit and infit mean squares of every examinee, from the responses at the examinees’ abilities.

Each response is compared with its probability at the examinee’s ability, under the model of each item, 1PL to 4PL. A missing response is left out, so that each examinee’s mean squares sum over the items the examinee answered. An examinee who answered no item, or whose ability is infinite or NaN, gets NaN throughout.

The Mean Squares page gives the method, its sources and the origin of each default.

Parameters:
responsesarray_like

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

itemsarray_like

The items, a matrix of shape (n, 4), one row [a, b, c, d] per column of responses.

thetaarray_like

Each examinee’s ability, one per row of responses, such as the theta of an AbilityEstimates.

Returns:
MeanSquares

Each examinee’s outfit and infit, and their standardized values.

Raises:
TypeError

If the responses are neither Booleans, integers nor floats, or theta holds values other than numbers.

ValueError

If items is not an (n, 4) matrix of finite numbers, responses is not a matrix with one column per item, a response is not 0, 1 or NaN, or theta does not hold one ability per row of responses.

Examples

>>> import numpy
>>> items = numpy.array([[1.0, -1.0, 0.0, 1.0], [1.5, 0.0, 0.2, 1.0], [0.8, 1.0, 0.0, 0.9]])
>>> responses = numpy.array([[1, 1, 0], [0, 1, 1], [1, numpy.nan, 0]])
>>> fit = person_mean_squares(responses, items, [0.5, 0.0, -0.5])
>>> fit.outfit.round(3), fit.infit.round(3)
(array([0.378, 1.99 , 0.435]), array([0.402, 1.904, 0.465]))
class irtlib.fit.MeanSquares(outfit: NDArray[floating[Any]], outfit_t: NDArray[floating[Any]], infit: NDArray[floating[Any]], infit_t: NDArray[floating[Any]])[source]#

The outfit and infit mean squares of each item, or of each examinee, each with its standardized value.

An item’s mean squares sum over every examinee with a finite ability, and an examinee’s over the items the examinee answered. Both mean squares have expectation 1 when the responses fit the model at the abilities they are evaluated at, and less when the abilities are estimated from the same responses. The conditional mean squares of an item sum instead over every examinee with neither no nor every response correct, and have expectation 1 when the responses fit the 1PL, with no abilities. Printed, it shows a table of each item’s or examinee’s values.

Parameters:
outfitnumpy.ndarray

The unweighted mean square of each item or examinee, Wright and Masters’ \(u\): the mean of its squared standardized residuals.

outfit_tnumpy.ndarray

The outfit standardized by the same cube-root transformation as infit_t, with the outfit’s own standard deviation under the model, or, for the conditional mean squares, its difference from 1 over that standard deviation; NaN where its variance under the model is not positive.

infitnumpy.ndarray

The weighted mean square of each item or examinee, Wright and Masters’ \(v\): the sum of its squared residuals over the sum of their variances.

infit_tnumpy.ndarray

The infit standardized by a cube-root transformation, with its standard deviation under the model, or, for the conditional mean squares, its difference from 1 over that standard deviation; NaN where its variance under the model is not positive.