Postprocesses the output of infit_statistic to produce summary tables
of posterior predictive infit statistics and a combined slab +
interval plot comparing observed infit values to the posterior
predictive distribution.
Arguments
- infit_draws
A data frame (or tibble) as returned by
infit_statisticor one element of the output ofinfit_statistic_hpcm, containing the columnsinfit(observed infit per draw) andinfit_rep(replicated infit per draw). The item identifier is taken from a column nameditemif there is one, and otherwise from the first column.- ci
Numeric in \((0, 1)\). Width of the highest density continuous interval of the replicated (posterior predictive) infit distribution, used in the
hditable and the slab display. Default is 0.84.
Value
A list with three elements:
- summary
A
tibblewith one row per item containing:item,infit_obs(posterior mean of observed infit),infit_rep(mean of replicated infit across draws), andinfit_ppp(posterior predictive p-value: proportion of draws where the observed infit exceeds the replicated infit, counting ties as one half). Values near 0.5 indicate good fit, values near 1 suggest underfit and values near 0 suggest overfit.- hdi
A
tibblewith one row per item containing:item,underfit(proportion of draws where the observed infit exceeds the upper HDI bound of the replicated distribution), andoverfit(proportion of draws where the observed infit falls below the lower HDI bound). See Details for how to read these.- plot
A
ggplotobject showing the posterior predictive distribution of replicated infit (grey filled slab) overlaid with the observed infit distribution (coloured slab + interval), with a dashed reference line at 1 (perfect fit).
Details
Two complementary summary tables are provided:
summaryReports the posterior mean observed and replicated infit values alongside the posterior predictive p-value (ppp). The ppp is the proportion of draws where the observed infit exceeds the replicated infit, with ties counted as one half. Under good fit, the ppp should be near 0.5. A ppp near 1 indicates the observed infit is consistently larger than expected (underfit), and a ppp near 0 that it is consistently smaller (overfit). The direction is the same as for the ppp of
q3_postanditem_restscore_statistic.hdiReports the proportion of draws where the observed infit falls above (underfit) or below (overfit) the HDI of the replicated distribution. The HDI is computed over all draws, so each draw's observed value is compared to the same fixed interval. The observed infit varies across draws only through parameter uncertainty, while the replicated infit also varies through the sampling of new responses. The observed distribution is therefore narrower, and these proportions move quickly from near 0 to near 1 as the observed values pass an interval bound. They are exceedance proportions, not posterior probabilities of misfit.
The plot uses two layers from the ggdist package:
stat_slabDisplays the posterior predictive (replicated) infit distribution as a filled density slab per item, shaded by credible interval level.
stat_slabintervalDisplays the observed infit distribution per item as a semi-transparent slab with point and interval summaries.
Under good model fit, the observed infit distribution should overlap substantially with the replicated distribution. Items where the observed distribution sits systematically above the replicated HDI indicate underfit (more variation than expected); items below indicate overfit (less variation than expected).
The infit ppp is conservative. Values near 0 or 1 are rarer than for a
uniform p-value, and misfit can go undetected (see
infit_statistic).
It is suggested to also evaluate item fit with
item_restscore_statistic and
item_restscore_post.
Examples
if (FALSE) { # \dontrun{
library(brms)
library(ggplot2)
# Assuming fit_pcm is a fitted brmsfit object
infit_draws <- infit_statistic(fit_pcm)
result <- infit_post(infit_draws)
result$summary
result$hdi
result$plot
} # }