options(width = 120)
library(bmm)
library(brms)
library(tidyverse)
library(tidybayes)
library(here)
source(here("_common.R")) # shared workshop colors + ggplot theme
parameter_colors <- c(a = '#0028a5', c = '#dc6800', f = '#28a745')
source_colors <- c(Observed = '#008577', Predicted = '#8054a1')
source_shapes <- c(Observed = 16, Predicted = 17)
source_lines <- c(Observed = 'solid', Predicted = 'dashed')The Memory Measurement Model (M3) with bmm
Take-home notebook — Psychonomics 2026 bmm workshop, Part 2
M3 is a computational measurement model of working memory (Oberauer & Lewandowsky, 2019). It describes the processes that lead to correct responses and to different types of errors. In M3, memory strength has two dimensions: memory for the items themselves (item memory) and memory for their relations to a context, such as a list position (binding memory). Every response candidate receives activation that reflects the evidence for it in working memory, and the candidates compete: the higher a candidate’s activation, the more likely it is selected. Correct responses and the different errors draw on the two dimensions differently, so the frequencies of the response categories let M3 estimate item memory and binding memory separately.
This notebook uses a simple-span data set as its example and shows you how to fit M3 to it with bmm: how to specify the model, check whether it reproduces the responses, and interpret how both kinds of memory change as lists get longer. The last section shows how to extend the model to complex span.
Setup
Load the packages used in this notebook, and the colours and plot theme shared by all workshop notebooks:
Data
The workshop uses the open-set experiment (openset) from Oberauer (2019). Twenty participants studied lists of words, each word in its own box, and were then asked which word had been in one of the boxes. List words were drawn without replacement from a pool of 1,198 nouns, so a word recurred only after the whole pool had been used. Lists had 2, 4, 6, or 8 words. At test, participants chose from a set of options that contained different numbers of studied items and not-presented lures (NPL; words not in the list). Column definitions are in the codebook.
Each row of the trial data is one test trial. It records the participant (id), the set size, how many studied items (rsizeList, including the correct one) and not-presented lures (rsizeNPL) were among the test options, and the response category (rcat: 1 = correct, 2 = other studied item, 3 = not-presented lure):
trials_simple <- read.csv(here("data", "m3_simple_trials.csv"))
head(trials_simple) id setsize rsizeList rsizeNPL rcat
1 10_openset 2 1 1 1
2 10_openset 2 1 1 1
3 10_openset 2 1 1 1
4 10_openset 2 1 1 1
5 10_openset 2 1 1 1
6 10_openset 2 1 1 1
M3 analyzes the response frequency for each response category. Therefore, we aggregate the trials into counts per category for each participant, set size, and option combination. Because the probability of a category also depends on how many options it had, we add one option-count column per category. Each test has one correct option, so n_corr is 1. The other studied items are the studied options without the correct one, so n_other is rsizeList - 1. rsizeNPL counts the not-presented lures among the options, so n_npl is rsizeNPL. Set size enters the model as a category, so we also store it as a factor (ss_fac). Putting everything together, the data can be summarized and phrased with the code:
dat_simple <- trials_simple |>
summarise(corr = sum(rcat == 1),
other = sum(rcat == 2),
npl = sum(rcat == 3),
.by = c(id, setsize, rsizeList, rsizeNPL)) |>
mutate(n_corr = 1L,
n_other = rsizeList - 1,
n_npl = rsizeNPL,
ss_fac = factor(setsize))
head(dat_simple) id setsize rsizeList rsizeNPL corr other npl n_corr n_other n_npl ss_fac
1 10_openset 2 1 1 23 0 0 1 0 1 2
2 10_openset 2 2 0 23 0 0 1 1 0 2
3 10_openset 2 2 2 23 0 0 1 1 2 2
4 10_openset 4 1 1 23 0 0 1 0 1 4
5 10_openset 4 2 0 23 0 0 1 1 0 4
6 10_openset 4 2 2 22 1 0 1 1 2 4
Each row contains the counts for one participant at one set size and one combination of test options: 480 rows, 20 participants × 24 combinations. The response-count columns sum to 23 in each row. A zero in an n_* column means that category was absent from the options.
Specify: model, formula, and priors
Model
Every response option starts with the same baseline activation . Studied items receive additional activation from item memory (). The correct item receives further activation from binding memory (), its association with the probed position. The activation per option, , therefore differs between response categories:
To predict how often each category is chosen, M3 turns these activations into category probabilities. With the softmax rule, a category’s weight is its number of options times the exponentiated activation per option. Dividing each weight by the sum of all weights gives the probabilities:
where is the activation per option in category and is its number of options. More options give a category more opportunities to be selected, even when activation per option stays the same.
Adding the same to every option does not change the probabilities, so bmm fixes at zero. The activations per option are then for the correct item, for other studied items, and for lures.
The bmm function m3() specifies the model with four arguments:
resp_catslists the response-count columns.num_optionslists the option-count columns, which must follow the same order asresp_cats.version = "ss"selects the simple-span activations above.choice_rule = "softmax"selects the softmax rule above.
model_simple <- m3(
resp_cats = c("corr", "other", "npl"),
num_options = c("n_corr", "n_other", "n_npl"),
version = "ss",
choice_rule = "softmax"
)Formula
In this data, participants’ performance varied across set sizes, suggesting that item memory and binding memory could change with set size. bmm can estimate each parameter separately for each condition. We use bmf() to specify one regression formula per parameter, starting with the parameter’s name (c ~, a ~). To get an estimate at each set size, the formulas use ss_fac:
formula_simple <- bmf(
c ~ 0 + ss_fac + (0 + ss_fac | id),
a ~ 0 + ss_fac + (0 + ss_fac | id)
)To make each coefficient the parameter’s value at one set size, rather than a difference from a reference set size, we remove the intercept with 0 +. We included random slope effect by adding (0 + ss_fac | id), which lets each participant deviate from these values at each set size and lets these deviations correlate. The fit summary reports these coefficients:
| Coefficient | Meaning |
|---|---|
a_ss_fac2, a_ss_fac4, a_ss_fac6, a_ss_fac8 |
Item memory at set sizes 2, 4, 6, and 8, respectively |
c_ss_fac2, c_ss_fac4, c_ss_fac6, c_ss_fac8 |
Binding memory at set sizes 2, 4, 6, and 8, respectively |
Priors
bmm estimates the model with Bayesian methods, so each parameter also needs a prior. The coefficients of and are activations, so their priors describe activation directly. We give each set-size coefficient a normal(3, 1) prior: activations around 3 are most plausible, and about 95% of the prior lies between 1 and 5. These priors apply to the set-size values, not to each participant’s activation. The participant-level standard deviations and correlations keep bmm’s default priors:
priors_simple <- c(
prior(normal(3, 1), class = "b", nlpar = "a", coef = "ss_fac2"),
prior(normal(3, 1), class = "b", nlpar = "a", coef = "ss_fac4"),
prior(normal(3, 1), class = "b", nlpar = "a", coef = "ss_fac6"),
prior(normal(3, 1), class = "b", nlpar = "a", coef = "ss_fac8"),
prior(normal(3, 1), class = "b", nlpar = "c", coef = "ss_fac2"),
prior(normal(3, 1), class = "b", nlpar = "c", coef = "ss_fac4"),
prior(normal(3, 1), class = "b", nlpar = "c", coef = "ss_fac6"),
prior(normal(3, 1), class = "b", nlpar = "c", coef = "ss_fac8")
)Fit: estimate the model and check the sampling
To estimate the parameters, we pass the formula, the model, the data, and the priors to bmm(), which samples from the posterior with Stan:
formula,model,data, andpriortake the objects defined above.filesaves the fitted model, andfile_refit = "on_change"refits only when the model, data, or priors change.- The other arguments control the sampling and are passed to
brms::brm(); see its documentation for details.
Fitting would take a few minutes, so the workshop ships the fitted model in models/. Because the saved fit matches this code, bmm() loads it instead of fitting again:
fit_simple <- bmm(
formula = formula_simple,
model = model_simple,
data = dat_simple,
prior = priors_simple,
chains = 4,
cores = 4,
iter = 5000,
warmup = 2000,
control = list(adapt_delta = 0.95),
sample_prior = "yes",
backend = "cmdstanr",
seed = 2026,
file = here("models", "m3_simple"),
file_refit = "on_change"
)To see the estimates, print the summary of the fit:
summary(fit_simple) Model: m3(resp_cats = c("corr", "other", "npl"),
num_options = c("n_corr", "n_other", "n_npl"),
choice_rule = "softmax",
version = "ss")
Links: c = identity; a = identity
Formula: b = 0
c ~ 0 + ss_fac + (0 + ss_fac | id)
a ~ 0 + ss_fac + (0 + ss_fac | id)
Data: dat_simple (Number of observations: 480)
Draws: 4 chains, each with iter = 5000; warmup = 2000; thin = 1;
total post-warmup draws = 12000
Multilevel Hyperparameters:
~id (Number of levels: 20)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(c_ss_fac2) 0.36 0.30 0.01 1.12 1.00 7605 6782
sd(c_ss_fac4) 0.59 0.23 0.15 1.10 1.00 4396 3324
sd(c_ss_fac6) 0.67 0.13 0.46 0.96 1.00 7467 8226
sd(c_ss_fac8) 0.42 0.08 0.29 0.60 1.00 7497 8421
sd(a_ss_fac2) 0.64 0.55 0.02 2.06 1.00 10542 6524
sd(a_ss_fac4) 0.59 0.50 0.02 1.88 1.00 7098 6688
sd(a_ss_fac6) 0.57 0.38 0.03 1.43 1.00 4211 5693
sd(a_ss_fac8) 0.72 0.26 0.28 1.29 1.00 5962 5676
cor(c_ss_fac2,c_ss_fac4) -0.05 0.37 -0.74 0.68 1.00 3585 7359
cor(c_ss_fac2,c_ss_fac6) -0.07 0.37 -0.75 0.65 1.00 1512 3156
cor(c_ss_fac4,c_ss_fac6) 0.36 0.26 -0.21 0.80 1.00 3780 4958
cor(c_ss_fac2,c_ss_fac8) -0.06 0.37 -0.73 0.65 1.00 1728 3436
cor(c_ss_fac4,c_ss_fac8) 0.26 0.27 -0.30 0.74 1.00 4024 6346
cor(c_ss_fac6,c_ss_fac8) 0.73 0.15 0.38 0.94 1.00 8236 9179
cor(a_ss_fac2,a_ss_fac4) 0.00 0.38 -0.72 0.70 1.00 17560 9462
cor(a_ss_fac2,a_ss_fac6) 0.00 0.38 -0.71 0.72 1.00 8624 8884
cor(a_ss_fac4,a_ss_fac6) 0.02 0.37 -0.67 0.70 1.00 8974 10008
cor(a_ss_fac2,a_ss_fac8) 0.00 0.38 -0.70 0.70 1.00 3727 5932
cor(a_ss_fac4,a_ss_fac8) 0.05 0.37 -0.66 0.73 1.00 5020 7702
cor(a_ss_fac6,a_ss_fac8) 0.29 0.34 -0.46 0.83 1.00 4702 6547
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
c_ss_fac2 4.94 0.37 4.27 5.72 1.00 18086 8525
c_ss_fac4 4.54 0.22 4.15 5.00 1.00 10214 8322
c_ss_fac6 3.21 0.16 2.89 3.53 1.00 8129 9067
c_ss_fac8 2.45 0.10 2.25 2.65 1.00 7684 8208
a_ss_fac2 3.56 0.84 1.99 5.28 1.00 20950 9094
a_ss_fac4 2.92 0.60 1.86 4.19 1.00 17565 8469
a_ss_fac6 2.71 0.33 2.14 3.45 1.00 11190 8064
a_ss_fac8 2.20 0.24 1.79 2.75 1.00 9261 7582
Constant Parameters:
Value
b_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).
The summary has four parts:
- The header repeats the model, the links, the formulas, the data (480 rows), and the sampling settings (12,000 draws after warmup).
- Multilevel Hyperparameters (
~id) describe how much participants differ at each set size (sd()) and how their deviations correlate (cor()). - Regression Coefficients are the set-size values of and , the coefficients from the Specify section.
- Constant Parameters list the baseline , fixed at 0.
In each row, Estimate is the posterior mean, Est.Error the posterior standard deviation, and l-95% CI / u-95% CI the bounds of the 95% credible interval. The last three columns are sampling diagnostics. Before interpreting the estimates, check that the sampler worked:
Rhatcompares variation between and within chains. Values near 1 indicate agreement; values above 1.01 warrant further investigation.Bulk_ESS/Tail_ESSdescribe how many independent draws the correlated MCMC draws are worth, for the bulk and tails of the posterior. They help assess the precision of posterior means and interval endpoints.- Divergent transitions can indicate that the sampler has not explored the posterior reliably. They are a sampling problem, not a test of whether the model describes the observed responses.
To count divergent transitions, use nuts_params():
nuts <- nuts_params(fit_simple)
sum(nuts$Value[nuts$Parameter == "divergent__"])[1] 0
With 5,000 iterations per chain (2,000 warmup), this fit has no divergent transitions. Maximum Rhat is 1.00; minimum bulk and tail ESS are 1,512 and 3,156.
To confirm which priors the fit used, use prior_info():
prior_info(fit_simple)Model: The Multinomial / Memory Measurement Model
parameter link class coef prior source
a identity b -- normal(3,1) bmm default
a identity b ss_fac2 normal(3, 1) user
a identity b ss_fac4 normal(3, 1) user
a identity b ss_fac6 normal(3, 1) user
a identity b ss_fac8 normal(3, 1) user
b -- b Intercept constant(0) bmm default
c identity b -- normal(3,1) bmm default
c identity b ss_fac2 normal(3, 1) user
c identity b ss_fac4 normal(3, 1) user
c identity b ss_fac6 normal(3, 1) user
c identity b ss_fac8 normal(3, 1) user
-- -- cor -- lkj(2) bmm default
a identity sd -- exponential(1) bmm default
c identity sd -- exponential(1) bmm default
The user rows (ss_fac2 to ss_fac8) are the priors on the set-size values; they override the general bmm default entries for and . The other rows are bmm defaults: the participant-level standard deviations (sd), their correlations (cor), and the fixed baseline . For a methods section, prior_info(fit_simple, format = "text") writes the same information as sentences.
Optional: re-fit the model yourself
To fit the model yourself, change file_refit = "on_change" to "always" in the code above. Re-fitting requires the Stan toolchain (Install_Packages.R, Part 2).
Evaluate: observed and predicted responses
Before interpreting the memory parameters, check whether the model describes the responses, including both kinds of error. To compare the model with the data, we compute the expected count in each response category with posterior_epred(). It returns the expected count (trials × predicted probability) for each posterior draw, data row, and category. colMeans() then averages over the draws, which gives one expected count per row and category. We use 200 randomly chosen draws to keep this fast:
set.seed(2026)
expected_simple <- posterior_epred(fit_simple, ndraws = 200)
predicted_simple <- dat_simple |>
select(id, setsize) |>
bind_cols(as.data.frame(colMeans(expected_simple)))To prepare the data for plotting, we (1) stack the observed and predicted counts, (2) sum each participant’s counts over the option combinations and divide by the total, and (3) average these proportions across participants and compute their standard errors:
counts_simple <- bind_rows(
Observed = dat_simple |> select(id, setsize, corr, other, npl),
Predicted = predicted_simple,
.id = "source"
)
participant_props <- counts_simple |>
summarise(across(c(corr, other, npl), sum),
.by = c(source, id, setsize)) |>
mutate(total = corr + other + npl) |>
pivot_longer(c(corr, other, npl),
names_to = "category", values_to = "count") |>
mutate(proportion = count / total)
pp_simple <- participant_props |>
mutate(category = factor(category,
levels = c("corr", "other", "npl"),
labels = c("Correct", "Other studied items",
"Not-presented lures"))) |>
summarise(se = sd(proportion) / sqrt(n()),
proportion = mean(proportion),
.by = c(source, setsize, category))Plot the observed and predicted proportions by set size:
dodge <- position_dodge(width = 0.25)
simple_predictive <- pp_simple |>
ggplot(aes(x = setsize, y = proportion, group = source,
color = source, shape = source, linetype = source)) +
geom_errorbar(aes(ymin = pmax(0, proportion - se),
ymax = pmin(1, proportion + se)),
width = 0.12, position = dodge) +
geom_line(position = dodge) +
geom_point(size = 3, position = dodge) +
facet_wrap(~category, nrow = 1, scales = "free_y") +
scale_x_continuous(breaks = c(2, 4, 6, 8)) +
scale_color_manual(values = source_colors) +
scale_shape_manual(values = source_shapes) +
scale_linetype_manual(values = source_lines) +
labs(x = "Set size", y = "Response proportion",
color = NULL, shape = NULL, linetype = NULL) +
theme_workshop() +
theme(legend.position = "right")
simple_predictive
The model reproduces the observed proportions at every set size, for correct responses and both kinds of error. We can therefore go on to interpret its estimates of item memory and binding memory.
Interpret: item memory and binding memory
To see how item and binding memory change with set size, summarise each set-size coefficient by its posterior median and 95% credible interval:
simple_parameters <- as.data.frame(fit_simple) |>
select(starts_with("b_a_ss_fac"), starts_with("b_c_ss_fac")) |>
pivot_longer(everything(),
names_to = c("parameter", "setsize"),
names_pattern = "b_(.)_ss_fac(.)",
values_to = "value") |>
mutate(setsize = as.integer(setsize)) |>
summarise(median_qi(value), .by = c(parameter, setsize))
simple_parameters |>
select(parameter, setsize, median = y, lower = ymin, upper = ymax) |>
knitr::kable(digits = 2)| parameter | setsize | median | lower | upper |
|---|---|---|---|---|
| a | 2 | 3.54 | 1.99 | 5.28 |
| a | 4 | 2.88 | 1.86 | 4.19 |
| a | 6 | 2.68 | 2.14 | 3.45 |
| a | 8 | 2.18 | 1.79 | 2.75 |
| c | 2 | 4.92 | 4.27 | 5.72 |
| c | 4 | 4.53 | 4.15 | 5.00 |
| c | 6 | 3.21 | 2.89 | 3.53 |
| c | 8 | 2.45 | 2.25 | 2.65 |
Plot the estimates by set size:
simple_posterior <- simple_parameters |>
ggplot(aes(x = setsize, y = y, color = parameter)) +
geom_line() +
geom_pointrange(aes(ymin = ymin, ymax = ymax)) +
facet_wrap(~parameter, nrow = 1,
labeller = as_labeller(c(a = "Item memory (a)",
c = "Binding memory (c)"))) +
scale_x_continuous(breaks = c(2, 4, 6, 8)) +
scale_y_continuous(limits = c(0, 6), breaks = 0:6,
expand = expansion(mult = 0)) +
scale_color_manual(values = parameter_colors, guide = "none") +
labs(x = "Set size", y = "Activation") +
theme_workshop()
simple_posterior
Binding memory declines clearly as lists get longer, from 4.92 at set size 2 to 2.45 at set size 8. Item memory tends to decline as well, from 3.54 to 2.18, but its estimates are uncertain at small set sizes. At set size 2, participants made only 6 errors, all to other studied items and none to lures. Item memory is informed by how errors split between other studied items and lures, so the data say little about , and its estimate stays close to the normal(3, 1) prior.
The posterior estimates allow us to test theoretical assumptions. For instance, to examine whether item memory differs between set size 8 and set size 2, we can use the hypothesis() function, which computes the difference in each posterior draw and tests whether it equals zero:
hypothesis(fit_simple, "a_ss_fac8 = a_ss_fac2")Hypothesis Tests for class b:
Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio Post.Prob Star
1 (a_ss_fac8)-(a_ss... = 0 -1.36 0.88 -3.14 0.3 0.52 0.34
---
'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 output:
Estimateis the posterior mean of . A negative value means lower item memory at set size 8.CI.Lower/CI.Upperbound the 95% credible interval of the difference.Evid.Ratiois the Bayes factor for no difference () against a difference: the posterior density of at zero divided by its prior density at zero. Values below 1 favor a difference. It needs the prior draws saved bysample_prior = "yes".Post.Probis the posterior probability of no difference, assuming both hypotheses were equally probable beforehand.
Item memory is about 1.36 activation units lower at set size 8 than at set size 2, but the 95% interval (−3.14 to 0.30) includes zero and , suggesting that the difference between set size 2 and set size 8 was inconclusive.
Extension: complex span
Li, Frischkorn, and Oberauer (2026), Experiment 1, added distractor processing to the memory task. Participants viewed three target–distractor pairs, each associated with a distinct context color, while judging which object was larger in real life. In the pre-cue condition, the target in each pair was designated before the size judgment. At test, a color cue indicated which target to select from 12 image options.
Binding memory is again the association between an item and its context, but here the context is the pair’s color rather than the list position. A paired distractor shares the tested target’s color context; other distractors belong to the other pairs. The workshop uses only the pre-cue condition: 45 participants, with one aggregated row each. Exclusions and columns are documented in the codebook.
dat_complex <- read.csv(here("data", "m3_complex_span.csv"))
head(dat_complex, 3) participant condition corr other distc disto npl n_corr n_other n_distc n_disto n_npl
1 1 pre 31 17 4 6 1 1 2 1 2 6
2 2 pre 33 14 6 7 0 1 2 1 2 6
3 3 pre 42 7 3 4 4 1 2 1 2 6
Specify
Distractors can also receive item and binding activation. M3 for complex span therefore adds filtering (), a multiplier on a distractor’s item and binding activation. With , distractors receive only the baseline activation; with , they receive the same activation as targets. Lower therefore means stronger filtering. The activation per option is:
The m3() arguments work as described in Model. Here, resp_cats and num_options list the five categories in the order of the equations above, and version = "cs" selects these complex-span activations:
model_complex <- m3(
resp_cats = c("corr", "distc", "other", "disto", "npl"),
num_options = c("n_corr", "n_distc", "n_other", "n_disto", "n_npl"),
version = "cs",
choice_rule = "softmax"
)The data contain a single condition, so each parameter gets one population value and participant deviations from it:
formula_complex <- bmf(
c ~ 1 + (1 | participant),
a ~ 1 + (1 | participant),
f ~ 1 + (1 | participant)
) and get the same normal(3, 1) prior as in simple span (see Priors). is estimated on the logit scale, where a logistic(0, 1) prior makes every value of between 0 and 1 equally plausible:
priors_complex <- c(
prior(normal(3, 1), class = "b", nlpar = "a", coef = "Intercept"),
prior(normal(3, 1), class = "b", nlpar = "c", coef = "Intercept"),
prior(logistic(0, 1), class = "b", nlpar = "f", coef = "Intercept")
)Fit
The fit uses the same settings and the same saved-fit handling as for simple span (see Fit):
fit_complex <- bmm(
formula = formula_complex,
model = model_complex,
data = dat_complex,
prior = priors_complex,
file = here("models", "m3_complex"),
file_refit = "on_change",
chains = 4,
cores = 4,
iter = 5000,
warmup = 2000,
control = list(adapt_delta = 0.95),
sample_prior = "yes",
backend = "cmdstanr",
seed = 2026
)Check the summary and count the divergent transitions:
summary(fit_complex) Model: m3(resp_cats = c("corr", "distc", "other", "disto", "npl"),
num_options = c("n_corr", "n_distc", "n_other", "n_disto", "n_npl"),
choice_rule = "softmax",
version = "cs")
Links: c = identity; a = identity; f = logit
Formula: b = 0
c ~ 1 + (1 | participant)
a ~ 1 + (1 | participant)
f ~ 1 + (1 | participant)
Data: dat_complex (Number of observations: 45)
Draws: 4 chains, each with iter = 5000; warmup = 2000; thin = 1;
total post-warmup draws = 12000
Multilevel Hyperparameters:
~participant (Number of levels: 45)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(c_Intercept) 0.91 0.12 0.71 1.18 1.00 4304 6922
sd(a_Intercept) 0.94 0.19 0.62 1.34 1.00 5627 7729
sd(f_Intercept) 0.41 0.12 0.18 0.65 1.00 3748 2937
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
c_Intercept 2.12 0.15 1.84 2.41 1.00 3013 5005
a_Intercept 3.11 0.22 2.70 3.56 1.00 8811 8519
f_Intercept 0.65 0.10 0.45 0.84 1.00 10876 9322
Constant Parameters:
Value
b_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).
complex_nuts <- nuts_params(fit_complex)
sum(complex_nuts$Value[complex_nuts$Parameter == "divergent__"])[1] 0
This fit has no divergent transitions. Maximum Rhat is 1.00; minimum bulk and tail ESS are 3,013 and 2,937.
Evaluate
To check whether the model describes all five categories, compute the expected counts as for simple span (see Evaluate):
set.seed(2026)
expected_complex <- posterior_epred(fit_complex, ndraws = 200)
predicted_complex <- dat_complex |>
select(participant, condition) |>
bind_cols(as.data.frame(colMeans(expected_complex)))Prepare the data for plotting in the same three steps. Each participant has one row, so step 2 only divides the counts by their total:
counts_complex <- bind_rows(
Observed = dat_complex |>
select(participant, condition, corr, distc, other, disto, npl),
Predicted = predicted_complex,
.id = "source"
)
participant_props_complex <- counts_complex |>
mutate(total = corr + distc + other + disto + npl) |>
pivot_longer(c(corr, distc, other, disto, npl),
names_to = "category", values_to = "count") |>
mutate(proportion = count / total)
pp_complex <- participant_props_complex |>
mutate(category = factor(category,
levels = c("corr", "distc", "other", "disto", "npl"),
labels = c("Correct", "Paired distractor",
"Other targets", "Other distractors",
"Not-presented lures"))) |>
summarise(se = sd(proportion) / sqrt(n()),
proportion = mean(proportion),
.by = c(source, condition, category))Plot correct responses and errors in separate panels:
dodge <- position_dodge(width = 0.25)
complex_predictive <- pp_complex |>
mutate(response_type = if_else(category == "Correct", "Correct", "Errors")) |>
ggplot(aes(x = category, y = proportion, group = source,
color = source, shape = source)) +
geom_errorbar(aes(ymin = pmax(0, proportion - se),
ymax = pmin(1, proportion + se)),
width = 0.10, position = dodge) +
geom_point(size = 3, position = dodge) +
facet_wrap(~response_type, nrow = 1, scales = "free", space = "free_x") +
ggh4x::scale_y_facet(response_type == "Correct",
limits = c(0.5, 0.9), breaks = seq(0.5, 0.9, 0.1)) +
ggh4x::scale_y_facet(response_type == "Errors",
limits = c(0, 0.20), breaks = seq(0, 0.20, 0.05)) +
scale_x_discrete(labels = c("Correct" = "Correct",
"Paired distractor" = "Paired\ndistractor",
"Other targets" = "Other\ntargets",
"Other distractors" = "Other\ndistractors",
"Not-presented lures" = "Not-presented\nlures")) +
scale_color_manual(values = source_colors) +
scale_shape_manual(values = source_shapes) +
labs(x = NULL, y = "Response proportion", color = NULL, shape = NULL) +
theme_workshop() +
theme(legend.position = "right", strip.text = element_text(size = 16))
complex_predictive
The model reproduces correct responses and most error types, but it underpredicts other-distractor responses (observed 8.6%, predicted 6.5%).
Interpret
is estimated on the logit scale, which keeps it between 0 and 1. Transform its draws with plogis() before summarising; and stay on the activation scale, as in simple span:
complex_parameters <- as.data.frame(fit_complex) |>
select(b_a_Intercept, b_c_Intercept, b_f_Intercept) |>
pivot_longer(everything(),
names_to = "parameter",
names_pattern = "b_(.)_Intercept",
values_to = "value") |>
mutate(value = if_else(parameter == "f", plogis(value), value)) |>
summarise(median_qi(value), .by = parameter)
complex_parameters |>
select(parameter, median = y, lower = ymin, upper = ymax) |>
knitr::kable(digits = 2)| parameter | median | lower | upper |
|---|---|---|---|
| a | 3.10 | 2.70 | 3.56 |
| c | 2.12 | 1.84 | 2.41 |
| f | 0.66 | 0.61 | 0.70 |
Plot the estimates, with in its own panel:
complex_posterior <- complex_parameters |>
mutate(scale = if_else(parameter == "f", "Filtering", "Activation")) |>
ggplot(aes(x = parameter, y = y, color = parameter)) +
geom_pointrange(aes(ymin = ymin, ymax = ymax)) +
facet_wrap(~scale, nrow = 1, scales = "free", space = "free_x") +
ggh4x::scale_y_facet(scale == "Activation",
limits = c(0, 6), breaks = 0:6) +
ggh4x::scale_y_facet(scale == "Filtering",
limits = c(0, 1), breaks = seq(0, 1, 0.25)) +
scale_color_manual(values = parameter_colors, guide = "none") +
labs(x = NULL, y = NULL) +
theme_workshop(base_size = 14)
complex_posterior
Distractors keep about two thirds of a target’s item and binding activation ( = 0.66, 95% CI 0.61–0.70), so about a third of their activation is filtered out. The posterior medians of item memory and binding memory are 3.10 and 2.12.
Further reading
The M3 tutorial covers choice rules, complex span, and custom activation functions. See the reading list for references and ?m3 for the model’s R documentation.