Signal Detection Theory with bmm

Take-home notebook — Psychonomics 2026 bmm workshop, Part 1

Author

Gidon T. Frischkorn

Setup

The SDT models arrived in bmm 1.4.1 (on CRAN since October 2026). If library(bmm) works but sdt_yn() or parameter_info() gives you could not find function, your bmm is older than that; update it once with:

install.packages("bmm")   # the workshop needs version 1.4.1 or newer
library(bmm)
library(brms)  # hypothesis() and other post-processing generics
library(tidyverse)
library(tidybayes)
library(here)

source(here("_common.R"))  # shared workshop colors + ggplot theme

Data

Recognition memory data from Koen, Aly, Wang, & Yonelinas (2013), as distributed with the MPTinR package: participants studied word lists and judged old/new test words on a 6-point confidence scale (1 = sure new … 6 = sure old). Two between-subjects test conditions (48 participants each): a recognition test under full attention (Experiment 2) and a test given immediately after study (Experiment 4).

All columns are documented in the codebook: data/README.md. The full-attention condition is also the example dataset in the Vuorre (2025) tutorial in resources/01_sdt/, so you can read this notebook and that paper side by side.

dat <- read.csv(here("data", "sdt_recognition.csv"))
glimpse(dat)
Rows: 23,902
Columns: 6
$ pid       <chr> "full_01", "full_01", "full_01", "full_01", "full_01", "full…
$ condition <chr> "full_attention", "full_attention", "full_attention", "full_…
$ stimulus  <chr> "old", "old", "old", "old", "old", "old", "old", "old", "old…
$ is_old    <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
$ rating    <int> 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, …
$ say_old   <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, …

Before any model: hit and false-alarm rates per participant, the raw material of every SDT analysis.

dat |>
  summarise(p_yes = mean(say_old), .by = c(pid, condition, stimulus)) |>
  pivot_wider(names_from = stimulus, values_from = p_yes) |>
  ggplot(aes(new, old, color = condition)) +
  geom_abline(linetype = "dashed", color = wk_colors[["grey"]]) +
  geom_point(size = 2, alpha = 0.8) +
  scale_color_manual(values = unname(wk_colors[c("blue", "orange")])) +
  coord_equal(xlim = c(0, 1), ylim = c(0, 1)) +
  labs(x = "False-alarm rate", y = "Hit rate", color = NULL) +
  theme_workshop()

Scatterplot of false-alarm rate against hit rate per participant, colored by condition, with the chance diagonal as a dashed line.

Specify: the model and its formula

Yes/no SDT describes each old/new decision with two parameters: the distance between the noise and signal evidence distributions (sensitivity d′d') and the location of the decision boundary (criterion cc, measured from the mean of the noise distribution: c=d′/2c = d'/2 is the unbiased midpoint, higher is more conservative).

sdt_yn() expects one row per participant × stimulus class, with the count of “old” responses and the number of trials. This data shape is a contract — getting it wrong is the first error most people hit, so check it against head() before fitting:

binary_counts <- dat |>
  summarise(
    n_old    = sum(say_old),
    n_trials = n(),
    .by = c(pid, condition, is_old)
  )
head(binary_counts, 4)
      pid      condition is_old n_old n_trials
1 full_01 full_attention      1    88      100
2 full_01 full_attention      0    22      100
3 full_02 full_attention      1    69      100
4 full_02 full_attention      0    26      100
sdt_model <- sdt_yn(response = "n_old", stimulus = "is_old",
                    n_trials = "n_trials")
sdt_model
sdt_yn(response = "n_old",        stimulus = "is_old",        n_trials = "n_trials") 
Response:   response = n_old (count of 'old'/'signal' responses per cell) 
Parameters: d, criterion, bias, sdratio 
Links:      d = identity; criterion = identity; bias = identity; sdratio = log 
Fixed:      sdratio = 0 
Use parameter_info() for parameter descriptions, links and fixed values.

Printing the model object shows you what you just built: its parameters, the link function each one uses, and which are fixed rather than estimated. parameter_info(sdt_model) gives the same information with full descriptions. If you misspell a parameter in the formula, the error message lists the valid names.

The formula addresses the model parameters by name — this is the core of the bmm workflow. One regression formula per parameter says how it varies over conditions and participants. bmf() (“bmm formula”) is where those go; it takes one ordinary R formula per parameter, and (1 | pid) is standard mixed-model syntax for “let this parameter vary across participants”, exactly as in lme4 or brms:

fit_sdt <- bmm(
  formula = bmf(
    d         ~ 1 + condition + (1 | pid),
    criterion ~ 1 + condition + (1 | pid)
  ),
  data  = binary_counts,
  model = sdt_model,
  sample_prior = "yes"  # prior draws: Bayes factors in hypothesis()
)

With treatment coding (full_attention is the reference level), the four population-level coefficients are:

Coefficient Meaning
d_Intercept d′d', full-attention condition
d_conditionimmediate difference in d′d', immediate − full attention
criterion_Intercept criterion cc, full-attention condition (from the noise mean)
criterion_conditionimmediate difference in cc, immediate − full attention

Everything you know about R’s linear formulas transfers: interactions, multiple predictors, and (1 | pid) for hierarchical participant-level parameters — but the “outcome” of each formula is a cognitive model parameter, not a raw response.

bmm offers a second name for the same boundary: bias, measured from the midpoint between the two distributions (0 = neutral, positive = conservative; bias = criterion - d/2 under equal variance). Write criterion or bias in the formula, never both. criterion is the one the false-alarm rate depends on alone, which is why this notebook uses it.

Before anything compiles, let bmm check formula and data together. bmm_data_check() runs the checks bmm() would run and reports how the model reads the response and the predictors; a formula that names a parameter the model does not have fails the hard checks here, with the valid names in the message:

bmm_data_check(
  bmf(d ~ 1 + condition + (1 | pid), criterion ~ 1 + condition + (1 | pid)),
  data = binary_counts, model = sdt_model
)
Pre-fit data check
Model: sdt_yn(response = "n_old", stimulus = "is_old", n_trials = "n_trials") 
Data:  192 rows, 23902 trials ('binary_counts') 

Response variables:
  n_old  numeric, range [3, 148] (expected: count of 'old'/'signal' responses
         per cell)

Data columns used by each parameter formula:
  d          condition, pid
  criterion  condition, pid

Predictor coding:
  condition  [predictor] character with 2 levels: 'full_attention', 'immediate'
  pid        [grouping]  character with 96 levels: 'full_01', 'full_02',
                         'full_03', 'full_04', 'full_05', 'full_06', 'full_07',
                         'full_08', 'full_09', 'full_10', ...

Trials per design cell:
  pid x condition: 96 non-empty cell(s)
  trials per cell: min 154 / median 250 / max 300

Findings:
  - Character predictor(s) 'condition' will be coerced to factors with
    alphabetical level order. Use factor() to control the reference level.
  - 96 design cell combination(s) contain no trials - fine if the design is
    intentionally incomplete.

Hard checks: passed

Read the findings for what they are. condition is a character column, so bmm codes it as a factor in alphabetical order, which makes full_attention the reference level. The 96 empty cells are the design: each participant took part in one condition only. The trial counts come from n_trials, here 154 to 300 per participant. The line that matters is the last one: the hard checks passed.

Fit: load the cached model

All workshop models ship pre-fitted in models/ — nothing to compile, nothing to wait for:

fit_sdt <- readRDS(here("models", "sdt_yn.rds"))
summary(fit_sdt)
  Model: sdt_yn(response = "n_old",
                stimulus = "is_old",
                n_trials = "n_trials") 
  Links: d = identity; criterion = identity; sdratio = log 
Formula: d ~ 1 + condition + (1 | pid)
         criterion ~ 1 + condition + (1 | pid)
         sdratio = 0 
   Data: binary_counts (Number of observations: 192)
  Draws: 4 chains, each with iter = 5000; warmup = 1000; thin = 4;
         total post-warmup draws = 4000

Multilevel Hyperparameters:
~pid (Number of levels: 96) 
                        Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
sd(d_Intercept)             0.37      0.03     0.31     0.44 1.00     3780
sd(criterion_Intercept)     0.31      0.03     0.26     0.36 1.00     3639
                        Tail_ESS
sd(d_Intercept)             3889
sd(criterion_Intercept)     3812

Regression Coefficients:
                             Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
d_Intercept                      1.45      0.06     1.33     1.57 1.00     3834
criterion_Intercept              0.70      0.05     0.60     0.80 1.00     3690
d_conditionimmediate            -0.28      0.08    -0.45    -0.12 1.00     3616
criterion_conditionimmediate    -0.34      0.07    -0.47    -0.21 1.00     3576
                             Tail_ESS
d_Intercept                      3851
criterion_Intercept              3990
d_conditionimmediate             3737
criterion_conditionimmediate     3789

Constant Parameters:
                      Value
sdratio_Intercept      0.00

Draws were sampled using sample(hmc). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).

Three things to read in that output before you trust anything else:

  • Rhat compares variation between and within the four chains. It should be 1.00; anything above ~1.01 means the chains have not agreed on the same answer and the estimates are not usable yet.
  • Bulk_ESS / Tail_ESS are effective sample sizes — how many independent draws the correlated MCMC draws are worth. A few hundred is enough for a point estimate; aim for >1000 before quoting the tails of an interval.
  • sdratio_Intercept is exactly 0 with no uncertainty because sdt_yn() fixes it there. That is the equal-variance assumption made visible: the signal and noise distributions are held to the same SD, which is what makes d here equal to the textbook d′d'. The rating model at the end of this notebook estimates it instead.

Which priors were used?

Every bmm model comes with default priors, so the fit above used priors even though the formula never mentions them. prior_info() lists each one, on the scale the model samples on, and says whether it is a bmm default or one you set:

prior_info(fit_sdt)
Model:  Signal Detection Theory (Yes/No) 

 parameter link     class     prior                   source     
 criterion identity b         normal(0, 0.5)          bmm default
 d         identity b         normal(0, 0.5)          bmm default
 criterion identity Intercept normal(0.5, 1.5)        bmm default
 d         identity Intercept normal(1, 1)            bmm default
 sdratio   log      Intercept constant(0) [native: 1] bmm default
 criterion identity sd        exponential(1)          bmm default
 d         identity sd        exponential(1)          bmm default

Priors and constants apply on the sampling scale set by each parameter's link
function.

prior_info(fit_sdt, format = "text") writes the same information as sentences for a methods section.

Optional: re-fit the model yourself

You do not need this to follow the workshop. Re-fitting requires the Stan toolchain (Install_Packages.R, Part 2) and takes a few minutes: the full fitting script is models/fit_sdt.R.

Evaluate: posteriors, hypotheses, model checks

First: does the model describe the data?

Before interpreting any parameter, simulate new data from the fitted model and compare it with the real data (a posterior predictive check). The one-line version:

pp_check(fit_sdt, ndraws = 50)

Default posterior predictive check: density of the observed counts of old responses with densities of 50 simulated datasets overlaid.

That plot mixes hits with false alarms and 100-trial with 150-trial cells, so its bumps are hard to read. Converting the simulated counts to per-participant rates and splitting by item type gives a clearer picture:

set.seed(2026)
ppc_rows <- fit_sdt$data |>
  as_tibble() |>
  mutate(row = row_number(),
         measure = ifelse(is_old == 1, "hit rate", "false-alarm rate"))

ppc_sim <- posterior_predict(fit_sdt, ndraws = 50) |>   # draws x rows of fit_sdt$data
  as_tibble(.name_repair = ~ as.character(seq_along(.x))) |>
  mutate(draw = row_number()) |>
  pivot_longer(-draw, names_to = "row", values_to = "n_old",
               names_transform = as.integer) |>
  left_join(select(ppc_rows, row, n_trials, measure), by = "row") |>
  mutate(rate = n_old / n_trials)

ggplot(ppc_sim, aes(rate)) +
  geom_density(aes(group = draw), color = wk_colors[["grey"]], linewidth = 0.4) +
  geom_density(data = mutate(ppc_rows, rate = n_old / n_trials),
               color = wk_colors[["blue"]], linewidth = 1.5) +
  facet_wrap(~ measure, scales = "free") +
  labs(x = "Proportion \"old\" responses per participant", y = NULL) +
  theme_workshop()

Densities of per-participant false-alarm and hit rates in 50 datasets simulated from the fitted model (grey) and in the observed data (blue).

The real data (blue) sit inside the simulated ones (grey). Read this check for what it is: with two numbers per participant (hit and false-alarm rate) and two parameters per participant (d′d' and cc), the yes/no model can reproduce any participant, so a good match here says the fit worked, not that SDT is right. Data with more response categories can contradict the model; the rating model at the end of this notebook is that test.

Posteriors

The posterior draws of the coefficients are draws of the SDT parameters, so condition-specific d′d' and cc are simple sums of draws:

sdt_pars <- fit_sdt |>
  spread_draws(b_d_Intercept, b_d_conditionimmediate,
               b_criterion_Intercept, b_criterion_conditionimmediate) |>
  mutate(
    d_full = b_d_Intercept,
    d_imm  = b_d_Intercept + b_d_conditionimmediate,
    c_full = b_criterion_Intercept,
    c_imm  = b_criterion_Intercept + b_criterion_conditionimmediate
  )

sdt_pars |>
  pivot_longer(d_full:c_imm,
               names_to = c("parameter", "condition"), names_sep = "_") |>
  group_by(parameter, condition) |>
  median_qi(value)
# A tibble: 4 × 8
  parameter condition value .lower .upper .width .point .interval
  <chr>     <chr>     <dbl>  <dbl>  <dbl>  <dbl> <chr>  <chr>    
1 c         full      0.698  0.603  0.797   0.95 median qi       
2 c         imm       0.360  0.266  0.451   0.95 median qi       
3 d         full      1.45   1.33   1.57    0.95 median qi       
4 d         imm       1.17   1.06   1.29    0.95 median qi       
sdt_pars |>
  pivot_longer(d_full:c_imm,
               names_to = c("parameter", "condition"), names_sep = "_") |>
  mutate(parameter = recode(parameter, d = "d'", c = "criterion c"),
         condition = recode(condition, full = "full attention", imm = "immediate")) |>
  ggplot(aes(x = value, y = condition, fill = condition)) +
  stat_halfeye(alpha = 0.8) +
  facet_wrap(~parameter, scales = "free_x") +
  scale_fill_manual(values = unname(wk_colors[c("blue", "orange")]), guide = "none") +
  labs(x = "Posterior value", y = NULL) +
  theme_workshop()

Posterior distributions of d-prime and criterion for the full-attention and immediate conditions, shown as halfeye plots.

Testing parameter differences is one line

Because condition differences are coefficients on the parameters, testing them needs no extra machinery:

# Does sensitivity differ between the two test conditions?
hypothesis(fit_sdt, "d_conditionimmediate = 0")
Hypothesis Tests for class b:
                Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
1 (d_conditionimmed... = 0    -0.28      0.08    -0.45    -0.12       0.03
  Post.Prob Star
1      0.03    *
---
'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
'*': For one-sided hypotheses, the posterior probability exceeds 95%;
for two-sided hypotheses, the value tested against lies outside the 95%-CI.
Posterior probabilities of point hypotheses assume equal prior probabilities.
# Is the immediate group more liberal (lower criterion)?
hypothesis(fit_sdt, "criterion_conditionimmediate < 0")
Hypothesis Tests for class b:
                Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
1 (criterion_condit... < 0    -0.34      0.07    -0.45    -0.23        Inf
  Post.Prob Star
1         1    *
---
'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
'*': For one-sided hypotheses, the posterior probability exceeds 95%;
for two-sided hypotheses, the value tested against lies outside the 95%-CI.
Posterior probabilities of point hypotheses assume equal prior probabilities.

How to read the two outputs:

  • Estimate, CI.Lower, CI.Upper: the posterior mean of the difference and its credible interval. For the directional test (< 0) the interval is one-sided, so it differs slightly from the 95% interval in fixef().
  • Evid.Ratio for = 0 is a Bayes factor in favour of no difference (Savage-Dickey; it needs sample_prior = "yes" at fit time and is NA without it). Values below 1 favour a difference, so 1 / Evid.Ratio is the evidence for one.
  • Evid.Ratio for < 0 is the posterior odds that the difference is negative, and Post.Prob the matching probability: the share of posterior draws below zero.
  • Star marks hypotheses whose interval excludes the tested value.

Participants tested immediately after study show lower sensitivity and a more liberal criterion than participants tested under full attention after a filler task — and the model quantifies both differences with full posterior uncertainty, from one formula.

Model-implied ROC

The bmm SDT toolkit turns the posterior into the classic SDT graphics — here the model-implied ROC curve with the observed operating points:

plot(roc_sdt(fit_sdt), observed = roc_observed(fit_sdt))

Model-implied ROC curves with credible bands and observed operating points per condition.

attr(auc_sdt(fit_sdt), "summary")
   AUC_mean AUC_lower AUC_upper      condition
1 0.8473433 0.8268049 0.8665051 full_attention
2 0.7957249 0.7730706 0.8184131      immediate

And the latent-distribution view that every SDT figure in a textbook draws by hand — reconstructed from the fitted posterior:

plot(latent_sdt(fit_sdt))

Model-implied noise and signal evidence distributions with the estimated criterion.

Extension: rating-scale SDT

The 6-point confidence ratings contain more information than the binary old/new split: sdt_rating() places K−1=5K-1 = 5 confidence thresholds on the same latent evidence axis. It expects one count column per rating category:

rating_counts <- dat |>
  count(pid, condition, is_old, rating) |>
  complete(nesting(pid, condition, is_old), rating, fill = list(n = 0)) |>
  pivot_wider(names_from = rating, values_from = n,
              names_prefix = "r", values_fill = 0)
head(rating_counts, 4)
# A tibble: 4 × 9
  pid     condition      is_old    r1    r2    r3    r4    r5    r6
  <chr>   <chr>           <int> <int> <int> <int> <int> <int> <int>
1 full_01 full_attention      0    37    30    11    16     5     1
2 full_01 full_attention      1     2     7     3     6     3    79
3 full_02 full_attention      0    32    26    16     6    14     6
4 full_02 full_attention      1     6    12    13     9    16    44

Recognition ROCs are classically asymmetric — old items have more variable memory strength than new items, the very phenomenon Koen et al. (2013) studied. With rating data, bmm can estimate that signal-SD ratio (sdratio) — the unequal-variance SDT model — with one more formula line, while d and criterion keep their condition effects:

fit_rating <- bmm(
  formula = bmf(
    d         ~ 1 + condition + (1 | pid),
    criterion ~ 1 + condition + (1 | pid),
    spacing   ~ 1,
    sdratio   ~ 1
  ),
  data  = rating_counts,
  model = sdt_rating(response = paste0("r", 1:6), stimulus = "is_old"),
  sample_prior = "yes"  # prior draws: Bayes factors in hypothesis()
)
fit_rating <- readRDS(here("models", "sdt_rating.rds"))
summary(fit_rating)
  Model: sdt_rating(response = paste0("r", 1:6),
                    stimulus = "is_old") 
  Links: d = identity; criterion = identity; spacing = identity; sdratio = identity 
Formula: d ~ 1 + condition + (1 | pid)
         criterion ~ 1 + condition + (1 | pid)
         spacing ~ 1
         sdratio ~ 1 
   Data: rating_counts (Number of observations: 192)
  Draws: 4 chains, each with iter = 5000; warmup = 1000; thin = 4;
         total post-warmup draws = 4000

Multilevel Hyperparameters:
~pid (Number of levels: 96) 
                        Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
sd(d_Intercept)             0.44      0.04     0.38     0.52 1.00     2366
sd(criterion_Intercept)     0.32      0.03     0.27     0.37 1.00     2420
                        Tail_ESS
sd(d_Intercept)             3180
sd(criterion_Intercept)     2950

Regression Coefficients:
                             Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
d_Intercept                      1.37      0.07     1.24     1.51 1.00     1772
d_conditionimmediate            -0.16      0.09    -0.34     0.02 1.00     1622
criterion_Intercept              0.53      0.05     0.44     0.63 1.00     1820
criterion_conditionimmediate    -0.36      0.07    -0.49    -0.23 1.00     1390
spacing_Intercept               -0.49      0.01    -0.51    -0.47 1.00     3921
sdratio_Intercept                0.36      0.02     0.33     0.39 1.00     3726
                             Tail_ESS
d_Intercept                      2625
d_conditionimmediate             2638
criterion_Intercept              2775
criterion_conditionimmediate     2723
spacing_Intercept                3645
sdratio_Intercept                3867

Note: sdratio is not fixed at 0, so d is d_a (root-mean-square SD units), not the noise-standardized d'.
      sdt_sensitivity() converts it to d' (noise SD) and d_S (signal SD).

Draws were sampled using sample(hmc). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).

summary() adds a note under the coefficients: with sdratio free, d is no longer the textbook d′d' (more on that below). sdratio is the log SD ratio, so 0 would mean equal variance. exp(sdratio) clearly above 1 (≈ 1.4) confirms the classic finding: the old-item distribution is wider than the new-item distribution.

Two things worth saying out loud. First, once sdratio is free, bmm’s d is dad_a — the separation measured in units of the two distributions’ root-mean-square SD — rather than the textbook d′d'; the two coincide only under equal variance, which is exactly the assumption the yes/no model made for us. Second, the condition difference in sensitivity points the same way as before but is now less certain, with an interval that includes zero. Neither result is more “correct” than the other: parameter estimates are estimates under a measurement model, which is precisely why the model belongs in your methods section.

sdt_sensitivity() converts d into the other scales per condition: da (what d estimates here), dn (noise-SD units, the textbook d′d') and ds (signal-SD units):

sdt_sensitivity(fit_rating, measure = c("da", "dn"))
SDT sensitivity (sdt_rating_standard, dist = normal)
  da = RMS-SD units (estimated) | dn = noise-SD units (d') | ds = signal-SD units
 measure mean lower upper      condition
      da 1.37  1.24  1.51 full_attention
      da 1.21  1.08  1.34      immediate
      dn 1.69  1.53  1.86 full_attention
      dn 1.50  1.34  1.66      immediate
fit_rating |>
  spread_draws(b_d_conditionimmediate, b_sdratio_Intercept) |>
  mutate(sd_ratio = exp(b_sdratio_Intercept)) |>
  pivot_longer(c(b_d_conditionimmediate, sd_ratio)) |>
  group_by(name) |>
  median_qi(value)
# A tibble: 2 × 7
  name                    value .lower .upper .width .point .interval
  <chr>                   <dbl>  <dbl>  <dbl>  <dbl> <chr>  <chr>    
1 b_d_conditionimmediate -0.158 -0.342 0.0168   0.95 median qi       
2 sd_ratio                1.43   1.39  1.47     0.95 median qi       

Where to go from here: the bmm SDT article (online only, not installed with the package) covers the ROC/zROC diagnostics, threshold parameterizations, and the criterion-free sdt_mafc() and sdt_ranking() models; the Vuorre (2025) preprint in resources/01_sdt/ builds the same models from raw brms formulas.

Further reading

See resources/01_sdt/ for PDFs and resources/README.md for the full reading list with DOIs.