# Setup for Example ---------------------------------------------------------
# Settings
set.seed(0) # seed for reproducibility
N <- 50 # number of persons
n <- 40 # number of items
# Randomly select 10% speeded examinees
cv <- sample(1:N, size = N * 0.10)
# Assign change point corresponding to 10% speeded items
cp <- n * 0.90
ci <- (cp + 1):n
# Create vector of indicators (1 = speeded, 0 = non-speeded)
ind <- ifelse(1:N %in% cv, 1, 0)
# Example: Item Scores and Response Times -----------------------------------
# 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 uncontaminated data
dat <- sim(psi, xi)
x <- dat$x
y <- dat$y
# Modify contaminated data by changing the item scores and response times
x[cv, ci] <- rbinom(length(cv) * length(ci), size = 1, prob = 0.25)
y[cv, ci] <- runif(length(cv) * length(ci), min = log(1), max = log(10))
# Detect change point
out <- detect_cp(
method = c("L_S_MAX1", "L_T_MIN1"),
cpi = c(1, n - 1),
psi = psi,
x = x,
y = y
)
Run the code above in your browser using DataLab