ip <- generate_ip(model = "3PL", n = 50)
true_theta <- rnorm(10000)
resp <- sim_resp(ip = ip, theta = true_theta, prop_missing = 0.3)
kern_output <- ks(resp)
# Plot ICC
i <- 12 # select an item to plot
x <- kern_output$icc[, i]
se <- kern_output$se[, i]
p <- prob(ip = ip[i], theta = kern_output$points)
p <- sapply(p, `[`, 2) # get the probability of correct responses
graph_data <- data.frame(
theta = kern_output$points,
icc = x,
ci_low = sapply(x - qnorm(.975) * se, function(x) max(x, 0)),
ci_high = sapply(x + qnorm(.975) * se, function(x) min(x, 1)),
p = p)
if (FALSE) {
p <- ggplot(data = graph_data) +
geom_line(aes(x = theta, y = icc), color = "blue", alpha = .7, size = 1) +
geom_line(aes(x = theta, y = p), color = "red", size = 1, alpha = .7) +
geom_ribbon(data = graph_data,
aes(x = theta, ymin = ci_low, ymax = ci_high),
alpha = .25) +
ylim(0, 1) +
labs(x = "Theta", y = "Probability",
title = "Item Characteristic Curve") +
theme_bw()
p
}
Run the code above in your browser using DataLab