Attach per-response predicted probabilities from a fitted unidimensional,
dichotomous mirt model to long-format IRW data. This is the piece
needed to compare models out of sample with irw_imv.
Arguments
- model
A fitted unidimensional mirt model with dichotomous items.
- resp
The wide response frame used to fit
model, including itsidcolumn, as returned byirw_long2resp. The item columns (everything butid) are what was passed tomirt::mirt().- newdata
(Optional) A long-format data frame with columns
idanditemgiving the responses to predict. Defaults to everyid/itempair inresp.- ability
Scoring method passed to
mirt::fscores(). Default"EAP".
Details
Person abilities are taken from the fit itself with
mirt::fscores(), so row i of the scored matrix is person
resp$id[i]. Passing the wide frame that produced the fit is what
lets the function recover that mapping; supplying ids in a different order
than the rows given to mirt::mirt() would silently mispair people
with abilities.
Probabilities come from mirt::probtrace(), so any dichotomous
mirt item type (Rasch, 2PL, 3PL, 4PL, ...) is handled without
assuming a particular parameterisation.
newdata may contain any id/item pairs, including ones
held out of the fit, as long as each person appears in resp and each
item was estimated. That is the cross-validation case: fit on part of the
data, predict the rest.
Requires the mirt package.
Examples
if (FALSE) { # \dontrun{
df <- irw_simdata(n_id = 200, n_item = 10, model = "2PL", seed = 1)
wide <- irw_long2resp(df)
fit <- mirt::mirt(wide[setdiff(names(wide), "id")], 1, "Rasch")
preds <- irw_predict(fit, wide)
} # }