Skip to contents

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.

Usage

irw_predict(model, resp, newdata = NULL, ability = "EAP")

Arguments

model

A fitted unidimensional mirt model with dichotomous items.

resp

The wide response frame used to fit model, including its id column, as returned by irw_long2resp. The item columns (everything but id) are what was passed to mirt::mirt().

newdata

(Optional) A long-format data frame with columns id and item giving the responses to predict. Defaults to every id/item pair in resp.

ability

Scoring method passed to mirt::fscores(). Default "EAP".

Value

newdata with an added numeric column p, the predicted probability of a response of 1.

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)
} # }