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, DIF analysis
  • Simulation: Generate response data from IRT models
  • Multiple Groups: Full multigroup analysis with invariance testing
  • Advanced Models: Multidimensional IRT and Bifactor models

Installation

pip install mirt

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)

Differential Item Functioning (DIF)

import numpy as np

# Responses with group membership
groups = np.array([0] * 250 + [1] * 250)  # Two groups

# DIF analysis with likelihood ratio test
dif_results = mirt.dif(responses, groups, model='2PL', method='likelihood_ratio')
print(dif_results)

# Other methods: 'wald', 'lord', 'raju'
dif_wald = mirt.dif(responses, groups, method='wald')

Multiple Group Analysis

from mirt.multigroup import fit_multigroup, compare_invariance

# Fit with different invariance levels
result = fit_multigroup(responses, groups, model='2PL', invariance='configural')

# Compare all invariance levels
results = compare_invariance(responses, groups, model='2PL', verbose=True)
# Returns: {'configural': ..., 'metric': ..., 'scalar': ..., 'strict': ...}

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
  • dif(data, groups, model, method) - Differential Item Functioning analysis

Multigroup Functions

  • fit_multigroup(data, groups, model, invariance) - Fit multigroup IRT model
  • compare_invariance(data, groups, model) - Compare invariance levels

Model Classes

  • TwoParameterLogistic - 2PL model class
  • ThreeParameterLogistic - 3PL model class
  • GradedResponseModel - GRM model class
  • MultidimensionalModel - Multidimensional IRT
  • BifactorModel - Bifactor model
  • 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 Yes
Bifactor Yes Yes
DIF Yes Yes (LR, Wald, Lord, Raju)
Multiple groups Full support Yes (configural, metric, scalar, strict)
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.3.tar.gz (73.7 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.3-py3-none-any.whl (96.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mirt-0.1.3.tar.gz
  • Upload date:
  • Size: 73.7 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.3.tar.gz
Algorithm Hash digest
SHA256 945cf5a48ede3dff71792afab7a1dcfd66d091d658a9a8ca681327df1e6a6c62
MD5 c7f96d95a8e8daca69da464c0be3286b
BLAKE2b-256 c06265bbf5eef03805589e823a0414d5c143dbc0fb4ebc24eeefffd5a8c688da

See more details on using hashes here.

Provenance

The following attestation bundles were made for mirt-0.1.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: mirt-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 96.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b28de97260b0c5d374a1abaf45e06c8279bf7e073cedb256e5940972556c98c3
MD5 3f4bedaccad17328a90c5e632d76242c
BLAKE2b-256 632edb5384e2dce7fded5652f928b248c791ee3f227abdb76c0193c5ead62d68

See more details on using hashes here.

Provenance

The following attestation bundles were made for mirt-0.1.3-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