| RMdimMartinLofResiduals | R Documentation |
Diagnostic accompanying RMdimMartinLof: per-cell standardised
residuals from the joint distribution of subscores under unidimensionality
(Christensen, Bjorner, Kreiner, & Petersen, 2002, eq. 13). Useful for
identifying where a partition deviates from the unidimensional null
rather than just whether it does (which RMdimMartinLof() answers).
RMdimMartinLofResiduals(
data,
partition,
output = c("kable", "dataframe", "ggplot"),
flag_threshold = 2,
color_by = c("residual", "n"),
color_limits = NULL,
min_expected = NULL
)
data |
A data.frame or matrix of item responses (0-based,
non-negative integers). Complete cases only: rows with any |
partition |
Same format as in |
output |
Character. |
flag_threshold |
Numeric. Cells with |
color_by |
Character. For |
color_limits |
Numeric length-2 vector or |
min_expected |
Numeric or |
For each cell of the joint subscore table (indexed by
(t_1, \ldots, t_D)), the conditional probability under H0 given the
total score t = \sum_d t_d is
p(t_1, \ldots, t_D \mid t) = \prod_d \gamma^{(d)}_{t_d} / \gamma_t,
the expected count is e = n_t \cdot p, and the residual is
(o - e) / \sqrt{n_t \cdot p \cdot (1 - p)}. CML estimates from the
unidimensional model are used for the \gamma-functions.
Reading the table (D = 2): under the unidimensional null, residuals
should be patternless and roughly N(0, 1). Multidimensionality with
positively correlated dimensions typically shows up as positive
residuals at the corners of each antidiagonal (high t1 + low t2,
low t1 + high t2) and negative residuals near the antidiagonal
centre (matched subscores). Negatively correlated dimensions show
positive residuals at the table corners (high/low and low/high) and
negative residuals at high/high and low/low. See Christensen et al.
(2002, section7) for a worked example.
Cells where the total score has no observed cases (n_t = 0) are
uninformative and are dropped from the output.
Complete cases only, as in RMdimMartinLof, and rows with
NA are dropped only after items outside partition have been removed.
The reported n = X of Y respondents counts respondents complete on the
partitioned items against the raw input rows.
Expected counts and residuals agree to numerical precision with the pml
SAS macro (Christensen, 2004), kindly shared by Karl Bang Christensen.
The one deliberate difference is at the extreme totals t = 0 and
t = max, where the conditional probability is 1 and the residual is
undefined: the macro prints 0, this function returns NA.
output = "kable": a knitr_kable object. For D = 2, a wide table
with rows = t1, columns = t2, cells = standardised residual
(**bold** if flagged, em-dash if NA). For D > 2, long-format with
one row per cell.
output = "dataframe": a long-format data.frame with columns t1,
..., tD, total, observed, expected, residual, flagged.
output = "ggplot": a geom_tile() heatmap (D = 2 or 3 only).
Christensen, K. B. (2004). pml: A SAS macro for testing unidimensionality in polytomous Rasch models (Technical note). National Institute of Occupational Health, Denmark, and Department of Biostatistics, University of Copenhagen.
Christensen, K. B., Bjorner, J. B., Kreiner, S., & Petersen, J. H. (2002). Testing unidimensionality in polytomous Rasch models. Psychometrika, 67(4), 563-574. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/BF02295132")}
RMdimMartinLof
set.seed(1)
dat <- as.data.frame(matrix(sample(0:1, 400 * 8, replace = TRUE),
nrow = 400, ncol = 8))
colnames(dat) <- paste0("I", 1:8)
# Wide kable table for D = 2
RMdimMartinLofResiduals(dat,
partition = list(c("I1","I2","I3","I4"),
c("I5","I6","I7","I8")))
# Heatmap
if (requireNamespace("ggplot2", quietly = TRUE)) {
RMdimMartinLofResiduals(dat,
partition = c(1,1,1,1,2,2,2,2),
output = "ggplot")
}
# Underlying data.frame for custom analysis
df <- RMdimMartinLofResiduals(dat,
partition = c(1,1,1,1,2,2,2,2),
output = "dataframe")
df[df$flagged, ]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.