
Estimation of Bayesian 2PL models using R-INLA
April 23, 2026
Bayesian Computational Statistics and Modeling Research Group (BAYESCOMP)
Led by Prof. Håvard Rue
Statistical methodology and computation

Statistical methodology and computation
Credit: NCRM Resource Repository





Behavioural Circumplex A way to quantify interpersonal behaviour patterns (similar spirit to Big Five, but focused on interaction style).
Predict interpersonal dynamics (complementarity). Expected interpersonal response patterns e.g., dominance \(\xrightarrow{}\) submission; hostility \(\xrightarrow{}\) hostility.
IIP circumplex modelling yields a 256-parameter factor model. Standard Bayesian MCMC is too slow for this scale!
We developed an INLA-based approximate Bayesian inference strategy for structural equation models (SEMs) and latent variable models more generally.
Advancing scalable Bayesian methods for latent variable modelling
2603.25690 [stat.ME]). arXiv.2604.00671 [stat.CO]). arXiv.R/INLAvaan package available on CRAN and GitHub.{ltm} package in RItem Response Theory (IRT) is a statistical framework for modelling the relationship between:
A person’s latent ability or trait (unobserved)
Their responses to test questions (observed)

Key Idea:
People with higher ability are more likely to answer difficult questions correctly—and we can model this in a mathematical way.
Educational Testing:
Design, calibrate, and score standardized exams (e.g., PISA).
Psychometrics:
Measure latent traits like anxiety, personality, or satisfaction.
Fairness & Comparability:
Place people and items on the same scale, compare across years, languages, or groups.
Beyond Testing:
Applied in marketing, health outcomes research, HR assessments, and more.

Questions of interest

International assessment that measures 15 year-old students’ reading, mathematics, and science literacy.
PISA makes use of IRT models for
For student \(s=1,\dots,n\) consider binary responses for item \(y_i\), \(i=1,\dots,p\).

Subject: Mathematics
| \(s\) | \(y_1\) | \(y_2\) | \(y_3\) | \(y_4\) | \(y_5\) |
|---|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 1 | 1 |
| 2 | 1 | 1 | 1 | 1 | 1 |
| 3 | 1 | 1 | 1 | 0 | 1 |
| \(\vdots\) | |||||
| \(n\) | 1 | 0 | 0 | 1 | 1 |
How to “convert” this data to meaningful scores and item information?
| Student | Item1 | Item2 | Item3 | Item4 | Item5 |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 |
| 2 | 0 | 1 | 1 | 1 | 1 |
| 3 | 1 | 1 | 0 | 1 | 1 |
| 4 | 1 | 1 | 1 | 1 | 0 |
| 5 | 1 | 1 | 1 | 1 | 0 |
| 6 | 0 | 0 | 1 | 1 | 0 |
| 7 | 1 | 0 | 0 | 0 | 0 |
| 8 | 0 | 0 | 0 | 1 | 0 |
| 9 | 1 | 0 | 0 | 0 | 0 |
| 10 | 0 | 0 | 0 | 0 | 0 |
| Student | Item1 | Item2 | Item3 | Item4 | Item5 | Score |
|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 | 5 |
| 2 | 0 | 1 | 1 | 1 | 1 | 4 |
| 3 | 1 | 1 | 0 | 1 | 1 | 4 |
| 4 | 1 | 1 | 1 | 1 | 0 | 4 |
| 5 | 1 | 1 | 1 | 1 | 0 | 4 |
| 6 | 0 | 0 | 1 | 1 | 0 | 2 |
| 7 | 1 | 0 | 0 | 0 | 0 | 1 |
| 8 | 0 | 0 | 0 | 1 | 0 | 1 |
| 9 | 1 | 0 | 0 | 0 | 0 | 1 |
| 10 | 0 | 0 | 0 | 0 | 0 | 0 |
| Difficulty | 4 | 5 | 5 | 3 | 7 |
| Student | Item1 | Item2 | Item3 | Item4 | Item5 | Score |
|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 | 5 |
| 2 | 0 | 1 | 1 | 1 | 1 | 4 |
| 3 | 1 | 1 | 0 | 1 | 1 | 4 |
| 4 | 1 | 1 | 1 | 1 | 0 | 4 |
| 5 | 1 | 1 | 1 | 1 | 0 | 4 |
| Difficulty | 1 | 0 | 1 | 0 | 2 |
| 6 | 0 | 0 | 1 | 1 | 0 | 2 |
| 7 | 1 | 0 | 0 | 0 | 0 | 1 |
| 8 | 0 | 0 | 0 | 1 | 0 | 1 |
| 9 | 1 | 0 | 0 | 0 | 0 | 1 |
| 10 | 0 | 0 | 0 | 0 | 0 | 0 |
| Difficulty | 3 | 5 | 4 | 3 | 5 |
Assumptions
A “good test item” should have the following properties:
Monotonicity: \(\theta \uparrow \, \Rightarrow \Pr(\text{correct}) \uparrow\)
Appropriate difficulty: Ideally match target population
High discrimination: Steep “success curve” around item difficulty
Model the probability of obtaining a correct answer using the two-parameter logistic (2PL) model defined by: \[ \pi_{si}(\boldsymbol{\theta}, \mathbf a, \mathbf b) := \Pr(y_{si} = 1 \mid \boldsymbol{\theta}, \mathbf a, \mathbf b) = \frac{1}{1 + e^{-\eta_{si}} } \in [0,1], \] where the linear predictor term is given by: \[ \eta_{si} = a_i(\theta_s - b_i) \in \mathbb R \] and
The logistic function \(f:\mathbb{R} \to (0,1)\) is defined by \(f(x)=\frac{1}{1+e^{-x}}\).


Knowing item parameters allows better tests design and accurate scoring.
Item Anchoring: Use well-calibrated items to link different test forms or administrations, ensuring comparability over time and across groups.
Computerized Adaptive Testing (CAT): Select items in real time based on a test-taker’s estimated ability level, improving efficiency and precision.

\[ \pi_{si}(\theta) = c_i + \frac{d_i-c_i}{1+e^{-a_i(\theta_s - b_i)}} \]
| Parameter | 1PL | 2PL | 3PL | 4PL |
|---|---|---|---|---|
| Difficulty (\(b_i\)) | ✓ | ✓ | ✓ | ✓ |
| Discrimination (\(a_i\)) | 1 | ✓ | ✓ | ✓ |
| Guessing (\(c_i\)) | 0 | 0 | ✓ | ✓ |
| Slipping (\(d_i\)) | 1 | 1 | 1 | ✓ |
Early 20th century: Spearman’s \(g\)-factor and factor analysis sparked the shift from classical test theory (CTT) to latent trait thinking. See Veritasium.
Mid-20th century: Georg Rasch developed a probabilistic item-response framework (related to the 1PL, but it has unique invariance properties).
1970s–1990s: The 2PL, 3PL, and 4PL models generalized Rasch’s approach, enabling discrimination, guessing, and slipping parameters. Foundations for SAT, GRE, PISA.
Today: Computer-based adaptive testing uses IRT to route items in real time. Duolingo, Khan Academy, etc. now personalise learning at scale.
via Maximum Likelihood
Suppose we are interested in the outcome \(X\) of a single random trial, which can either be “success” (\(X=1\)) or “failure” (\(X=0\)) only. Examples include
Let the probability mass function (pmf) for \(X\) be \[ f(x; \pi) = \pi^x(1-\pi)^{1-x} = \begin{cases} \pi & x=1\text{ (``success'') }\\ 1-\pi &x=0 \text{ (``failure'')} \end{cases} \]
We say that \(X\) has a Bernoulli distribution written \(X\sim\operatorname{Bern}(p)\).
Context: Assume available \(X_1,\dots,X_n\sim f(x;\vartheta)\) (iid samples) but \(\vartheta\) is unknown. How to estimate it?
Define the likelihood function \(L(\vartheta) = \prod_{i=1}^n f(X_i; \vartheta)\).
The value \(\hat\vartheta = \arg\max_\vartheta L(\vartheta)\) is called the maximum likelihood estimator (MLE) of \(\vartheta\).

Proposal:\(\hspace{3cm}\)Abilities follow a bell-shaped curve, \(\theta_s \sim \operatorname{N}(0,1)\) say.
We can then integrate out1 the latents, like so: \[ L(\mathbf a, \mathbf b) = \prod_{s=1}^n \int \Bigg\{ \prod_{i=1}^p \pi_{si}(\theta_s; a_i, b_i)^{y_{si}}(1-\pi_{si}(\theta_s; a_i, b_i))^{1-y_{si}} \,\phi(\theta_s)\,d\theta_s \Bigg\} \]
Here, the bias is \(O(n^{-1})\) and thus disappears the more data we have. It is also generally less biased than JML.
MML is also more robust to sample size variations and provides more stable item parameter estimates.
{ltm} package{ltm} package{ltm} package{ltm} package
Call:
ltm(formula = LSAT ~ z1, IRT.param = TRUE)
Scoring Method: Empirical Bayes
Factor-Scores for observed response patterns:
Item 1 Item 2 Item 3 Item 4 Item 5 Obs Exp z1 se.z1
1 1 1 1 1 1 298 296.693 0.606 0.855
2 1 1 1 1 0 28 29.127 0.139 0.833
3 1 1 1 0 1 61 62.520 0.117 0.832
4 1 0 1 1 1 80 83.541 0.093 0.831
5 0 1 1 1 1 15 13.920 0.023 0.828
6 1 1 0 1 1 173 173.310 -0.022 0.827
7 1 1 1 0 0 11 8.445 -0.329 0.816
8 1 0 1 1 0 15 11.463 -0.352 0.815
9 1 0 1 0 1 28 24.989 -0.373 0.815
10 0 1 1 1 0 2 2.000 -0.420 0.813
11 0 1 1 0 1 3 4.370 -0.441 0.813
12 1 1 0 1 0 21 25.646 -0.463 0.812
13 0 0 1 1 1 4 5.955 -0.463 0.812
14 1 1 0 0 1 56 56.105 -0.483 0.812
15 1 0 0 1 1 81 76.562 -0.506 0.811
16 0 1 0 1 1 16 13.577 -0.573 0.809
17 1 0 1 0 0 3 4.659 -0.803 0.804
18 0 0 1 1 0 3 1.179 -0.891 0.803
19 1 1 0 0 0 16 11.254 -0.911 0.802
20 0 0 1 0 1 1 2.614 -0.911 0.802
21 1 0 0 1 0 14 15.590 -0.933 0.802
22 1 0 0 0 1 29 34.616 -0.953 0.802
23 0 1 0 0 1 8 6.431 -1.019 0.801
24 0 0 0 1 1 11 8.942 -1.041 0.800
25 0 0 1 0 0 1 0.696 -1.331 0.797
26 1 0 0 0 0 10 9.480 -1.373 0.797
27 0 1 0 0 0 1 1.840 -1.438 0.796
28 0 0 0 1 0 2 2.596 -1.460 0.796
29 0 0 0 0 1 6 5.861 -1.479 0.796
30 0 0 0 0 0 3 2.277 -1.895 0.795
{ltm} package

A dahlia flower, see https://github.com/dalia-project/DALIA

Bayes Theorem
\[ \text{Posterior} =: p(\vartheta \mid y) = \frac{p(y \mid \vartheta)\,p(\vartheta)}{p(y)} = \frac{\text{Likelihood} \times \text{Prior}}{\text{Evidence}} \]
Bayesian inference blends data with expert belief.

| Aspect | ML (JML/MML) | Bayesian |
|---|---|---|
| Point estimates | Direct optimization | Posterior means/medians |
| Uncertainty | Asymptotic SEs | Credible intervals |
| Priors | Not used | Required/optional |
| Small samples | Can be unstable | Often more stable with priors |
| Complex hierarchy | Harder | Natural framework |
Although Bayesian methods are preferable, Bayesian methods can be computationally intensive, especially for large datasets or complex models. This is where INLA comes in.
Why? The “normalising constant” \(p(y) = \int p(y \mid \vartheta)p(\vartheta)d\vartheta\) is often intractable, especially with high-dimensional parameters.

MCMC is the gold standard for Bayesian inference but can be slow to converge, especially with many parameters (e.g., large \(n\) and \(p\) in IRT).
INLA is a deterministic approximation strategy for Bayesian inference in latent Gaussian models.
It is attractive when:
The Ingredients 🥕🍅🧅🧄
\[ \begin{align} y \mid \mathcal X, \vartheta_1 &\sim \prod_{i=1}^n \pi(y_i \mid \mathcal X, \vartheta_1) \\ \mathcal X \mid \vartheta_2 &\sim \operatorname{N}(0, Q(\vartheta_2)^{-1}) \\ \vartheta := \{\vartheta_1, \vartheta_2\} &\sim \pi(\vartheta) \end{align} \]
Hierarchical Latent Gaussian Models (LGMs), encompassing
The Recipe 🧑🍳 (avail. in R/INLA)
To install INLA, run the following:
Generate some data from \(y_i = \beta_0 + \beta_1 x_i + \epsilon_i\):
Given these data points, can we
recover \(\beta_0\) (intercept) and \(\beta_1\) (slope)?
Time used:
Pre = 0.451, Running = 0.138, Post = 0.00657, Total = 0.596
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
(Intercept) 1.904 0.058 1.790 1.904 2.018 1.904 0
x 1.496 0.056 1.386 1.496 1.606 1.496 0
Model hyperparameters:
mean sd 0.025quant 0.5quant
Precision for the Gaussian observations 1.49 0.148 1.21 1.48
0.975quant mode
Precision for the Gaussian observations 1.79 1.47
Marginal log-Likelihood: -263.40
is computed
Posterior summaries for the linear predictor and the fitted values are computed
(Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
The good news is that IRT falls under the category of latent Gaussian models, so we can use INLA for estimation.
Recall the model hierarchy:
| Layer | Type | R-INLA component |
|---|---|---|
| \(y_{si}\sim \text{Bernoulli}(\pi_{si})\) | Likelihood | family = "binomial" |
| \(\text{logit}(\pi_{si}) = \eta_{si}\) | Link function | control.family = list(link = "logit") |
| \(\eta_{si} = a_i(\theta_s - b_i)\) | Linear predictor | formula = y ~ . |
| \(\theta_s \sim \operatorname{N}(0,1)\) | Latent field | f(model = "iid") |
| \(a_i\), \(b_i\) | “fixed effects” | |
# A tibble: 5,000 × 5
student idx_a y minus1 idx_b
<int> <int> <int> <dbl> <int>
1 1 1 0 -1 1
2 1 2 0 -1 2
3 1 3 0 -1 3
4 1 4 0 -1 4
5 1 5 0 -1 5
6 2 1 0 -1 1
7 2 2 0 -1 2
8 2 3 0 -1 3
9 2 4 0 -1 4
10 2 5 0 -1 5
# ℹ 4,990 more rows
pivot_longer()
Source: GitHub
gadenbuie/tidyexplain
\[ \eta_{si} = {\color{gray}a_i}(\theta_s + -1 \times b_i) \]
form <- y ~ -1 +
# Add the student abilities random effect
f(
student,
model = "iid",
hyper = list(prec = list(initial = log(1), fixed = TRUE)) # θ ~ N(0, 1)
) +
# Add item difficulties, treated as random effect with fixed precision
f(
item,
minus1, # to multiply by -1 for the difficulty parameter
model = "iid",
hyper = list(prec = list(initial = -log(3), fixed = TRUE)) # b_i ~ N(0, 3)
)\[ {\color{gray}\eta_{si} = } \, a_i{\color{gray}(\theta_s -b_i)} \]
Note: Undocumented feature!!!
{ltm} INLA_Disc ltm_Disc INLA_Diff ltm_Diff
Item 1 0.9099 0.8254 -3.1842 -3.3597
Item 2 0.6981 0.7229 -1.4376 -1.3696
Item 3 0.7144 0.8905 -0.3341 -0.2799
Item 4 0.7070 0.6886 -1.8655 -1.8659
Item 5 0.7816 0.6575 -2.7621 -3.1236
ID mean sd 0.025quant 0.5quant 0.975quant mode kld
1 Item 1 -3.184 0.486 -4.283 -3.124 -2.430 -3.087 2.48e-05
2 Item 2 -1.438 0.265 -2.084 -1.395 -1.039 -1.375 9.91e-06
3 Item 3 -0.334 0.114 -0.586 -0.326 -0.133 -0.309 1.01e-06
4 Item 4 -1.866 0.331 -2.693 -1.812 -1.369 -1.790 1.31e-05
5 Item 5 -2.762 0.460 -3.910 -2.697 -2.064 -2.669 1.62e-05
mean sd 0.025quant 0.5quant 0.975quant mode
beta[1] for lp_scale 0.910 0.162 0.598 0.908 1.235 0.898
beta[2] for lp_scale 0.698 0.129 0.444 0.698 0.951 0.699
beta[3] for lp_scale 0.714 0.126 0.467 0.714 0.963 0.713
beta[4] for lp_scale 0.707 0.132 0.449 0.707 0.967 0.705
beta[5] for lp_scale 0.782 0.144 0.501 0.781 1.068 0.777

{brms}30.235 sec elapsed
INLA able to reduce time to inference from 30 seconds to 1 second for this dataset!


📊 Beyond total scores: IRT reveals item difficulty & discrimination, and estimates individual abilities — richer insight than raw sums.
🧩 Model flexibility: 1PL → 4PL models let you balance simplicity against realism (guessing, slipping, varying discrimination).
⚖️ Estimation choices: Maximum likelihood is fast and familiar; Bayesian inference adds stability with sparse data and natural uncertainty quantification.
🚀 INLA enables scalability: Deterministic Bayesian inference makes complex, structured IRT models feasible — orders of magnitude faster than MCMC.
🌍 Fairness matters: Differential Item Functioning (DIF) and spatial DIF detection help ensure tests are equitable across groups and regions.
🔮 Future frontiers: Spatio-temporal, multidimensional, and hierarchical IRT models open new doors for large-scale educational assessment.