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 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)
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 modelfscores(model, responses, method)- Compute person abilitiessimdata(model, n_persons, n_items, ...)- Simulate response dataitemfit(result, responses)- Item fit statisticspersonfit(result, responses)- Person fit statistics
Model Classes
TwoParameterLogistic- 2PL model classThreeParameterLogistic- 3PL model classGradedResponseModel- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mirt-0.1.1.tar.gz.
File metadata
- Download URL: mirt-0.1.1.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf0ff0b889a7f60dcc954bde9d36a61fbefe0d56d7b5bc1be9fd09c30a1c54b7
|
|
| MD5 |
4d07336a3a04cd974816e264de1621cb
|
|
| BLAKE2b-256 |
8549752ea585204f544770965b5b1a84fb842843e40b5d520fbc771b80d4e336
|
Provenance
The following attestation bundles were made for mirt-0.1.1.tar.gz:
Publisher:
publish.yml on Cameron-Lyons/mirt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mirt-0.1.1.tar.gz -
Subject digest:
cf0ff0b889a7f60dcc954bde9d36a61fbefe0d56d7b5bc1be9fd09c30a1c54b7 - Sigstore transparency entry: 790636501
- Sigstore integration time:
-
Permalink:
Cameron-Lyons/mirt@cfb1debf33c475fbd4b8470fcf3b44e7c86b4e02 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Cameron-Lyons
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cfb1debf33c475fbd4b8470fcf3b44e7c86b4e02 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mirt-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mirt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 36.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbe806f55de8c1ac5762954ceae2ace85ee2a80d4ed87dd0d5295eac26447431
|
|
| MD5 |
2682c2ed76bd0f2fbc24d437dfb579a0
|
|
| BLAKE2b-256 |
0df77a0d1e69d03abf55b4d9426ac4fefca47cac817195e649ad8745bd2358f3
|
Provenance
The following attestation bundles were made for mirt-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on Cameron-Lyons/mirt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mirt-0.1.1-py3-none-any.whl -
Subject digest:
dbe806f55de8c1ac5762954ceae2ace85ee2a80d4ed87dd0d5295eac26447431 - Sigstore transparency entry: 790636510
- Sigstore integration time:
-
Permalink:
Cameron-Lyons/mirt@cfb1debf33c475fbd4b8470fcf3b44e7c86b4e02 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Cameron-Lyons
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cfb1debf33c475fbd4b8470fcf3b44e7c86b4e02 -
Trigger Event:
push
-
Statement type: