Skip to main content

Multidimensional Item Response Theory for Python

Project description

mirt

Multidimensional Item Response Theory for Python

A comprehensive Python implementation of Item Response Theory (IRT) models, inspired by R's mirt package.

Features

  • Dichotomous Models: 1PL (Rasch), 2PL, 3PL, 4PL
  • Polytomous Models: GRM, GPCM, PCM, NRM
  • Estimation: EM algorithm with Gauss-Hermite quadrature
  • Scoring: EAP, MAP, ML methods for person ability estimation
  • Diagnostics: Item fit, person fit statistics
  • Simulation: Generate response data from IRT models
  • Multiple Groups: Basic multiple group analysis

Installation

pip install -e .

Or for development:

pip install -e ".[dev]"

Quick Start

import mirt
import numpy as np

# Simulate response data
responses = mirt.simdata(model='2PL', n_persons=500, n_items=20, seed=42)

# Fit a 2PL model
result = mirt.fit_mirt(responses, model='2PL')

# View results
print(result.summary())

# Get item parameters
params = result.coef()
print(params)

# Score respondents
scores = mirt.fscores(result, responses, method='EAP')
print(scores.to_dataframe().head())

Supported Models

Dichotomous (Binary) Models

Model Description Parameters
1PL/Rasch One-parameter logistic difficulty (b)
2PL Two-parameter logistic discrimination (a), difficulty (b)
3PL Three-parameter logistic a, b, guessing (c)
4PL Four-parameter logistic a, b, c, upper asymptote (d)

Polytomous (Ordinal) Models

Model Description Use Case
GRM Graded Response Model Likert scales
GPCM Generalized Partial Credit Partial credit items
PCM Partial Credit Model Rasch for polytomous
NRM Nominal Response Model Unordered categories

Examples

Fitting Different Models

# 1PL (Rasch) model
result_1pl = mirt.fit_mirt(responses, model='1PL')

# 3PL model with guessing
result_3pl = mirt.fit_mirt(responses, model='3PL')

# Graded Response Model for Likert data
likert_data = mirt.simdata(model='GRM', n_categories=5)
result_grm = mirt.fit_mirt(likert_data, model='GRM', n_categories=5)

Person Scoring

# Different scoring methods
eap_scores = mirt.fscores(result, responses, method='EAP')
map_scores = mirt.fscores(result, responses, method='MAP')
ml_scores = mirt.fscores(result, responses, method='ML')

# Access theta values
print(eap_scores.theta)
print(eap_scores.standard_error)

Item Analysis

# Item fit statistics
item_fit = mirt.itemfit(result, responses)
print(item_fit)

# Person fit statistics
person_fit = mirt.personfit(result, responses)
print(person_fit)

Data Simulation

# Simulate with specific parameters
a = np.random.lognormal(0, 0.3, size=20)
b = np.random.normal(0, 1, size=20)

responses = mirt.simdata(
    model='2PL',
    discrimination=a,
    difficulty=b,
    n_persons=1000,
    seed=42
)

API Reference

Main Functions

  • fit_mirt(data, model, ...) - Fit an IRT model
  • fscores(model, responses, method) - Compute person abilities
  • simdata(model, n_persons, n_items, ...) - Simulate response data
  • itemfit(result, responses) - Item fit statistics
  • personfit(result, responses) - Person fit statistics

Model Classes

  • TwoParameterLogistic - 2PL model class
  • ThreeParameterLogistic - 3PL model class
  • GradedResponseModel - GRM model class
  • etc.

Comparison with R mirt

Feature R mirt Python mirt
Dichotomous models 1PL-4PL 1PL-4PL
Polytomous models GRM, GPCM, PCM, NRM GRM, GPCM, PCM, NRM
Estimation EM, MHRM EM
Multidimensional Full support Basic 2PL
Bifactor Yes Planned
DIF Yes Basic
GUI Shiny app -

Dependencies

  • numpy >= 1.21
  • scipy >= 1.7
  • pandas >= 1.3

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Type checking
mypy src/mirt

# Formatting
black src tests
ruff check src tests

License

MIT License - see LICENSE

References

  • Chalmers, R. P. (2012). mirt: A Multidimensional Item Response Theory Package for the R Environment. Journal of Statistical Software, 48(6), 1-29.
  • Bock, R. D., & Aitkin, M. (1981). Marginal maximum likelihood estimation of item parameters: Application of an EM algorithm. Psychometrika, 46(4), 443-459.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mirt-0.1.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mirt-0.1.0-py3-none-any.whl (36.6 kB view details)

Uploaded Python 3

File details

Details for the file mirt-0.1.0.tar.gz.

File metadata

  • Download URL: mirt-0.1.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mirt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 537aaba9d37038b9c46d5975fc0c1c75997f693555003f544a939091d9d13d81
MD5 9a3844c7768d685107144a215b10d258
BLAKE2b-256 b0ad9c3cfae25fd32cfee2a2c5f49ec73e2e7425905c6f0d88f4b9c455d80f35

See more details on using hashes here.

Provenance

The following attestation bundles were made for mirt-0.1.0.tar.gz:

Publisher: publish.yml on Cameron-Lyons/mirt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mirt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mirt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mirt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 482d9358e6c90bece57c9f9793d019fa549acadfb8f953f2527c92275f3ffede
MD5 e44ab62ffe09f158b1a678b84c052cec
BLAKE2b-256 a1142fcdb08616726b54ff87d0c7499d283d2ed3b97747ec0fde24021d3ee488

See more details on using hashes here.

Provenance

The following attestation bundles were made for mirt-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Cameron-Lyons/mirt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page