## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 4.5 ) ## ----load--------------------------------------------------------------------- library(irtsim) library(ggplot2) ## ----design-byhand------------------------------------------------------------ design_byhand <- irt_design( model = "2PL", n_items = 10, item_params = list( a = c(0.8, 1.0, 1.1, 1.2, 1.3, 0.9, 1.4, 1.0, 1.2, 1.1), b = seq(-2, 2, length.out = 10) ) ) design_byhand ## ----design-helper------------------------------------------------------------ set.seed(2026) ip <- irt_params_2pl( n_items = 10, a_mean = 0, a_sd = 0.25, # log-normal: median a = 1 b_mean = 0, b_sd = 1, b_range = c(-2, 2) ) design_helper <- irt_design( model = "2PL", n_items = 10, item_params = ip ) ## ----design-priorfit---------------------------------------------------------- prior_data <- mirt::expand.table(mirt::LSAT7) prior_fit <- mirt::mirt(prior_data, 1, "2PL", verbose = FALSE) co <- mirt::coef(prior_fit, IRTpars = TRUE, simplify = TRUE)$items design_prior <- irt_design( model = "2PL", n_items = nrow(co), item_params = list(a = co[, "a"], b = co[, "b"]) ) co ## ----study-------------------------------------------------------------------- study <- irt_study( design = design_helper, sample_sizes = c(100, 250, 500, 1000) ) study ## ----simulate, cache = FALSE-------------------------------------------------- results <- irt_simulate( study = study, iterations = 50, seed = 1, progress = FALSE ) ## ----summary------------------------------------------------------------------ res_summary <- summary(results, criterion = c("mse", "bias", "rmse", "coverage")) head(res_summary$item_summary) ## ----plot, fig.alt = "MSE of difficulty estimates by sample size, one line per item"---- plot(res_summary, criterion = "mse", param = "b", threshold = 0.05) ## ----recommend---------------------------------------------------------------- n_rec <- recommended_n(res_summary, criterion = "mse", threshold = 0.05, param = "b") n_rec ## ----recommend-details-------------------------------------------------------- attr(n_rec, "details")