# \donttest{
############################################################################
# This example demonstrates how to detect global DIF in polytomous items
# using the RDIF-CR framework implemented in `irtQ::crdif()`.
# Simulated response data are generated from 5 GRM items with 4 score
# categories. DIF is introduced in the 1st and 5th items.
############################################################################
###############################################
# (1) Simulate response data with DIF
###############################################
set.seed(1)
# Generate ability parameters for 1000 examinees in each group
# Reference and focal groups follow N(0, 1.5^2)
theta_ref <- rnorm(1000, 0, 1.5)
theta_foc <- rnorm(1000, 0, 1.5)
# Combine abilities from both groups
theta_all <- c(theta_ref, theta_foc)
# Define item parameters using `irtQ::shape_df()`
# Items 1 and 5 are intentionally modified to exhibit DIF
par_ref <- irtQ::shape_df(
par.prm = list(
a = c(1, 1, 1, 2, 2),
d = list(c(-2, 0, 1),
c(-2, 0, 2),
c(-2, 0, 1),
c(-1, 0, 2),
c(-2, 0, 0.5))
),
cats = 4, model = "GRM"
)
par_foc <- irtQ::shape_df(
par.prm = list(
a = c(2, 1, 1, 2, 0.5),
d = list(c(-0.5, 0, 0.5),
c(-2, 0, 2),
c(-2, 0, 1),
c(-1, 0, 2),
c(-1.5, -1, 0))
),
cats = 4, model = "GRM"
)
# Generate response data
resp_ref <- irtQ::simdat(x = par_ref, theta = theta_ref, D = 1)
resp_foc <- irtQ::simdat(x = par_foc, theta = theta_foc, D = 1)
# Combine response data across groups
data <- rbind(resp_ref, resp_foc)
###############################################
# (2) Estimate item and ability parameters
###############################################
# Estimate GRM item parameters using `irtQ::est_irt()`
fit_mod <- irtQ::est_irt(data = data, D = 1, model = "GRM", cats = 4)
# Extract estimated item parameters
x <- fit_mod$par.est
# Estimate ability scores using ML method
score <- est_score(x = x, data = data, method = "ML")$est.theta
###############################################
# (3) Perform RDIF-CR DIF analysis
###############################################
# Define group membership: 1 = focal group
group <- c(rep(0, 1000), rep(1, 1000))
# (a) DIF detection without purification
dif_nopuri <- crdif(
x = x, data = data, score = score,
group = group, focal.name = 1, D = 1, alpha = 0.05
)
print(dif_nopuri)
# (b) DIF detection with purification using RDIF_{R}-CR
dif_puri_1 <- crdif(
x = x, data = data, score = score,
group = group, focal.name = 1, D = 1, alpha = 0.05,
purify = TRUE, purify.by = "crdifr"
)
print(dif_puri_1)
# (c) DIF detection with purification using RDIF_{S}-CR
dif_puri_2 <- crdif(
x = x, data = data, score = score,
group = group, focal.name = 1, D = 1, alpha = 0.05,
purify = TRUE, purify.by = "crdifs"
)
print(dif_puri_2)
# (d) DIF detection with purification using RDIF_{RS}-CR
dif_puri_3 <- crdif(
x = x, data = data, score = score,
group = group, focal.name = 1, D = 1, alpha = 0.05,
purify = TRUE, purify.by = "crdifrs"
)
print(dif_puri_3)
# }
Run the code above in your browser using DataLab