plotting item characteristic curves for all items in the data

4,649 views
Skip to first unread message

Irshad Mujawar

unread,
Aug 27, 2014, 2:45:17 AM8/27/14
to mirt-p...@googlegroups.com
Hello everyone,

While using the fucntion itemplot, I realized that you can draw only one characteristic curve at a time corresponding to a single item which you have specified.

In the "ltm" package there is a function called plot.ltm ;   if you specify that items=NULL It will plot item characteristic curves for all the items in the data.

Does anyone know if there is any facility in itemplot  function to do the same.?

cheers,
Irshad

Jordache Ramjith

unread,
Aug 27, 2014, 2:50:05 AM8/27/14
to Irshad Mujawar, mirt-package
Try this

plot(model, type = 'trace', auto.key = FALSE)


--
You received this message because you are subscribed to the Google Groups "mirt-package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mirt-package...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Irshad Mujawar

unread,
Aug 27, 2014, 3:13:13 AM8/27/14
to mirt-p...@googlegroups.com, irshadmuj...@gmail.com

Thank you for the reply Jordache.
It worked for me.

This could be little greedy but if I want suppose a specific number of characteristic curves; suppose more than 1 but not all then?

And can we not have all the curves overlapping on each other.

like this:

Phil Chalmers

unread,
Aug 27, 2014, 8:39:33 AM8/27/14
to Irshad Mujawar, mirt-package
Try the following code, and see the plot-method help file in mirt for other options. The last line plots the first 3 items all on the same plot.

```
library(mirt)
dat <- expand.table(LSAT7)
mod <- mirt(dat, 1)
plot(mod, type = 'trace')
plot(mod, type = 'trace', which.items = 1:3, facet_items=FALSE)
```

This also brings up another interesting point that many aren't aware of when making custom graphics. One of the main reasons I opted for the lattice package instead of using base R graphics (which looks to be the image attached here) was that the data is actually silently returned in the package whenever a plot is drawn. So, if you don't like the defaults, you can always extract the data and actually build your own, potentially with an entirely different plotting system. For example,

```
plt <- plot(mod, type = 'trace', facet_items=FALSE) #store the object
print(plt) #plot the object
str(plt) #find the data
plt$panel.args
pltdata <- data.frame(lapply(plt$panel.args, function(x) do.call(cbind, x))[[1]])
pltdata$item <- rep(colnames(dat), each = 50)
head(pltdata)

library(ggplot2)
ggplot(pltdata, aes(x, y, colour=item)) + geom_line() + ggtitle('ggplot2 Tracelines') +
    xlab(expression(theta)) + ylab(expression(P(theta)))
```

Phil

Irshad Mujawar

unread,
Aug 28, 2014, 1:52:08 AM8/28/14
to mirt-p...@googlegroups.com, irshadmuj...@gmail.com
Thanks a lot Phil. :)

That code worked for me plus the extra information you gave is pretty useful.


Irshad

Dimitrios Zacharatos

unread,
Jul 6, 2017, 7:08:36 AM7/6/17
to mirt-package, irshadmuj...@gmail.com
This is very nice. I am mainly using ggplot and plotly, and it is good to know that. I tried to write something more general and I do not know to what extent it may be usefull.


#' Return data for irt model plots
#' This function can handle mainly one dimensional models
#' @param model Mirt package object of irt model
#' @param type type of plot to view; can be 'info' to show the test information function, 'rxx' for the reliability function, 'infocontour' for the test information contours, 
#' 'SE' for the test standard error function, 'trace', 'infotrace', and 'itemscore' for all item probability, information, and scoring or trace lines, 
#' 'infoSE' for a combined test information and standard error plot, and 'score' and 'scorecontour' for the expected total score surface and contour plots. 
#' If empiricalhist = TRUE was used in estimation then the type 'empiricalhist' also will be available to generate the empirical histogram plot
#' @keywords IRT
#' @export
#' @examples
#' set.seed(12345)
#' cormatrix<-data.frame(psych::sim.rasch(nvar=15,n=5000,low=-4,high=4,d=NULL,a=1,mu=0,sd=1)$items)
#' onefactormodel<-mirt::mirt(cormatrix[,1:5],1,empiricalhist=TRUE,technical=list(NCYCLES=1000000))
#' twofactormodel<-mirt::mirt(cormatrix[,1:10],2,technical=list(NCYCLES=1000000))
#' threefactormodel<-mirt::mirt(cormatrix,3,technical=list(NCYCLES=1000000))
#' data_irt(onefactormodel,"info")
#' data_irt(twofactormodel,"info")
#' data_irt(threefactormodel,"info")
#' plot_irt(onefactormodel,"info",title="Test Information",xlab=expression(theta),ylab=expression(l(theta)))
data_irt<-function(model,type) {
  require(mirt)
  pt<-plot(model,type=type,facet_items=FALSE)
  result<-data.frame(Type=string_aes(type),pt$panel.args[[1]])
  item<-rep("",nrow(result))
  if(type=="trace"||type=="infotrace"||type=="itemscore"){
    result$item<-factor(rep(as.character(colnames(model@Data$data)),each=50),levels=colnames(model@Data$data))
  }
  return(result)
}


However models with 2 and 3 θ are a bit more difficult to work with.

Dimitrios Zacharatos

unread,
Jul 6, 2017, 7:09:38 AM7/6/17
to mirt-package, irshadmuj...@gmail.com


On Thursday, July 6, 2017 at 2:08:36 PM UTC+3, Dimitrios Zacharatos wrote:
This is very nice. I am mainly using ggplot and plotly, and it is good to know that I can get data to use with ggplot. I tried to write something more general and I do not know to what extent it may be usefull.

Aiden loe

unread,
Nov 16, 2017, 6:41:07 PM11/16/17
to mirt-p...@googlegroups.com

Thanks for the information here. 
Just a quick question to anyone reading this. 
This all works really well, but it becomes quite hard to identify items by difference in colours once you have say about 20 items. The colours repeat itself, even when provided with a legend. 
Is there quick way in the plot() which allows us to reorganise the ICCs such that it is ordered in terms of difficulty levels? This means that the legend will order itself by item difficulty rather than item 1, item 2 ....

Aiden

Phil Chalmers

unread,
Nov 16, 2017, 8:26:21 PM11/16/17
to Aiden loe, mirt-package
Likely not, at least not without munging through the inner workings of the lattice package. It may be easier just to save the associated information via mirt's secondary functions (e.g., probtrace(), expected.score(), etc), and build you graphics manually with something like, say, ggplot2. 

Phil

On Thu, Nov 16, 2017 at 6:41 PM, Aiden loe <aide...@gmail.com> wrote:

Thanks for the information here. 
Just a quick question to anyone reading this. 
This all works really well, but it becomes quite hard to identify items by difference in colours once you have say about 20 items. The colours repeat itself, even when provided with a legend. 
Is there quick way in the plot() which allows us to reorganise the ICCs such that it is ordered in terms of difficulty levels? 

Aiden

--
You received this message because you are subscribed to the Google Groups "mirt-package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mirt-package+unsubscribe@googlegroups.com.

Aiden loe

unread,
Nov 17, 2017, 10:59:19 AM11/17/17
to mirt-p...@googlegroups.com

Thanks Phil. I asked for help on stackoverflow. 

I thought this might be be useful for others to know as well. 

library(mirt)
dat <- expand.table(LSAT7)
mod <- mirt(dat, 1)

plt <- plot(mod, type = 'trace', facet_items=FALSE) #store the object

print(plt) #plot the object
str(plt) #find the data
plt$panel.args
pltdata <- data.frame(lapply(plt$panel.args, function(x) do.call(cbind, x))[[1]])
pltdata$item <- rep(colnames(dat), each = 50)


pltdata$item<-as.factor(pltdata$item)
library(dplyr)
aux<-pltdata %>%
  group_by(item) %>%
  slice(which.min(abs(y-0.5)))

aux<-aux[order(aux$x),]
ord<-as.integer(aux$item)
pltdata$item = factor(pltdata$item,levels(pltdata$item)[ord])

library(ggplot2)
ggplot(pltdata, aes(x, y, colour = item)) + 
  geom_line() + 
  ggtitle('ggplot2 Tracelines') + 
  xlab(expression(theta)) + 
  ylab(expression(P(theta))) + 
  geom_hline(aes(yintercept = 0.5))

Aiden loe

unread,
Nov 24, 2017, 11:08:24 AM11/24/17
to mirt-p...@googlegroups.com
Hi Phil, 

Is there a function in the package that plots the operating characteristics curve for each polytomous item? 

Aiden


Phil Chalmers

unread,
Nov 25, 2017, 7:18:21 PM11/25/17
to Aiden loe, mirt-package
Do you mean like the following?

model <- mirt(Science, 1)
plot(model, type = 'trace')
plot(model, type = 'itemscore')


Phil

On Fri, Nov 24, 2017 at 11:08 AM, Aiden loe <aide...@gmail.com> wrote:
Hi Phil, 

Is there anyway to plot the operating characteristics curve for each polytomous item? 

Aiden

--

Aiden

unread,
Nov 25, 2017, 7:21:55 PM11/25/17
to Phil Chalmers, mirt-package
Thanks for responding Phil. 

Not really. I think it is called the cumulative item response curve. Sorry, to many different curve names to remember. 




Aiden

Phil Chalmers

unread,
Nov 25, 2017, 7:24:18 PM11/25/17
to Aiden, mirt-package
I understand. No, you can't build these directly. You'd need to recreate the response curves from the probability functions directly in order to do this. 

Phil
Message has been deleted

Phil Chalmers

unread,
Mar 16, 2019, 1:29:48 PM3/16/19
to dbro...@gmail.com, mirt-package
I don't see any issue with this code. Does it not give the plots you were expecting or something?

On Fri, Mar 15, 2019, 9:34 AM <dbro...@gmail.com> wrote:
Is it valid to use the information in $panel.args of the itemplot function to do this? For example, if irtS13PL is my model, the following produces what looks okay. 


m1 <- itemplot(irtS13PL,1)$panel.args[[1]]
iccs <- matrix(ncol=11,nrow=length(m1$x))
iccs[,1] <- m1$x
for (i in 1:10)
 iccs[,1+i] <- itemplot(irtS13PL,i)$panel.args[[1]]$y
plot(range(iccs[,1]),range(iccs[,2:11]),col="white")
for (i in 2:11)
  lines(iccs[,1],iccs[,i])

Phil

Aiden






Phil

To unsubscribe from this group and stop receiving emails from it, send an email to mirt-package...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mirt-package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mirt-package...@googlegroups.com.

dbro...@gmail.com

unread,
Mar 16, 2019, 4:10:08 PM3/16/19
to mirt-package
I thought it should be fine, and it looked right, just wanted to make sure. Thanks for your great package!  Dan
Reply all
Reply to author
Forward
0 new messages