# IRT represents a general framework for understanding the relationship between an individual's standing on an underlying factor (e.g., a particular skill, ability, or trait) and their responses to assessment items designed to measure that underlying factor.
# Installing necessary packages
#install.packages("ltm")
#install.packages("expm")
# Loading the respective libraries
library(expm)
## Loading required package: Matrix
##
## Attaching package: 'expm'
## The following object is masked from 'package:Matrix':
##
## expm
library(ltm)
## Loading required package: MASS
## Loading required package: msm
## Loading required package: polycor
# Sample dataset for IRT
data(LSAT)
# Each row is a response from a user and each column is an item (question)
# Answers are either 1 (correct) or 0 (incorrect)
head(LSAT)
## Item 1 Item 2 Item 3 Item 4 Item 5
## 1 0 0 0 0 0
## 2 0 0 0 0 0
## 3 0 0 0 0 0
## 4 0 0 0 0 1
## 5 0 0 0 0 1
## 6 0 0 0 0 1
# Running the IRT model
irm = ltm(LSAT~z1, IRT.param = TRUE)
# Let's analyse the model output now
# negative ones are easier questions - difficulty
# generally higher the discrimination values, the better the question is at differentiating top and poor performers
coef(irm)
## Dffclt Dscrmn
## Item 1 -3.3597341 0.8253715
## Item 2 -1.3696497 0.7229499
## Item 3 -0.2798983 0.8904748
## Item 4 -1.8659189 0.6885502
## Item 5 -3.1235725 0.6574516
## In the below plot, what we have is an item characteristic curve, which gives information about each item: how difficult they are and glimpse at their discrimination level
# So Q's 1 & 5 would be the easiest among these questions, as the ability required to solve this item is fairly less (A good way to measure would be to plot a line from the median probability and the point at which the item curve intersects)
# In terms of discrimination, Item 3 is one with the maximum difficulty. We just need to look at the range of the Y axis for this measure.
plot(irm, type="ICC") # Plots all items at once

# An important offering of the IRT is the scale selection measurement. The Test Information Function gives an indication of where the current item set is able to provide maximum information.
# In the below plot you will notice that the plot peaks around -2 to 0, which indicates that the item set is able to identify learners whose ability is slightly less than average. So these are probably the low scorers.
# However, this may not always be the question for which we are seeking answer to. What if we wanted to identify information about top scorers? So in this case, our item set is not helping us achieve that. Hence, this is a good way to udnerstand whether our item set is helping us achieve our objective or not
plot(irm, type="IIC", items = 0) # Test Information Function. Where am I getting information about the users? Highest information is around -2, which means it has information about fairly weaker students
