Skip to content

Add more ERP measures - #14221

Merged
larsoner merged 1 commit into
mne-tools:mainfrom
BelizSertcan:erp-meas
Aug 25, 2026
Merged

Add more ERP measures#14221
larsoner merged 1 commit into
mne-tools:mainfrom
BelizSertcan:erp-meas

Conversation

@BelizSertcan

@BelizSertcan BelizSertcan commented Aug 25, 2026

Copy link
Copy Markdown

This PR completes @withmywoessner 's work in #12434.

Reference issue (if any)

Closes #7848
Closes #12434

What does this implement/fix?

Implements the following ERP measures:

  • Mean amplitude
  • Area amplitude (all positive, numeric integration)
  • Fractional area latency
  • Fractional peak latency

Changes relative to #12434:

  1. Following the discussion in the previous PR, average=True now returns a
    single-row DataFrame, with the channel index shown as "average", so the
    column layout stays consistent with average=False.
  2. Renamed channels to channel for consistency with the rest of MNE.
  3. Replaced the original tests, which only asserted DataFrame.shape. The new
    tests check computed values against closed-form results.
  4. Each function calls _check_pandas_installed(strict=True) rather than
    importing pandas at module level, so pandas stays optional for compute_sme.

Bugs fixed from #12434:

  1. Unit mismatch in compute_frac_area_latency.
  2. compute_frac_peak_latency returned the peak's own latency for "offset"
    rather than the true post-peak crossing.
  3. All four functions crashed with any picks other than "all" — the channel
    column used the full ch_names while the data was the picked subset. Now
    resolves picks via _picks_to_idx before building the labels.

Additional information

Question for reviewers:
Should compute_frac_area_latency support mode='intg'? For a biphasic
signal the lobes can cancel, so the cumulative integral isn't monotonic and
"the latency at which X% of the area is reached" may have multiple solutions
or none.

Claude Opus 5 helped identifying the bugs and writing the tests, and drafted this PR description.

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need similar changes to other functions. Anything following the : in param names needs to resolve to a intersphinx-findable cross-ref entry, or have an ignore in doc/conf.py:numpydoc_xref_ignore. You will see CircleCI complain about these formatting and reference problems...

Comment thread mne/stats/erp.py Outdated
Comment thread mne/stats/erp.py Outdated
Co-authored-by: Jacob Woessner <Woessner.jacob@gmail.com>
@larsoner
larsoner merged commit 3b6725a into mne-tools:main Aug 25, 2026
31 checks passed
@welcome

welcome Bot commented Aug 25, 2026

Copy link
Copy Markdown

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

@larsoner

Copy link
Copy Markdown
Member

Looks great, thanks @BelizSertcan !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERP Measurement Tool for MNE

2 participants