# Setup for Examples 1 to 3 -------------------------------------------------
# Settings
set.seed(0) # seed for reproducibility
N <- 5000 # number of persons
n <- 40 # number of items
# Randomly select 20% unmotivated persons
cv <- sample(1:N, size = N * 0.20)
# Create vector of indicators (1 = unmotivated, 0 = motivated)
ind <- ifelse(1:N %in% cv, 1, 0)
# Generate person parameters for the 3PL model and lognormal model
xi <- MASS::mvrnorm(
N,
mu = c(theta = 0.00, tau = 0.00),
Sigma = matrix(c(1.00, 0.25, 0.25, 0.25), ncol = 2)
)
# Generate item parameters for the 3PL model and lognormal model
psi <- cbind(
a = rlnorm(n, meanlog = 0.00, sdlog = 0.25),
b = NA,
c = runif(n, min = 0.05, max = 0.30),
alpha = runif(n, min = 1.50, max = 2.50),
beta = NA
)
# Generate positively correlated difficulty and time intensity parameters
psi[, c("b", "beta")] <- MASS::mvrnorm(
n,
mu = c(b = 0.00, beta = 3.50),
Sigma = matrix(c(1.00, 0.20, 0.20, 0.15), ncol = 2)
)
# Simulate item scores and response times
dat <- sim(psi, xi)
x <- dat$x
t <- exp(dat$y)
# Modify contaminated data by guessing on 20% of the items
for (v in cv) {
ci <- sample(1:n, size = n * 0.20)
x[v, ci] <- rbinom(length(ci), size = 1, prob = 0.25)
t[v, ci] <- runif(length(ci), min = 1, max = 10)
}
# Example 1: Visual Inspection Methods --------------------------------------
# Detect rapid guessing using the visual inspection method
out <- detect_rg(
method = "VI",
t = t,
outlier = 90
)
# Detect rapid guessing using the visual inspection with proportion correct
# method
out <- detect_rg(
method = "VITP",
t = t,
x = x,
outlier = 90
)
# Example 2: Threshold Methods ----------------------------------------------
# Detect rapid guessing using the custom threshold method with a common
# three-second threshold
out <- detect_rg(
method = "CT",
t = t,
thr = 3
)
# Detect rapid guessing using the custom threshold method with 10% of the
# median item response time
out <- detect_rg(
method = "CT",
t = t,
thr = apply(t, 2, function(i) 0.10 * median(i))
)
# Detect rapid guessing using the normative threshold method with 10% of the
# mean item response time
out <- detect_rg(
method = "NT",
t = t,
nt = 10
)
# Detect rapid guessing using the normative threshold method with 5 to 35% of
# the mean item response time
out <- detect_rg(
method = "NT",
t = t,
nt = seq(5, 35, by = 5)
)
# Example 3: Visual Inspection and Threshold Methods ------------------------
# Detect rapid guessing using the cumulative proportion correct method
out <- detect_rg(
method = "CUMP",
t = t,
x = x,
outlier = 90
)
Run the code above in your browser using DataLab