Plot the serial position curve restricted to items of specific categories.

The category SPC filters the standard serial position curve by item category, revealing category-dependent encoding and retrieval patterns across study positions.

Workflow

Code
import os
import matplotlib.pyplot as plt
import warnings
from jaxcmr.analyses.cat_spc import plot_cat_spc
from jaxcmr.helpers import find_project_root, generate_trial_mask, load_data, save_figure

warnings.filterwarnings("ignore")
Code
data_path = "data/TalmiEEG.h5"
figure_dir = "results/figures"
figure_str = ""
ylim = None
trial_query = "data['subject'] > 0"
category_field = "condition"
category_values = [1, 2]
labels = ["Negative", "Neutral"]
color_cycle = ["red", "black"]
contrast_name = "condition"
Code
project_root = find_project_root()
figure_dir = os.path.join(project_root, figure_dir)
data_path = os.path.join(project_root, data_path)
data = load_data(data_path)
trial_mask = generate_trial_mask(data, trial_query)
Code
plot_cat_spc(
    data, trial_mask,
    category_field=category_field,
    category_values=category_values,
    labels=labels,
    color_cycle=color_cycle,
    contrast_name=contrast_name,
)
if ylim is not None:
    for ax in plt.gcf().axes:
        ax.set_ylim(ylim)
save_figure(figure_dir, figure_str)

Interpretation

Each curve shows recall probability across study positions for one category.

  • Category separation: some item types are recalled more than others.
  • Position × category interaction: category effects may vary across primacy, middle, or recency positions.

API Details

Notebook parameters

  • data_path — path to an HDF5 file containing a RecallDataset with category fields.
  • figure_dir — directory for saving figures.
  • figure_str — base filename for the saved figure. Leave empty to display without saving.
  • ylim — y-axis limits as a tuple, or None for automatic scaling.
  • trial_query — a Python expression evaluated against the dataset to select trials.
  • category_field — dataset field containing category labels.
  • category_values — list of category values to plot.
  • labels — legend labels for each category.
  • color_cycle — colors for each curve.
  • contrast_name — legend title.