This is an RMarkdown document displaying R code for a multi-faceted plot based on 2PL item characteristics. The basic structure of the plot is to graph items by their a and b parameters as y and x axes, respectively.
In addition to this, three cut-scores are represented by three different colored vertical lines.
Lastly, item information for each item is calculated for each cut-score and summarized in a color-based visual in the plot. Specifically, plotted points of items will match the color of the cut-score they provide the most information towards. Items that provide minimal information at each cut-score will be black.
Item parameters and cut-scores are randomly generated for 30 items for 3 different tests. B parameters and cut-scores are simulated so as to come from different distributions for each specific test.
This plot was created with the intention of providing a unique dynamic visual of 2PL item characteristics.
The first block of code accomplished the following:
library(ggplot2)
library(plyr)
library(dplyr)
Test <- c(rep(1, 30), rep(2, 30), rep(3, 30))
Test <- data.frame(Test)
Cut_1 <- c(rep(rnorm(1,-1,.2),30), rep(rnorm(1,-1,.2),30), rep(rnorm(1,-1,.2),30))
Cut_2 <- c(rep(rnorm(1,0,.2),30), rep(rnorm(1,0,.2),30), rep(rnorm(1,0,.2),30))
Cut_3 <- c(rep(rnorm(1,1,.2),30), rep(rnorm(1,1,.2),30), rep(rnorm(1,1,.2),30))
a <- rnorm(90, 1.25, .33)
b <- c(rnorm(30, -.25, .9), rnorm(30, 0, 1), rnorm(30, .25, .9))
a <- as.data.frame(a)
b <- as.data.frame(b)
Item_set <- cbind(Test, a, b, Cut_1, Cut_2, Cut_3)
The following section of code will calculate item information for each item at each of the three corresponding test cut-scores. The items are then flagged in the following manner:
The flagged value will be used to color the points on the plot.
Item_set <- Item_set %>% mutate(Inf_1 = (a^2)*(1/(1 + exp(-a*(Cut_1-b))))*(exp(-a*(Cut_1-b))/(1 + exp(-a*(Cut_1-b)))))
Item_set <- Item_set %>% mutate(Inf_2 = (a^2)*(1/(1 + exp(-a*(Cut_2-b))))*(exp(-a*(Cut_2-b))/(1 + exp(-a*(Cut_2-b)))))
Item_set <- Item_set %>% mutate(Inf_3 = (a^2)*(1/(1 + exp(-a*(Cut_3-b))))*(exp(-a*(Cut_3-b))/(1 + exp(-a*(Cut_3-b)))))
Item_set <- Item_set %>% rowwise() %>% mutate(max_inf = max(Inf_1, Inf_2, Inf_3))
Item_set <- Item_set %>% mutate(flag = ifelse(max_inf < .1, 1, ifelse(max_inf == Inf_1, 2, ifelse(max_inf == Inf_2, 3, 4))))
Item_set <- as.data.frame(Item_set)
Item_set$flag <- as.factor(Item_set$flag)
The plots are then created for each test. The plot will allow a psychometrician to inspect several aspects of item-level characteristics for a given test:
colorset = c("1"="black","2"="indianred","3"="blue","4"="green3")
twodim_plot <- Item_set %>% ggplot(aes(x=b,y=a)) + geom_point(aes(color = flag)) + geom_vline(aes(xintercept = Cut_1), linetype ="dashed",color="indianred") + geom_vline(aes(xintercept = Cut_2), linetype ="dashed",color="blue") + geom_vline(aes(xintercept = Cut_3), linetype ="dashed",color="green3") + scale_color_manual(values = colorset) + ylim(0,3) + facet_wrap(~Test)
twodim_plot