Plot Distribution of Simulated Infit and Outfit MSQ Values
Source:R/infitcutoff_plot.R
RMitemInfitCutoffPlot.RdVisualises the distribution of simulation-based conditional item fit values
from RMitemInfitCutoff, optionally overlaying observed item fit
from the original data.
Arguments
- simfit
The return value of
RMitemInfitCutoff(a list with componentsresults,item_cutoffs,actual_iterations,sample_n, anditem_names).- data
Optional. A data.frame or matrix of item responses for computing and overlaying observed conditional item fit values. Items must be scored starting at 0 (non-negative integers). When provided, the plot includes orange diamond markers for the observed infit/outfit MSQ alongside the simulated distribution, plus segment summaries from the cutoff intervals.
- output
Character string. Either
"infit"(default) to show only the infit panel,"outfit"to show only the outfit panel, or"both"to show infit and outfit side by side (requires thepatchworkpackage whendatais supplied).
Details
Uses ggdist::stat_dotsinterval() (when data is not supplied) or
ggdist::stat_dots() (when data is supplied) with
point_interval = "median_hdci" and .width = c(0.66, 0.999).
When data is not supplied, the function plots the simulated MSQ
distributions as dot-interval plots using ggdist::stat_dotsinterval() with
median and Highest Density Continuous Interval (HDCI) summaries, faceted by
statistic (InfitMSQ / OutfitMSQ).
When data is supplied, the function:
Fits a Rasch model (
eRm::RM()for dichotomous data oreRm::PCM()for polytomous data) and computes observed conditional infit and outfit MSQ viaiarm::out_infit().Overlays observed fit values as orange diamond markers on the simulated distributions.
Shows per-item cutoff intervals (from
simfit$item_cutoffs) as black line segments, with thicker segments for the 66% HDCI range and black dots for the median.
The ggplot2, ggdist, and optionally patchwork packages must be
installed (they are in Suggests, not Imports).
Examples
# \donttest{
set.seed(42)
sim_data <- as.data.frame(
matrix(sample(0:1, 200 * 10, replace = TRUE), nrow = 200, ncol = 10)
)
colnames(sim_data) <- paste0("Item", 1:10)
# Run simulation
cutoff_res <- RMitemInfitCutoff(sim_data, iterations = 100, parallel = FALSE,
seed = 42)
# Simulated distribution only (infit + outfit faceted)
RMitemInfitCutoffPlot(cutoff_res)
# With observed fit overlaid (infit only, the default)
RMitemInfitCutoffPlot(cutoff_res, data = sim_data)
# Both infit and outfit panels side by side
RMitemInfitCutoffPlot(cutoff_res, data = sim_data, output = "both")
# }