How to write the item name in a function (instead of the item's numeric value) ?

Hello to you all,

Just starting using R so if appropriate "go slow" with your answer.

Using mirt package, trying to generate a plot with:

itemplot(polymodel, item = 3, type = "trace")

Works great but the title of the graph is: "Trace lines for item 3"
I would like to have the title show the name of the item (variable) like this: "Trace lines for item v.5.1.1.a"

Help for mirt gives : "item a single numeric value, or the item name, indicating which item to plot"

I tried different ways to type the item name:

itemplot(polymodel, item = "var13$v.5.1.1.a", type = "trace")
Error in x@ParObjects$pars[[item]] : attempt to select less than one element in get1index

itemplot(polymodel, item = var13$v.5.1.1.a, type = "trace")
Error in x@ParObjects$pars[[item]] : recursive indexing failed at level 2

itemplot(polymodel, item = v.5.1.1.a, type = "trace")
Error in itemplot(polymodel, item = v.5.1.1.a, type = "trace") : object 'v.5.1.1.a' not found

I would really appreciate any help here.

Regards,
AlexDP

Welcome to R!

It looks like itemplot relies on lattice (you can see that from the fact that itemplot can pass elements to lattice). Hence, it is likely that you can simply use the appropriate lattice command to generate a title. Try something like

itemplot(polymodel, item = 3, type = "trace", main="Trace lines for item v.5.1.1.a")

If you come from Stata, labels do not play the same role in R, so you often will end up tweaking graphs.

For more information on lattice see http://lattice.r-forge.r-project.org

Thank you. Your solution works fine and I will use it.

Since I have 13 items to plot individually, I was hoping to find a solution that would work within a for loop like:

varNames <- names(var13)
for (it in varNames) {
itemplot(polymodel, item = it, type = trace)
}

But this is not working.

You are welcome. For the second question, you need to provide a bit more information about your data. Even better, try to set up a reprex using one of the built-in data sets such as mtcars. See below for information about how to write a good reprex.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.