5.5 Exercises#

Polytomous IRT#

This week, we will do some exercises on Item Response Theory with polytomous data.

1️⃣ RSM Model Comparison#

Instructions:

  1. Fit a new RSM model (fitrsm3) using the original CEAQ data (including items 10 and 15).

  2. Compare the item fit statistics (ifit3) of fitrsm3 to those of fitrsm2 (the model without items 10 and 15). Are there any noticeable differences?

  3. Conduct Andersen’s LR-test on fitrsm3 using the gradevec splitting criterion. Does the model fit improve or worsen compared to fitrsm2?

# 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:

  1. Extract the item location parameters (difficulty) from the fitpcm model.

  2. Identify the two items with the highest and lowest difficulty parameters.

  3. Plot the item characteristic curves (ICCs) for these two items on the same graph.

  4. 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:

  1. Extract the item discrimination parameters (disc) from the stgpcm model.

  2. Identify the item with the highest discrimination parameter.

  3. Identify the item with the worst discrimination paramenter.

  4. 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