# Conditional Mean Squares :API: {py:func}`irtlib.fit.conditional_mean_squares` :Sources: {cite:t}`Christensen2013`; {cite:t}`Muller2020`; {cite:t}`Wright1982` ## Motivation The {doc}`mean-squares` compare each response with its probability at an ability estimated from the same responses, which lowers their expectation below 1. On data drawn from the Rasch model with 10, 15 and 20 items, Müller finds the mean outfit 0.91, 0.94 or 0.95, and 0.96, and the mean infit 0.94, 0.96 and 0.97, at weighted likelihood abilities, whatever the number of examinees {cite:p}`Muller2020{p. 8, Table 3}`; Christensen and Kreiner know of "no published results" on how the choice of the ability estimate changes this {cite:p}`Christensen2013{p. 88}`. Under the Rasch model the number correct is sufficient for the ability, and the probability of a correct response given the number correct depends on the items alone, so that "we do not have to be concerned about how person parameters are estimated" {cite:p}`Christensen2013{p. 89}`. The conditional mean squares compare each response with that probability. Their mean is 1.00 on data that fit the model, at every test length and sample size Müller simulated, and he concludes that "conditional residuals should be used" {cite:p}`Muller2020{pp. 1, 8}`. They need a calibration of the 1PL, such as one by {doc}`/methods/calibration/cml`, and no abilities; for the 2PL to 4PL, {doc}`s-x2` groups the examinees by their number correct instead. ## Definition An examinee with $r$ correct responses answers item $i$ correctly with the probability $\pi_{ri}$ of the {doc}`/methods/calibration/cml` page, which depends on the items' difficulties alone {cite:p}`Christensen2013{p. 89, Equation 5.13}`; {cite:p}`Muller2020{p. 4, Equation 7}`. For examinee $j$, with $r$ correct, the residual of a response, its variance and its standardized value are $$ y_{ij} = u_{ij} - \pi_{ri}, \quad W_{ri} = \pi_{ri}(1 - \pi_{ri}), \quad z_{ij} = y_{ij} / W_{ri}^{1/2} $$ {cite:p}`Christensen2013{p. 86, Equations 5.6-5.7}`. Over the examinees whose number correct is neither 0 nor $M$, which tell nothing of the items' fit (p. 85), $n_r$ of them with $r$ correct, the outfit and the infit of item $i$ are $$ U_i = \frac{\sum_j z_{ij}^2}{\sum_r n_r}, \quad V_i = \frac{\sum_j y_{ij}^2}{\sum_r n_r W_{ri}} $$ (p. 86, Equations 5.8-5.9), both with expectation 1 under the model (p. 86). The outfit is the mean, weighted by $n_r / \sum_r n_r$, of the means of the identically distributed $z_{ij}^2$ of the examinees with $r$ correct, and so is asymptotically normal, with the variance of that weighted mean (pp. 89-90, Equations 5.14-5.15). A squared standardized residual has variance $\operatorname{VAR}(z^2 \mid r) = C_{ri}/W_{ri}^2 - 1$ {cite:p}`Wright1982{p. 100, Table 5.4a}`, where $C_{ri} = W_{ri}\,(\pi_{ri}^3 + (1 - \pi_{ri})^3)$ is the kurtosis of a response (p. 98, Equation 5.4.4), so that $$ \operatorname{VAR}(U_i) = \frac{\sum_r n_r \operatorname{VAR}(z^2 \mid r)}{\left(\sum_r n_r\right)^2}. $$ At $\pi_{ri} = .1$, $z^2$ is 0.1111 or 9, with variance 7.1 {cite:p}`Christensen2013{p. 87}`. The infit's distribution "can be derived in the same way" {cite:p}`Christensen2013{p. 90}`, with no formula printed. irtlib derives it so: given the numbers correct, the infit's denominator is fixed, and the $y_{ij}^2$ of the examinees with $r$ correct are identically distributed with mean $W_{ri}$ and variance $C_{ri} - W_{ri}^2$, so that $$ \operatorname{VAR}(V_i) = \frac{\sum_r n_r (C_{ri} - W_{ri}^2)}{\left(\sum_r n_r W_{ri}\right)^2}, $$ the variance $q_i^2$ of the weighted mean square {cite:p}`Wright1982{p. 101, Equation 5.4.8}` at the conditional probabilities. Each mean square is standardized as $(U_i - 1)/\operatorname{VAR}(U_i)^{1/2}$ and $(V_i - 1)/\operatorname{VAR}(V_i)^{1/2}$, with no cube root, which brought the conditional statistics "no apparent improvement" in Müller's simulations {cite:p}`Muller2020{p. 6}`; Christensen and Kreiner's two-sided normal $p$-values follow from these, an outfit of 1.237 with a standard deviation of 0.107 having $p = .027$ {cite:p}`Christensen2013{p. 90, Table 5.1}`. ## Implementation **The model.** The number correct is sufficient for the ability under the Rasch model {cite:p}`Christensen2013{p. 89}`, so the conditional mean squares take a calibration of the 1PL: every item with the same slope $a$, $c = 0$ and $d = 1$, whose Rasch item parameters are $a b_i$ {cite:p}`Wright1982{p. 38, Equation 3.1.1}`, so that $\varepsilon_i = e^{-a b_i}$. Its likelihood does not matter: no ability and no grid is used. **Items and examinees left out.** An item the calibration left without an estimate, as {doc}`/methods/calibration/cml` leaves an item answered correctly by every examinee or by none, has no probabilities, and its values are NaN; the numbers correct count the other items. The examinees with none or all of those correct are left out of every item's sums {cite:p}`Christensen2013{p. 85}`; after a calibration by conditional maximum likelihood, they are the examinees it left out. The sources sum over complete responses, and a missing response is refused, as for the {doc}`mean-squares` ({doc}`ADR-0006 `). **The probabilities** come from the logarithms of the elementary symmetric functions, by the summation algorithm of {doc}`/methods/calibration/cml`, which keeps long tests from overflowing. **The standard deviations are asymptotic.** Müller finds them too large, because the squared residuals of an item are negatively correlated, so that the standardized values come out too small and a fitting item is rejected less often than the nominal level; he recommends a parametric bootstrap for the outfit's $p$-values {cite:p}`Muller2020{pp. 1, 8, 10}`. irtlib reports the asymptotic values. On Müller's design, 20 data sets of 2,000 examinees with items from {doc}`/methods/calibration/cml`, the outfit and infit averaged 0.998 and 1.000 with 10 items, and 1.000 with 20; 2.5% to 3.5% of the fitting items had a standardized outfit beyond ±1.96, and 1% a standardized infit (measured 2026-12-02). ## Parameters {func}`~irtlib.fit.conditional_mean_squares` takes the calibration and the responses it was calibrated on, and has no settings. ## Guarantees 1. Each item gets its conditional outfit and infit and their standardized values, from a calibration of the 1PL of any likelihood, without abilities. 2. An item the calibration left without an estimate gets NaN. The examinees with none or all of the other items correct are left out of every item's sums, without a warning; when no examinee is left, every value is NaN. 3. A calibration of a model other than the 1PL, or a missing response, raises an error. ## References ```{bibliography} :filter: docname in docnames ``` ## API Reference ```{eval-rst} .. autofunction:: irtlib.fit.conditional_mean_squares ```