Quick start#
Overview#
PyFCIRT is a high-level Bayesian forced-choice modeling interface with Python and R APIs. Built on the PyMC probabilistic programming framework, it is designed to make forced-choice models easy to specify, fit, and evaluate. GPU-accelerated sampling is available through JAX.
Supported models#
Forced-choice: dominance models
Thurstonian item response theory model (
TIRT).Thurstonian IRT model with a joint-ranking likelihood (
TIRTRank).Two-parameter logistic model for rankings (
TwoPLRank).Multidimensional generalized partial preference model (
MGPPM).
Forced-choice: ideal-point models
Generalized Thurstonian unfolding model (
GTUM).Generalized graded unfolding model for rankings (
GGUMRank).
Likert and dichotomous models
One- to four-parameter logistic IRT models (
DichotomousIRT).Generalized partial credit model (
GPCM).Generalized graded unfolding model (
GGUM).
Different measurement models can be combined within a test, including forced-choice, Likert, and dichotomous models.
Installation#
Use Python 3.12 or later for pip or conda. These commands install the beta release.
pip#
python -m pip install --pre pyfcirt
For NVIDIA GPU sampling on Linux or WSL 2, install PyFCIRT with CUDA Runtime 13.0.96.
python -m pip install --pre "pyfcirt[cuda13]" "nvidia-cuda-runtime==13.0.96"
conda#
conda install -c qipengchen/label/beta -c conda-forge pyfcirt
Docker#
CPU:
docker run --rm -it ghcr.io/qipengchen/pyfcirt:0.1.0b2-cpu
NVIDIA GPU (CUDA 13):
docker run --rm -it --gpus all ghcr.io/qipengchen/pyfcirt:0.1.0b2-cuda13
See GPU setup for compatibility and verification.
Your first analysis#
Fit TIRT to a simulated teaching dataset with 100 respondents and 24 triplets. The design table assigns each statement to a block and trait; the response table contains one person’s judgment of a named statement pair per row.
import pyfcirt as fc
example = fc.load_example("tirt_study", model="TIRT")
design_df = example.data.design
response_df = example.data.responses.frame
# design_df.head(3):
# block_id position statement_id trait keying
# B1 1 S1 T1 1
# B1 2 S2 T2 1
# B1 3 S3 T3 1
# response_df.head(3):
# person_id block_id statement_1 statement_2 response
# P1 B1 S1 S2 0
# P1 B1 S1 S3 1
# P1 B1 S2 S3 1
Register the design and responses, then fit TIRT.
model = fc.Model()
model.add_fc(
design_df,
response_df,
format="comparison_long",
model="TIRT",
)
model.prepare()
model.fit(random_seed=42)
model.coef(blocks=["B1"], kind="stats", round_to="auto")
model="TIRT" selects the measurement model. Each response records a pair
judgment. Response 1 prefers the first statement;
0 prefers the second. In the design, position gives presentation order and
keying gives the loading direction on the named trait.
model.coef() reports posterior means, standard deviations and uncertainty
intervals for the statements and pairs in B1.
Follow the examples for prior prediction, diagnostics and model checks, and use the API reference for individual calls. Use Prepare your data to define your own design and read CSV or spreadsheet responses.
Quick start in R#
Install the R development package from the source checkout. In R, install
ggplot2, posterior, and reticulate if needed. Then run these commands
from the repository root in the Python environment that R will use. Set
RETICULATE_PYTHON to that environment’s Python executable before starting R.
python -m pip install ".[io,covariates,numpyro]"
R CMD INSTALL r/pyfcirt
Fit TIRT to the same 100 respondents and 24 triplets as in the Python example.
library(pyfcirt)
example <- load_example("tirt_study", model = "TIRT")
head(example$design, 3)
head(example$responses, 3)
m <- model()
m$add_fc(example$design, example$responses, format = example$format,
model = "TIRT", response_format = example$response_format)
m$prepare()
m$fit(random_seed = 42L)
coef(m, blocks = "B1", kind = "stats", digits = 2L)
See the R examples and R API reference.