| RMdifLR | R Documentation |
Splits a Rasch model by an external grouping variable using
eRm::LRtest() and reports per-group item locations (or per-group
threshold locations) together with their standard errors. A single
function replaces the four legacy helpers (RIdifTableLR,
RIdifThreshTblLR, RIdifFigureLR, RIdifThreshFigLR) by exposing the
two underlying axes – level (item or threshold) and output
(data.frame, kable, or ggplot) – as arguments. The same data
preparation pipeline feeds all six combinations.
RMdifLR(
data,
dif_var,
model = c("auto", "PCM", "RM"),
level = c("item", "threshold"),
output = c("kable", "dataframe", "ggplot"),
cutoff = 0.5,
conf = 0.95,
sort = FALSE
)
data |
A data.frame or matrix of item responses (non-negative
integers, 0-based). One column per item, one row per person. Person
IDs and grouping variables must not be included – pass the grouping
variable separately via |
dif_var |
Vector of length |
model |
One of |
level |
One of |
output |
One of |
cutoff |
Numeric or |
conf |
Numeric in (0, 1). Confidence level used for the ggplot
error bars. Default |
sort |
Logical. |
The Partial Credit Model (PCM) is fitted by default for polytomous data
and the dichotomous Rasch Model (RM) is fitted when all responses are
0/1; this can be overridden via model.
For the data.frame and kable outputs, locations are reported on the
centred eRm parameterisation returned by eRm::thresholds().
Per-group fits come from eRm::LRtest(..., splitcr = dif_var);
the unsplit fit (All column) is the model fitted to the full
dataset. The Andersen LR statistic, df, and p-value reported as the
lr_test attribute / caption come directly from
LRtest()'s return value.
cell_spec()-style HTML cell colouring used in the legacy
easyRasch package has been dropped in favour of a logical
Flagged column (and bold rendering in the kable output), so the
kable renders correctly in HTML, LaTeX, and pipe/markdown.
A data.frame, a knitr_kable object, or a ggplot
object, depending on output.
The data.frame has one row per item (level = "item") or per
item x threshold (level = "threshold"), with columns
Item (and Threshold at threshold level), one numeric
column per group level, an All column for the unsplit fit,
MaxDiff, Flagged (when cutoff is non-NULL),
and matching SE_* columns.
The Andersen LR test result is attached as
attr(result, "lr_test") on the data.frame, in the kable
footnote, and in the ggplot caption (LR \chi^2, df, p-value).
if (requireNamespace("eRm", quietly = TRUE)) {
set.seed(1)
data("pcmdat2", package = "eRm")
grp <- factor(sample(c("A", "B"), nrow(pcmdat2), replace = TRUE))
# Default: kable of per-group item locations
RMdifLR(pcmdat2, dif_var = grp)
# ggplot panel of item locations with 95% CIs
RMdifLR(pcmdat2, dif_var = grp, output = "ggplot")
# Threshold-level kable, sorted by MaxDiff
RMdifLR(pcmdat2, dif_var = grp, level = "threshold", sort = TRUE)
# Tidy data.frame for downstream use
df <- RMdifLR(pcmdat2, dif_var = grp, output = "dataframe")
attr(df, "lr_test")
df[df$Flagged, ]
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.