Learn R Programming

tirt (version 0.2.0)

binary_irt: Binary (Dichotomous) Item Response Theory Estimation Using Likelihood or Bayesian

Description

Estimates item and person parameters for binary item response models using either Marginal Maximum Likelihood or Joint Maximum Likelihood. Now supports flexible prior distributions for Bayesian estimation (MAP estimation).

Usage

binary_irt(data, model = "2PL", method = "EM", control = list())

Value

A list containing:

  • item_params: A data frame of estimated item parameters (discrimination, difficulty, guessing) and their standard errors.

  • person_params: A data frame of estimated person abilities (theta) and standard errors.

  • model_fit: A data frame containing fit statistics such as Akaike's Information Criterion (AIC), the Bayesian Information Criterion (BIC), and Log-Likelihood.

  • settings: A list of control parameters used in the estimation.

Arguments

data

A N x J data.frame of dichotomous responses (0/1).

model

String. "Rasch", "2PL" (2-Parameter Logistic), or "3PL" (3-Parameter Logistic).

method

String. "EM" (Marginal Maximum Likelihood via Expectation-Maximization) or "MLE" (Joint Maximum Likelihood). However, using Bayesian will override the likelihood estimation.

control

A list of control parameters for the estimation algorithm:

  • max_iter: Maximum number of EM iterations (default = 100).

  • converge_tol: Convergence criterion for parameter change (default = 1e-4).

  • theta_range: Numeric vector of length 2 specifying the integration grid bounds (default = c(-4, 4)).

  • quad_points: Number of quadrature points (default = 21).

  • verbose: Logical; if TRUE, prints progress to console.

  • prior: A list specifying prior distributions or fixed values for item parameters. Default is NULL (no priors). For Rasch: list(b = value) or list(b = function(x) dnorm(x, 0, 1, log=TRUE)). For 2PL: list(a = ..., b = ...). For 3PL: list(a = ..., b = ..., g = ...). Each parameter can be: - A single numeric value (applied to all items) - A numeric vector of length k (item-specific fixed values) - A function returning log-density (applied to all items) - A list of length k with functions or values (item-specific)

Examples

Run this code
  # # Simulate data
  set.seed(123)
  N <- 500; J <- 10
  true_theta <- rnorm(N)
  true_b <- seq(-2, 2, length.out=J)
  true_a <- runif(J, 0.8, 1.2)
  data_mat <- matrix(NA, N, J)
  for(i in 1:N) {
    p <- 1 / (1 + exp(-true_a * (true_theta[i] - true_b)))
    data_mat[i,] <- rbinom(J, 1, p)
  }
  df <- as.data.frame(data_mat)
  names(df) <- paste0("Q", 1:J)

  # # Run Function without prior
  res <- binary_irt(df, model="2PL", method="EM")

# \donttest{
  # # Run Function with prior (function-based)
  res_prior <- binary_irt(df, model="2PL", method="EM",
                          control=list(prior=list(
                            a = function(x) dlnorm(x, 0, 0.5, log=TRUE),
                            b = function(x) dnorm(x, 0, 2, log=TRUE)
                          )))

  # # Run Function with fixed value prior
  res_fixed <- binary_irt(df, model="2PL", method="EM",
                          control=list(prior=list(
                            a = 1,  # Fix all discrimination prior to 1
                            b = function(x) dnorm(x, 0, 2, log=TRUE)
                          )))

  # View Results
  head(res$item_params)
  head(res$person_params)
  print(res$model_fit)
  # --- Example 2: With Package Data ---
  data("ela1", package = "tirt")
  # Subset the first 30 columns (must use the object name 'data_binary')
  df <- ela1[, 1:30]
  # Run Function on package data
  real_res <- binary_irt(df, model="2PL", method="EM")
  head(real_res$item_params)
  # }

Run the code above in your browser using DataLab