Skip to content

Phase 3: Statistics package #134

Closed

Description

@suraj-ranganath

🤖

Phase 3: Statistics Package

Summary

Create the useful EEGPrep equivalent of EEGLAB's functions/statistics package. This phase should provide stable numerical helpers that time-frequency and STUDY phases can reuse instead of reimplementing.

Can start after Phase 1 merges. Can run in parallel with Phases 2 and 4.

Scope

Prioritize useful, workflow-supporting helpers:

  • statcond, teststat, fdr
  • surrogate confidence interval and p-value helpers
  • cell-array style ANOVA/correlation/t-test helpers adapted to Python/NumPy inputs
  • concatdata or equivalent only if used by STUDY/time-frequency paths

Do not expose stale MATLAB-only convenience wrappers unless Phase 1's matrix classifies them as needed.

Acceptance Criteria

  • Add an EEGPrep statistics package in the locally appropriate source location.
  • Public functions have concise docstrings and clear NumPy input contracts.
  • Deterministic MATLAB parity tests cover numerical behavior with documented tolerances.
  • Invalid shape/type inputs fail clearly.
  • Phase 4 and Phase 6 can consume the helpers without private copy-paste implementations.
  • Matrix rows touched by this phase are updated.

Verification

Run:

  • focused statistics tests
  • MATLAB parity tests for deterministic functions
  • uv run --no-sync ruff check .
  • uv run --no-sync ruff format --check .
  • uv run --no-sync ty check
  • broader non-slow tests if shared numerical helpers affect existing workflows

/goal Prompt

/goal Port the EEGLAB statistics helper package needed by EEGPrep workflows. Use EEGLAB as oracle, implement idiomatic standalone Python/NumPy equivalents, add deterministic MATLAB parity tests and edge-case tests, expose only useful public APIs without stale helper bloat, and update the parity matrix for every function classified in this phase.

Activity

  1. added
    phase
    on Jun 5, 2026
  2. claude commented on Jun 5, 2026

    @claude
    Contributor

    🤖 Plan:

    • Read AGENTS.md, fix-issue, pull-request skills
    • Verify scope and blockers (Phase 1 status, vendored oracle, existing code)
    • Post analysis (scope too large for single PR — design comment instead of PR)
    • Await human direction on (a) splitting into sub-PRs, (b) waiting for Phase 1, and (c) ASCII-only or relaxed comment policy

    Research

    Epic-scale phase issue: port EEGLAB's 15-function functions/statistics package, add deterministic MATLAB parity tests, and update a parity matrix. Well over the 100-line ceiling for a single agent PR, and it has unresolved upstream dependencies.

    Blockers:

    • Phase 1 (Phase 1: Parity matrix, staleness triage, and porting contracts #132) — the parity-matrix foundation — is still OPEN. Issue body says "Can start after Phase 1 merges" and an acceptance criterion is "Matrix rows touched by this phase are updated." That matrix does not exist yet.
    • Vendored EEGLAB oracle is missing locally: `src/eegprep/eeglab/` is an empty directory, so there is no in-repo MATLAB source to port `statcond`/`teststat`/`fdr`/etc. from. Existing phases pulled it in via the audit at `.notes/eeglab-migration-gap-audit.md`; that audit lists the 15 functions but does not provide source.
    • No current EEGPrep callers depend on these helpers: `functions/timefreqfunc/newtimef.py` and `newcrossf.py` do not import any `statcond`/`fdr`/bootstrap symbol, and Phase 4 (Phase 4: Time-frequency internals and legacy time-frequency entry points #135) and Phase 6 (Phase 6: STUDY and group-level depth #137) are explicitly the future consumers.

    Relevant code

    Proposed Approach

    Do not implement in one PR. Stage the work behind Phase 1 and split by helper family. Recommended sequencing once Phase 1 merges and src/eegprep/eeglab/functions/statistics/ is populated:

    1. PR A — package skeleton + fdr + parity-matrix wiring. New src/eegprep/functions/statistics/__init__.py, port fdr (BH and BY, deterministic, exact MATLAB parity), classify the other 14 rows in the matrix as port/consolidated/stale_skip. Small, lands the package shape. Likely ~150-250 LOC.
    2. PR B — cell-array parametric helpers. ttest_cell, ttest2_cell, anova1_cell, anova1rm_cell, anova2_cell, anova2rm_cell, corrcoef_cell. NumPy-vectorised, MATLAB parity tests against fixed seeds. Likely ~400-600 LOC + tests.
    3. PR C — surrogate + dispatcher. surrogdistrib, stat_surrogate_pvals, stat_surrogate_ci, concatdata, teststat, and statcond (dispatcher that calls the cell helpers and surrogdistrib). statcondfieldtrip → classify external_dependency_skip unless Phase 1 disagrees. Likely ~500-800 LOC + tests.

    Each PR carries its own MATLAB parity tests (gated on MATLAB Engine / Octave per AGENTS.md), deterministic seed fixtures, ruff/ty/pre-commit, and matrix updates. Phase 4 (#135) consumes PR C; Phase 6 (#137) consumes PRs B and C.

    Open questions for a human before I start:

    1. Should I wait for Phase 1 (Phase 1: Parity matrix, staleness triage, and porting contracts #132) to merge, or open a draft of PR A against feature/eeglab-core-parity-completion with the matrix scaffold pre-filled?
    2. The vendored src/eegprep/eeglab/ is empty in this checkout — is that intentional (gitignored locally) or is it expected to be present before this phase starts? It is required as the porting oracle.
    3. Should statcondfieldtrip be marked external_dependency_skip (FieldTrip is not in EEGPrep) or port with a thin no-FT shim?
    4. Scope on surrogdistrib — full bootstrap/permutation/jackknife as in EEGLAB, or only the modes Phase 4/Phase 6 will actually call?
  3. suraj-ranganath commented on Jun 7, 2026

    @suraj-ranganath
    MemberAuthor

    🤖 Resolved by the work now included in PR #152. Closing this constituent phase/follow-up issue now; parent epic #131 remains open until the epic PR merges.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions