5.5 Exercises#
Polytomous IRT#
This week, we will do some exercises on Item Response Theory with polytomous data.
1️⃣ RSM Model Comparison#
Instructions:
Fit a new RSM model (
fitrsm3
) using the originalCEAQ
data (including items 10 and 15).Compare the item fit statistics (
ifit3
) offitrsm3
to those offitrsm2
(the model without items 10 and 15). Are there any noticeable differences?Conduct Andersen’s LR-test on
fitrsm3
using thegradevec
splitting criterion. Does the model fit improve or worsen compared tofitrsm2
?
# Import packages
# Fit the model
ro.r(...)
# Get person parameters
ppar3 = ro.r(...)
# Get item fit
ifit03 = ro.r(...)
print(ifit03)
ro.r(...)
ro.r(...)
ro.r(...)
LRtest2 = ro.r(...)
print(LRtest2)
2️⃣ Exercise PCM Item Difficulty Comparison#
Instructions:
Extract the item location parameters (difficulty) from the
fitpcm
model.Identify the two items with the highest and lowest difficulty parameters.
Plot the item characteristic curves (
ICCs
) for these two items on the same graph.Interpret the plot. How do the
ICCs
reflect the difference in difficulty between the two items? Discuss which regions of the latent trait the items target and how their curves differ in steepness and peak probability
# Import packages
# Load the data in R
ro.r(...)
# Convert data to a Pandas df
ASTI = pandas2ri.rpy2py(ro.globalenv['ASTI'])
# Extract PG items
PGitems = ASTI.iloc[:, [10, 13, 14, 16, 17, 22]]
# Inspect the dataset
print(...)
# Put data back into R
ro.globalenv...
ro.r(...)
thresh = ro.r("thresholds(fitpcm)")
print(thresh) # Item ASTI23 & ASTI14 (highest & lowest threshold 2)
# Plot ICCs in R
%%R
plotICC(...)
%%R
plotICC(...)
3️⃣ GPCM Discrimination Exploration#
Instructions:
Extract the item discrimination parameters (
disc
) from thestgpcm
model.Identify the item with the highest discrimination parameter.
Identify the item with the worst discrimination paramenter.
Plot the two item and compare them.
# Import packages
# Load the data in R
ro.r(...)
# Convert data to a Pandas df
ASTI = pandas2ri.rpy2py(ro.globalenv['ASTI'])
# Extract ST items
STitems = ASTI.iloc[:, [1,3,6,12,15,23,24]]
# Inspect the dataset
print(...)
# Put data back into R
ro.globalenv...
# Fit the model
ro.r(...)
# Extract discrimination parameters
coeffs = ro.r('stgpcm$coef')
print(coeffs)
# If we don't want to select the maximum and minimum by hand:
# Convert R list to Python dictionary
coeffs_dict = {key: list(value) for key, value in zip(coeffs.names, coeffs)}
# Extract last value of each discrimination parameter
disc_para = pd.DataFrame({'disc': [values[-1] for values in coeffs_dict.values()]})
# Display the final DataFrame
print(disc_para)
# Find max and min discrimination values
max_disc = disc_para.loc...
min_disc = disc_para.loc...
# Print results
print("Max Discrimination Parameter:")
print(max_disc)
print("\nMin Discrimination Parameter:")
print(min_disc)
# Plot ICCs in R
%%R
plot(..., main = "ICC GPCM", items =...) # maximum dscm parameter. Watchout: R starts counting at 1
%%R
plot(..., main = "ICC GPCM", items = ...) # minimum dscm parameter. Watchout: R starts counting at 1